Przeglądaj źródła

Changed icon field to EmField_icon in EmClass and EmField. Added sortcolumn argument for EmType and EmClass.

Yann Weber 9 lat temu
rodzic
commit
47ce122e93
3 zmienionych plików z 20 dodań i 15 usunięć
  1. 8
    8
      EditorialModel/classes.py
  2. 3
    3
      EditorialModel/fields.py
  3. 9
    4
      EditorialModel/types.py

+ 8
- 8
EditorialModel/classes.py Wyświetl plik

@@ -15,7 +15,8 @@ import EditorialModel
15 15
 
16 16
 ## @brief Manipulate Classes of the Editorial Model
17 17
 # Create classes of object.
18
-#@see EmClass, EmType, EmFieldGroup, EmField
18
+# @see EmClass, EmType, EmFieldGroup, EmField
19
+# @todo sortcolumn handling
19 20
 class EmClass(EmComponent):
20 21
 
21 22
     table = 'em_class'
@@ -25,7 +26,7 @@ class EmClass(EmComponent):
25 26
     # @see EditorialModel::components::EmComponent::_fields
26 27
     _fields = [
27 28
         ('classtype', ftypes.EmField_char),
28
-        ('icon', ftypes.EmField_integer),
29
+        ('icon', ftypes.EmField_icon),
29 30
         ('sortcolumn', ftypes.EmField_char)
30 31
     ]
31 32
 
@@ -35,17 +36,15 @@ class EmClass(EmComponent):
35 36
     # @return An EmClass instance
36 37
     # @throw EmComponentExistError if an EmClass with this name and a different classtype exists
37 38
     @classmethod
38
-    def create(cls, name, class_type):
39
-        return cls._create_db(name, class_type)
39
+    def create(cls, name, classtype, icon=None, sortcolumn='rank', **em_component_args):
40
+        return cls._create_db(name=name, classtype=classtype['name'], icon=icon, sortcolumn=sortcolumn, **em_component_args)
40 41
 
41 42
     @classmethod
42 43
     ## Isolate SQL for EmClass::create
43
-    # @todo Remove hardcoded default value for icon
44 44
     # @return An instance of EmClass
45
-    def _create_db(cls, name, class_type):
45
+    def _create_db(cls, name, classtype, icon, sortcolumn, **em_component_args):
46 46
         #Create a new entry in the em_class table
47
-        values = {'name': name, 'classtype': class_type['name'], 'icon': 0}
48
-        result = super(EmClass, cls).create(**values)
47
+        result = super(EmClass, cls).create(name=name, classtype=classtype, icon=icon, sortcolumn=sortcolumn, **em_component_args)
49 48
 
50 49
         dbe = result.db_engine()
51 50
         conn = dbe.connect()
@@ -162,3 +161,4 @@ class EmClass(EmComponent):
162 161
                 linked_types.append(EditorialModel.types.EmType(table_name_elements[1]))
163 162
 
164 163
         return linked_types
164
+

+ 3
- 3
EditorialModel/fields.py Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3 3
 from EditorialModel.components import EmComponent, EmComponentNotExistError
4
-from EditorialModel.fieldtypes import EmField_boolean, EmField_char, EmField_integer, get_field_type
4
+from EditorialModel.fieldtypes import EmField_boolean, EmField_char, EmField_integer, EmField_icon, get_field_type
5 5
 from EditorialModel.fieldgroups import EmFieldGroup
6 6
 from EditorialModel.classes import EmClass
7 7
 
@@ -30,7 +30,7 @@ class EmField(EmComponent):
30 30
         ('rel_field_id', EmField_integer),
31 31
         ('optional', EmField_boolean),
32 32
         ('internal', EmField_boolean),
33
-        ('icon', EmField_integer)
33
+        ('icon', EmField_icon)
34 34
     ]
35 35
 
36 36
     ## Create (Function)
@@ -55,7 +55,7 @@ class EmField(EmComponent):
55 55
     # @see EmComponent::__init__()
56 56
     # @staticmethod
57 57
     @classmethod
58
-    def create(cls, name, fieldgroup, fieldtype, optional=0, internal=0, rel_to_type_id=0, rel_field_id=0, icon=0, **em_component_args):
58
+    def create(cls, name, fieldgroup, fieldtype, optional=0, internal=0, rel_to_type_id=0, rel_field_id=0, icon=None, **em_component_args):
59 59
         created_field = super(EmField, cls).create(
60 60
             name=name,
61 61
             fieldgroup_id=fieldgroup.uid,

+ 9
- 4
EditorialModel/types.py Wyświetl plik

@@ -17,6 +17,7 @@ import EditorialModel.classes
17 17
 # EmType with special fields called relation_to_type fields
18 18
 #
19 19
 # @see EditorialModel::components::EmComponent
20
+# @todo sortcolumn handling
20 21
 class EmType(EmComponent):
21 22
     table = 'em_type'
22 23
     table_hierarchy = 'em_type_hierarchy'
@@ -40,8 +41,8 @@ class EmType(EmComponent):
40 41
     # @see EmComponent::__init__()
41 42
     # 
42 43
     # @todo check that em_class is an EmClass object (fieldtypes can handle it)
43
-    def create(c, name, em_class, **em_component_args):
44
-        return super(EmType, c).create(name=name, class_id=em_class.uid, **em_component_args)
44
+    def create(c, name, em_class, sortcolumn='rank', **em_component_args):
45
+        return super(EmType, c).create(name=name, class_id=em_class.uid, sortcolumn=sortcolumn, **em_component_args)
45 46
 
46 47
     @property
47 48
     ## Return an sqlalchemy table for type hierarchy
@@ -220,11 +221,15 @@ class EmType(EmComponent):
220 221
     def _subOrSup(self, sup = True):
221 222
         conn = self.db_engine().connect()
222 223
         htable = self._table_hierarchy
224
+        type_table = sqlutils.get_table(self.__class__)
225
+
223 226
         req = htable.select()
224 227
         if sup:
225
-            req = req.where(htable.c.subordinate_id == self.uid)
228
+            col = htable.c.subordinate_id
226 229
         else:
227
-            req = req.where(htable.c.superior_id == self.uid)
230
+            col = htable.c.superior_id
231
+
232
+        req = req.where(col == self.uid)
228 233
         res = conn.execute(req)
229 234
         rows = res.fetchall()
230 235
         conn.close()

Loading…
Anuluj
Zapisz