Browse Source

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

Yann Weber 9 years ago
parent
commit
24865eb6ee

+ 1
- 1
lodel/leapi/datahandlers/data_field.py View File

15
         if self.__class__ == DataField:
15
         if self.__class__ == DataField:
16
             raise NotImplementedError("Abstract class")
16
             raise NotImplementedError("Abstract class")
17
 
17
 
18
-        super().__init__(internal, **kwargs)
18
+        super(self.__class__, self).__init__(internal, **kwargs)
19
 
19
 
20
         self.nullable = nullable
20
         self.nullable = nullable
21
         self.uniq = uniq
21
         self.uniq = uniq

+ 1
- 1
lodel/leapi/datahandlers/data_fields/__init__.py View File

1
-__author__ = 'roland'
1
+

+ 2
- 2
lodel/leapi/datahandlers/data_fields/bool.py View File

11
     def __init__(self, **kwargs):
11
     def __init__(self, **kwargs):
12
         if 'check_data_value' not in kwargs:
12
         if 'check_data_value' not in kwargs:
13
             kwargs['check_data_value'] = self.check_value
13
             kwargs['check_data_value'] = self.check_value
14
-        super(Bool, self).__init__(ftype='bool', **kwargs)
14
+        super(self.__class__, self).__init__(ftype='bool', **kwargs)
15
 
15
 
16
-    def check_value(self, value):
16
+    def _check_data_value(self, value):
17
         error = None
17
         error = None
18
         try:
18
         try:
19
             value = bool(value)
19
             value = bool(value)

+ 1
- 1
lodel/leapi/datahandlers/data_fields/datetime.py View File

13
     def __init__(self, now_on_update=False, now_on_create=False, **kwargs):
13
     def __init__(self, now_on_update=False, now_on_create=False, **kwargs):
14
         self.now_on_update = now_on_update
14
         self.now_on_update = now_on_update
15
         self.now_on_create = now_on_create
15
         self.now_on_create = now_on_create
16
-        super(Datetime, self).__init__(**kwargs)
16
+        super(self.__class__, self).__init__(**kwargs)

+ 1
- 1
lodel/leapi/datahandlers/data_fields/file.py View File

9
     # @param **kwargs
9
     # @param **kwargs
10
     def __init__(self, upload_path=None, **kwargs):
10
     def __init__(self, upload_path=None, **kwargs):
11
         self.upload_path = upload_path
11
         self.upload_path = upload_path
12
-        super(File, self).__init__(ftype='file', **kwargs)
12
+        super(self.__class__, self).__init__(ftype='file', **kwargs)

+ 1
- 1
lodel/leapi/datahandlers/data_fields/format.py View File

15
     def __init__(self, format_string, field_list, max_length, **kwargs):
15
     def __init__(self, format_string, field_list, max_length, **kwargs):
16
         self._field_list = field_list
16
         self._field_list = field_list
17
         self._format_string = format_string
17
         self._format_string = format_string
18
-        super().__init__(internal='automatic', max_length=max_length)
18
+        super(self.__class__, self).__init__(internal='automatic', max_length=max_length)

+ 1
- 1
lodel/leapi/datahandlers/data_fields/integer.py View File

8
     ftype = 'int'
8
     ftype = 'int'
9
 
9
 
10
     def __init__(self, **kwargs):
10
     def __init__(self, **kwargs):
11
-        super(Integer, self).__init__(ftype='int', **kwargs)
11
+        super(self.__class__, self).__init__(ftype='int', **kwargs)
12
 
12
 
13
     def _check_data_value(self, value):
13
     def _check_data_value(self, value):
14
         error = None
14
         error = None

+ 1
- 1
lodel/leapi/datahandlers/data_fields/regexvarchar.py View File

15
         self.regex = regex
15
         self.regex = regex
16
         self.compiled_re = re.compile(regex)  # trigger an error if invalid regex
16
         self.compiled_re = re.compile(regex)  # trigger an error if invalid regex
17
 
17
 
18
-        super().__init__(max_length=max_length, **kwargs)
18
+        super(self.__class__, self).__init__(max_length=max_length, **kwargs)
19
 
19
 
20
     def _check_data_value(self, value):
20
     def _check_data_value(self, value):
21
         error = None
21
         error = None

+ 2
- 2
lodel/leapi/datahandlers/data_fields/text.py View File

6
     help = 'A text field (big string)'
6
     help = 'A text field (big string)'
7
     ftype = 'text'
7
     ftype = 'text'
8
 
8
 
9
-    def __init__(self):
10
-        super(Text, self).__init__(ftype='text', **kwargs)
9
+    def __init__(self, **kwargs):
10
+        super(self.__class__, self).__init__(ftype='text', **kwargs)

+ 1
- 1
lodel/leapi/datahandlers/data_fields/uid.py View File

11
     def __init__(self, is_id_class, **kwargs):
11
     def __init__(self, is_id_class, **kwargs):
12
         self._is_id_class = is_id_class
12
         self._is_id_class = is_id_class
13
         kwargs['internal'] = 'automatic'
13
         kwargs['internal'] = 'automatic'
14
-        super().__init__(is_id_class=is_id_class, **kwargs)
14
+        super(self.__class__, self).__init__(is_id_class=is_id_class, **kwargs)
15
 
15
 
16
     def _check_data_value(self, value):
16
     def _check_data_value(self, value):
17
         return (value, None)
17
         return (value, None)

+ 1
- 1
lodel/leapi/datahandlers/data_fields/varchar.py View File

9
     # @brief max_length int: The maximum length of this field
9
     # @brief max_length int: The maximum length of this field
10
     def __init__(self, max_length=64, **kwargs):
10
     def __init__(self, max_length=64, **kwargs):
11
         self.max_length = int(max_length)
11
         self.max_length = int(max_length)
12
-        super().__init__(**kwargs)
12
+        super(self.__class__, self).__init__(**kwargs)

+ 35
- 1
lodel/leapi/datahandlers/field_data_handler.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import importlib
2
 import importlib
3
 
3
 
4
+
4
 class FieldDataHandler(object):
5
 class FieldDataHandler(object):
5
 
6
 
6
     help_text = 'Generic Field Data Handler'
7
     help_text = 'Generic Field Data Handler'
12
     # @param internal False | str : define whether or not a field is internal
13
     # @param internal False | str : define whether or not a field is internal
13
     # @param immutable bool : indicates if the fieldtype has to be defined in child classes of LeObject or if it is designed globally and immutable
14
     # @param immutable bool : indicates if the fieldtype has to be defined in child classes of LeObject or if it is designed globally and immutable
14
     # @param **args
15
     # @param **args
16
+    # @throw NotImplementedError if it is instanciated directly
15
     def __init__(self, internal=False, immutable=False, **args):
17
     def __init__(self, internal=False, immutable=False, **args):
18
+        if self.__class__ == GenericFieldType:
19
+            raise NotImplementedError("Abstract class")
20
+
16
         self.internal = internal  # Check this value ?
21
         self.internal = internal  # Check this value ?
17
         self.immutable = bool(immutable)
22
         self.immutable = bool(immutable)
18
 
23
 
28
     ## @brief checks if a fieldtype is internal
33
     ## @brief checks if a fieldtype is internal
29
     # @return bool
34
     # @return bool
30
     def is_internal(self):
35
     def is_internal(self):
31
-        return self.internal != False
36
+        return self.internal is not False
32
 
37
 
33
     ## @brief calls the data_field defined _check_data_value() method
38
     ## @brief calls the data_field defined _check_data_value() method
34
     # @return tuple (value, error|None)
39
     # @return tuple (value, error|None)
38
     def _check_data_value(self, value):
43
     def _check_data_value(self, value):
39
         return (value, None)
44
         return (value, None)
40
 
45
 
46
+    ## @brief Build field value
47
+    # @param emcomponent EmComponent : An EmComponent child class instance
48
+    # @param fname str : The field name
49
+    # @param datas dict : dict storing fields values (from the component)
50
+    # @param cur_value : the value from the current field (identified by fieldname)
51
+    def construct_data(self, emcomponent, fname, datas, cur_value):
52
+        emcomponent_fields = emcomponent.fields()
53
+        fname_data_handler = None
54
+        if fname in emcomponent_fields:
55
+            fname_data_handler = FieldDataHandler.from_name(emcomponent_fields[fname])
56
+
57
+        if fname in datas.keys():
58
+            return cur_value
59
+        elif fname_data_handler is not None and hasattr(fname_data_handler, 'default'):
60
+                return fname_data_handler.default
61
+        elif fname_data_handler is not None and fname_data_handler.nullable:
62
+                return None
63
+
64
+        raise RuntimeError("Unable to construct data for field %s", fname)
65
+
66
+    ## @brief Check datas consistency
67
+    # @param emcomponent EmComponent : An EmComponent child class instance
68
+    # @param fname : the field name
69
+    # @param datas dict : dict storing fields values
70
+    # @return an Exception instance if fails else True
71
+    # @todo A implémenter
72
+    def check_data_consistency(self, emcomponent, fname, datas):
73
+        return True
74
+
41
     ## @brief given a field type name, returns the associated python class
75
     ## @brief given a field type name, returns the associated python class
42
     # @param fieldtype_name str : A field type name
76
     # @param fieldtype_name str : A field type name
43
     # @return DataField child class
77
     # @return DataField child class

Loading…
Cancel
Save