|
@@ -0,0 +1,37 @@
|
|
1
|
+#-*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+import leapi.lecrud as lecrud
|
|
4
|
+import leapi.letype as letype
|
|
5
|
+
|
|
6
|
+from .generic import FieldTypeError
|
|
7
|
+from . import integer
|
|
8
|
+
|
|
9
|
+class EmFieldType(integer.EmFieldType):
|
|
10
|
+
|
|
11
|
+ help = 'Fieldtypes designed to handle editorial model UID for LeObjects'
|
|
12
|
+
|
|
13
|
+ def __init__(self, id_class=True, **kwargs):
|
|
14
|
+ kwargs['internal'] = 'automatic'
|
|
15
|
+ super(EmFieldType, self).__init__(id_class = id_class, **kwargs)
|
|
16
|
+
|
|
17
|
+ def _check_data_value(self, value):
|
|
18
|
+ if not( value is None):
|
|
19
|
+ return ValueError("Cannot set this value. Only None is authorized")
|
|
20
|
+
|
|
21
|
+ def construct_data(self, lec, fname, datas):
|
|
22
|
+ if isinstance(lec, letype._LeType):
|
|
23
|
+ # if None try to fetch data from lec itself
|
|
24
|
+ fname[datas] = lec.em_uid()[ 0 if self.class_id else 1]
|
|
25
|
+ else:
|
|
26
|
+ raise RuntimeError("The LeObject is not a LeType")
|
|
27
|
+
|
|
28
|
+ def check_data_consistency(self, lec, fname, datas):
|
|
29
|
+ if isinstance(lec, lecrud._LeCrud) and lec.implements_letype():
|
|
30
|
+ if datas[fname] != (lec._class_id if self.class_id else lec._type_id):
|
|
31
|
+ return FieldTypeError("Given Editorial model uid doesn't fit with given LeObject")
|
|
32
|
+ else:
|
|
33
|
+ return FieldTypeError("You have to give a LeType !!!")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|