Quellcode durchsuchen

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

Yann Weber vor 9 Jahren
Ursprung
Commit
4eef4398a3

+ 21
- 6
EditorialModel/fields.py Datei anzeigen

@@ -19,16 +19,31 @@ class EmField(EmComponent):
19 19
     ranked_in = 'fieldgroup_id'
20 20
 
21 21
     ## Instanciate a new EmField
22
-    # @todo define and test type for icon and fieldtype
22
+    # @todo define and test type for icon
23 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 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 36
         self.fieldgroup_id = fieldgroup_id
27 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 47
         self.rel_field_id = rel_field_id
33 48
         self.check_type('rel_field_id', (int, type(None)))
34 49
         self.icon = icon
@@ -59,7 +74,7 @@ class EmField(EmComponent):
59 74
     @staticmethod
60 75
     ## @brief Return the list of allowed field type
61 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 79
     ## @brief Get the fieldtype instance
65 80
     # @return a fieldtype instance

+ 1
- 2
EditorialModel/fieldtypes/datetime.py Datei anzeigen

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

+ 1
- 2
EditorialModel/fieldtypes/file.py Datei anzeigen

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

+ 3
- 1
EditorialModel/fieldtypes/generic.py Datei anzeigen

@@ -16,11 +16,13 @@ class GenericFieldType(object):
16 16
     # @param default ? : The default value
17 17
     # @param nullable bool : is None allowed as value ?
18 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 21
     # @param **kwargs dict : Other arguments
20 22
     # @throw NotImplementedError if called directly
21 23
     # @throw AttributeError if bad ftype
22 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 26
         if self.__class__ == GenericFieldType:
25 27
             raise NotImplementedError("Abstract class")
26 28
         

+ 10
- 0
EditorialModel/fieldtypes/pk.py Datei anzeigen

@@ -0,0 +1,10 @@
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 Datei anzeigen

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

Laden…
Abbrechen
Speichern