Browse Source

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

Yann Weber 9 years ago
parent
commit
47ce122e93
3 changed files with 20 additions and 15 deletions
  1. 8
    8
      EditorialModel/classes.py
  2. 3
    3
      EditorialModel/fields.py
  3. 9
    4
      EditorialModel/types.py

+ 8
- 8
EditorialModel/classes.py View File

15
 
15
 
16
 ## @brief Manipulate Classes of the Editorial Model
16
 ## @brief Manipulate Classes of the Editorial Model
17
 # Create classes of object.
17
 # Create classes of object.
18
-#@see EmClass, EmType, EmFieldGroup, EmField
18
+# @see EmClass, EmType, EmFieldGroup, EmField
19
+# @todo sortcolumn handling
19
 class EmClass(EmComponent):
20
 class EmClass(EmComponent):
20
 
21
 
21
     table = 'em_class'
22
     table = 'em_class'
25
     # @see EditorialModel::components::EmComponent::_fields
26
     # @see EditorialModel::components::EmComponent::_fields
26
     _fields = [
27
     _fields = [
27
         ('classtype', ftypes.EmField_char),
28
         ('classtype', ftypes.EmField_char),
28
-        ('icon', ftypes.EmField_integer),
29
+        ('icon', ftypes.EmField_icon),
29
         ('sortcolumn', ftypes.EmField_char)
30
         ('sortcolumn', ftypes.EmField_char)
30
     ]
31
     ]
31
 
32
 
35
     # @return An EmClass instance
36
     # @return An EmClass instance
36
     # @throw EmComponentExistError if an EmClass with this name and a different classtype exists
37
     # @throw EmComponentExistError if an EmClass with this name and a different classtype exists
37
     @classmethod
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
     @classmethod
42
     @classmethod
42
     ## Isolate SQL for EmClass::create
43
     ## Isolate SQL for EmClass::create
43
-    # @todo Remove hardcoded default value for icon
44
     # @return An instance of EmClass
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
         #Create a new entry in the em_class table
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
         dbe = result.db_engine()
49
         dbe = result.db_engine()
51
         conn = dbe.connect()
50
         conn = dbe.connect()
162
                 linked_types.append(EditorialModel.types.EmType(table_name_elements[1]))
161
                 linked_types.append(EditorialModel.types.EmType(table_name_elements[1]))
163
 
162
 
164
         return linked_types
163
         return linked_types
164
+

+ 3
- 3
EditorialModel/fields.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
 from EditorialModel.components import EmComponent, EmComponentNotExistError
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
 from EditorialModel.fieldgroups import EmFieldGroup
5
 from EditorialModel.fieldgroups import EmFieldGroup
6
 from EditorialModel.classes import EmClass
6
 from EditorialModel.classes import EmClass
7
 
7
 
30
         ('rel_field_id', EmField_integer),
30
         ('rel_field_id', EmField_integer),
31
         ('optional', EmField_boolean),
31
         ('optional', EmField_boolean),
32
         ('internal', EmField_boolean),
32
         ('internal', EmField_boolean),
33
-        ('icon', EmField_integer)
33
+        ('icon', EmField_icon)
34
     ]
34
     ]
35
 
35
 
36
     ## Create (Function)
36
     ## Create (Function)
55
     # @see EmComponent::__init__()
55
     # @see EmComponent::__init__()
56
     # @staticmethod
56
     # @staticmethod
57
     @classmethod
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
         created_field = super(EmField, cls).create(
59
         created_field = super(EmField, cls).create(
60
             name=name,
60
             name=name,
61
             fieldgroup_id=fieldgroup.uid,
61
             fieldgroup_id=fieldgroup.uid,

+ 9
- 4
EditorialModel/types.py View File

17
 # EmType with special fields called relation_to_type fields
17
 # EmType with special fields called relation_to_type fields
18
 #
18
 #
19
 # @see EditorialModel::components::EmComponent
19
 # @see EditorialModel::components::EmComponent
20
+# @todo sortcolumn handling
20
 class EmType(EmComponent):
21
 class EmType(EmComponent):
21
     table = 'em_type'
22
     table = 'em_type'
22
     table_hierarchy = 'em_type_hierarchy'
23
     table_hierarchy = 'em_type_hierarchy'
40
     # @see EmComponent::__init__()
41
     # @see EmComponent::__init__()
41
     # 
42
     # 
42
     # @todo check that em_class is an EmClass object (fieldtypes can handle it)
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
     @property
47
     @property
47
     ## Return an sqlalchemy table for type hierarchy
48
     ## Return an sqlalchemy table for type hierarchy
220
     def _subOrSup(self, sup = True):
221
     def _subOrSup(self, sup = True):
221
         conn = self.db_engine().connect()
222
         conn = self.db_engine().connect()
222
         htable = self._table_hierarchy
223
         htable = self._table_hierarchy
224
+        type_table = sqlutils.get_table(self.__class__)
225
+
223
         req = htable.select()
226
         req = htable.select()
224
         if sup:
227
         if sup:
225
-            req = req.where(htable.c.subordinate_id == self.uid)
228
+            col = htable.c.subordinate_id
226
         else:
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
         res = conn.execute(req)
233
         res = conn.execute(req)
229
         rows = res.fetchall()
234
         rows = res.fetchall()
230
         conn.close()
235
         conn.close()

Loading…
Cancel
Save