|
@@ -5,6 +5,7 @@ import importlib
|
5
|
5
|
from EditorialModel.components import EmComponent
|
6
|
6
|
from EditorialModel.exceptions import EmComponentCheckError
|
7
|
7
|
import EditorialModel
|
|
8
|
+import EditorialModel.fieldtypes
|
8
|
9
|
from django.db import models
|
9
|
10
|
|
10
|
11
|
## EmField (Class)
|
|
@@ -15,28 +16,16 @@ class EmField(EmComponent):
|
15
|
16
|
ranked_in = 'fieldgroup_id'
|
16
|
17
|
|
17
|
18
|
ftype = None
|
18
|
|
-
|
19
|
|
- fieldtypes = {
|
20
|
|
- 'int': models.IntegerField,
|
21
|
|
- 'integer': models.IntegerField,
|
22
|
|
- 'bigint': models.BigIntegerField,
|
23
|
|
- 'smallint': models.SmallIntegerField,
|
24
|
|
- 'boolean': models.BooleanField,
|
25
|
|
- 'bool': models.BooleanField,
|
26
|
|
- 'float': models.FloatField,
|
27
|
|
- 'char': models.CharField,
|
28
|
|
- 'varchar': models.CharField,
|
29
|
|
- 'text': models.TextField,
|
30
|
|
- 'time': models.TimeField,
|
31
|
|
- 'date': models.DateField,
|
32
|
|
- 'datetime': models.DateTimeField,
|
33
|
|
- }
|
|
19
|
+ help = 'Default help text'
|
34
|
20
|
|
35
|
21
|
## Instanciate a new EmField
|
36
|
22
|
# @todo define and test type for icon and fieldtype
|
37
|
23
|
# @warning nullable == True by default
|
38
|
24
|
def __init__(self, model, uid, name, fieldgroup_id, 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):
|
39
|
25
|
|
|
26
|
+ if self.ftype == None:
|
|
27
|
+ raise NotImplementedError("Trying to instanciate an EmField and not one of the fieldtypes child classes")
|
|
28
|
+
|
40
|
29
|
self.fieldgroup_id = fieldgroup_id
|
41
|
30
|
self.check_type('fieldgroup_id', int)
|
42
|
31
|
self.optional = optional
|
|
@@ -57,10 +46,19 @@ class EmField(EmComponent):
|
57
|
46
|
super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
|
58
|
47
|
|
59
|
48
|
@staticmethod
|
|
49
|
+ ## @brief Return an EmField subclass given a wanted field type
|
|
50
|
+ # @return An EmField subclass
|
|
51
|
+ # @throw When not found
|
|
52
|
+ # @see EmField::fieldtypes()
|
60
|
53
|
def get_field_class(ftype, **kwargs):
|
61
|
54
|
ftype_module = importlib.import_module('EditorialModel.fieldtypes.%s'%ftype)
|
62
|
55
|
return ftype_module.fclass
|
63
|
56
|
|
|
57
|
+ @staticmethod
|
|
58
|
+ ## @brief Return the list of allowed field type
|
|
59
|
+ def fieldtypes_list():
|
|
60
|
+ return [ f for f in EditorialModel.fieldtypes.__all__ if f != '__init__' ]
|
|
61
|
+
|
64
|
62
|
## @brief Abstract method that should return a validation function
|
65
|
63
|
# @param raise_e Exception : if not valid raise this exception
|
66
|
64
|
# @param ret_valid : if valid return this value
|
|
@@ -98,19 +96,3 @@ class EmField(EmComponent):
|
98
|
96
|
def delete_check(self):
|
99
|
97
|
return True
|
100
|
98
|
|
101
|
|
- """
|
102
|
|
- def to_django(self):
|
103
|
|
- if self.fieldtype in ('varchar', 'char'):
|
104
|
|
- max_length = None if 'max_length' not in self.options else self.options['max_length']
|
105
|
|
- return self.fieldtypes[self.fieldtype](max_length=max_length, **self.options)
|
106
|
|
-
|
107
|
|
- if self.fieldtype in ('time', 'datetime', 'date'):
|
108
|
|
- auto_now = False if 'auto_now' not in self.options else self.options['auto_now']
|
109
|
|
- auto_now_add = False if 'auto_now_add' not in self.options else self.options['auto_now_add']
|
110
|
|
- return self.fieldtypes[self.fieldtype](auto_now=auto_now, auto_now_add=auto_now_add, **self.options)
|
111
|
|
-
|
112
|
|
- if self.fieldtype == 'boolean' and ('nullable' in self.options and self.options['nullable'] == 1):
|
113
|
|
- return models.NullBooleanField(**self.options)
|
114
|
|
-
|
115
|
|
- return self.fieldtypes[self.fieldtype](**self.options)
|
116
|
|
- """
|