Browse Source

Updated some fieldtypes and added a primary key (pk) fieldtype

Yann Weber 9 years ago
parent
commit
4eef4398a3

+ 21
- 6
EditorialModel/fields.py View File

19
     ranked_in = 'fieldgroup_id'
19
     ranked_in = 'fieldgroup_id'
20
 
20
 
21
     ## Instanciate a new EmField
21
     ## Instanciate a new EmField
22
-    # @todo define and test type for icon and fieldtype
22
+    # @todo define and test type for icon
23
     # @warning nullable == True by default
23
     # @warning nullable == True by default
24
+    # @param model Model : Editorial model
25
+    # @param uid int : Uniq id
26
+    # @param fieldtype str : Fieldtype name ( see Editorialmodel::fieldtypes )
27
+    # @param optional bool : Indicate if a field is optional or not
28
+    # @param internal str|bool : If False the field is not internal, else it can takes value in "object" or "automatic"
29
+    # @param rel_field_id int|None : If not None indicates that the field is a relation attribute (and the value is the UID of the rel2type field)
30
+    # @param nullable bool : If True None values are allowed
31
+    # @param default * : Default field value
32
+    # @param uniq bool : if True the value should be uniq in the db table
33
+    # @param **kwargs : more keywords arguments for the fieldtype
24
     def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable=True, default=None, uniq=False, **kwargs):
34
     def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable=True, default=None, uniq=False, **kwargs):
25
 
35
 
26
         self.fieldgroup_id = fieldgroup_id
36
         self.fieldgroup_id = fieldgroup_id
27
         self.check_type('fieldgroup_id', int)
37
         self.check_type('fieldgroup_id', int)
28
-        self.optional = optional
29
-        self.check_type('optional', bool)
30
-        self.internal = internal
31
-        self.check_type('internal', bool)
38
+        self.optional = bool(optional)
39
+
40
+        if not internal:
41
+            self.internal = False
42
+        else:
43
+            if internal.lower() not in ['object', 'automatic']:
44
+                raise ValueError("The internal arguments possible values are : [False, 'object', 'automatic']")
45
+            self.internal = internal.lower()
46
+
32
         self.rel_field_id = rel_field_id
47
         self.rel_field_id = rel_field_id
33
         self.check_type('rel_field_id', (int, type(None)))
48
         self.check_type('rel_field_id', (int, type(None)))
34
         self.icon = icon
49
         self.icon = icon
59
     @staticmethod
74
     @staticmethod
60
     ## @brief Return the list of allowed field type
75
     ## @brief Return the list of allowed field type
61
     def fieldtypes_list():
76
     def fieldtypes_list():
62
-        return [f for f in EditorialModel.fieldtypes.__all__ if f != '__init__']
77
+        return [f for f in EditorialModel.fieldtypes.__all__ if f != '__init__' and f != 'generic' ]
63
 
78
 
64
     ## @brief Get the fieldtype instance
79
     ## @brief Get the fieldtype instance
65
     # @return a fieldtype instance
80
     # @return a fieldtype instance

+ 1
- 2
EditorialModel/fieldtypes/datetime.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
-from EditorialModel.fieldtypes import GenericFieldType
4
-
3
+from EditorialModel.fieldtypes.generic import GenericFieldType
5
 
4
 
6
 class EmFieldType(GenericFieldType):
5
 class EmFieldType(GenericFieldType):
7
 
6
 

+ 1
- 2
EditorialModel/fieldtypes/file.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
-from EditorialModel.fieldtypes import GenericFieldType
4
-
3
+from EditorialModel.fieldtypes.generic import GenericFieldType
5
 
4
 
6
 class EmFieldType(GenericFieldType):
5
 class EmFieldType(GenericFieldType):
7
 
6
 

+ 3
- 1
EditorialModel/fieldtypes/generic.py View File

16
     # @param default ? : The default value
16
     # @param default ? : The default value
17
     # @param nullable bool : is None allowed as value ?
17
     # @param nullable bool : is None allowed as value ?
18
     # @param check_function function : A callback check function that takes 1 argument and raise a TypeError if the validation fails
18
     # @param check_function function : A callback check function that takes 1 argument and raise a TypeError if the validation fails
19
+    # @param uniq bool : Indicate if a field should handle uniq values
20
+    # @param primary bool : If true the field is a primary key
19
     # @param **kwargs dict : Other arguments
21
     # @param **kwargs dict : Other arguments
20
     # @throw NotImplementedError if called directly
22
     # @throw NotImplementedError if called directly
21
     # @throw AttributeError if bad ftype
23
     # @throw AttributeError if bad ftype
22
     # @throw AttributeError if bad check_function
24
     # @throw AttributeError if bad check_function
23
-    def __init__(self, ftype, default = None, nullable = True, check_function = None, uniq = False, **kwargs):
25
+    def __init__(self, ftype, default = None, nullable = True, check_function = None, uniq = False, primary=False, **kwargs):
24
         if self.__class__ == GenericFieldType:
26
         if self.__class__ == GenericFieldType:
25
             raise NotImplementedError("Abstract class")
27
             raise NotImplementedError("Abstract class")
26
         
28
         

+ 10
- 0
EditorialModel/fieldtypes/pk.py View File

1
+#-*- coding: utf-8 -*-
2
+
3
+import EditorialModel
4
+
5
+class EmFieldType(EditorialModel.fieldtypes.integer.EmFieldType):
6
+    
7
+    help = 'Integer primary key fieldtype'
8
+
9
+    def __init__(self):
10
+        super(EmFieldType, self).__init__(ftype='int', primary=True)

+ 1
- 1
EditorialModel/fieldtypes/regexchar.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
 import re
3
 import re
4
-import EditorialModel.fieldtypes.char.EmFieldType
4
+import EditorialModel
5
 
5
 
6
 class EmFieldType(EditorialModel.fieldtypes.char.EmFieldType):
6
 class EmFieldType(EditorialModel.fieldtypes.char.EmFieldType):
7
 
7
 

Loading…
Cancel
Save