Browse Source

EM component: uid not id + make sure it is an integer

ArnAud 9 years ago
parent
commit
462b6f3bbb
1 changed files with 10 additions and 2 deletions
  1. 10
    2
      EditorialModel/components.py

+ 10
- 2
EditorialModel/components.py View File

@@ -25,6 +25,7 @@ class EmComponent(object):
25 25
             raise EnvironmentError('Abstract class')
26 26
         if isinstance(id_or_name, int):
27 27
             self.id = id_or_name
28
+            self.name = None
28 29
         elif isinstance(id_or_name, str):
29 30
             self.id = None
30 31
             self.name = id_or_name
@@ -41,7 +42,7 @@ class EmComponent(object):
41 42
         if self.id is None:
42 43
             select.where(table.col.name == self.name)
43 44
         else:
44
-            select.where(table.col.id == self.id)
45
+            select.where(table.col.uid == self.id)
45 46
 
46 47
         sqlresult = table.rexec(select)
47 48
         records = sqlresult.fetchall()
@@ -55,7 +56,7 @@ class EmComponent(object):
55 56
             for k in record.keys():
56 57
                 setattr(row, k, record[k])
57 58
 
58
-        self.id = row.uid
59
+        self.id = int(row.uid)
59 60
         self.name = row.name
60 61
         self.rank = 0 if row.rank is None else int(row.rank)
61 62
         self.date_update = row.date_update
@@ -92,5 +93,12 @@ class EmComponent(object):
92 93
     def modify_rank(self, new_rank):
93 94
         pass
94 95
 
96
+    def __repr__(self):
97
+        if self.name is None:
98
+            return "<%s #%s, 'non populated'>" % (type(self).__name__, self.id)
99
+        else:
100
+            return "<%s #%s, '%s'>" % (type(self).__name__, self.id, self.name)
101
+
102
+
95 103
 class EmComponentNotExistError(Exception):
96 104
     pass

Loading…
Cancel
Save