X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=diaspy%2Fmodels.py;h=9df0ae752204d93e59ce07dd73f10b2fc6e41993;hb=4882952fbea2c92730af5a438797fb27f1608389;hp=6bc3115920b49960f382bdf36c9dd784a5f0c705;hpb=08f03d2621d69d66f18a7f5616ddd4b9dbf91e88;p=diaspy.git diff --git a/diaspy/models.py b/diaspy/models.py index 6bc3115..9df0ae7 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -1,27 +1,38 @@ #!/usr/bin/env python3 -import json -import re - - """This module is only imported in other diaspy modules and MUST NOT import anything. """ +import json +import re + +from diaspy import errors + + class Aspect(): """This class represents an aspect. + + Class can be initialized by passing either an id and/or name as + parameters. + If both are missing, an exception will be raised. """ - def __init__(self, connection, id=-1): + def __init__(self, connection, id=None, name=None): self._connection = connection - self.id = id - self.name = self._findname() - + self.id, self.name = id, name + if id and not name: + self.name = self._findname() + elif name and not id: + self.id = self._findid() + elif not id and not name: + raise Exception('Aspect must be initialized with either an id or name') + def _findname(self): """Finds name for aspect. """ - name = '' + name = None aspects = self._connection.getUserInfo()['aspects'] for a in aspects: if a['id'] == self.id: @@ -29,28 +40,39 @@ class Aspect(): break return name - def getUsers(self): - """Returns list of GUIDs of users who are listed in this aspect. + def _findid(self): + """Finds id for aspect. """ - start_regexp = re.compile('