Allow initializing Aspect class also using name. Add GitHub standard Python .gitignore
authorJason Robinson <jaywink@basshero.org>
Wed, 3 Jul 2013 09:52:57 +0000 (12:52 +0300)
committerJason Robinson <jaywink@basshero.org>
Wed, 3 Jul 2013 10:07:16 +0000 (13:07 +0300)
.gitignore
diaspy/models.py

index 87538bdbbec9e2d0edfd9fa8c7d9a1d8142b1e71..dd5cdc121163ef6c197be9ff997eb611fd6af80c 100644 (file)
@@ -3,10 +3,45 @@
 docs/build/*
 */__pycache__/*
 __pycache__/*
-*.pyc
 .env
 
 check-*.py
 
 testconf.py
 TEST_COUNT
+
+*.py[cod]
+
+# C extensions
+*.so
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+lib
+lib64
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+nosetests.xml
+
+# Translations
+*.mo
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
index cc4b0a448f2539b587178c36b169c38aead08367..d4f6d7d337fbdd0ceb0b067693d1e1438c7d3bab 100644 (file)
@@ -12,22 +12,42 @@ MUST NOT import anything.
 
 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:
                 name = a['name']
                 break
         return name
+        
+    def _findid(self):
+        """Finds id for aspect.
+        """
+        id = None
+        aspects = self._connection.getUserInfo()['aspects']
+        for a in aspects:
+            if a['name'] == self.name:
+                id = a['id']
+                break
+        return id
 
     def getUsers(self):
         """Returns list of GUIDs of users who are listed in this aspect.