Browse Source

Cleaning & commenting + adding warning

Yann Weber 9 years ago
parent
commit
d199d571bd

+ 5
- 4
EditorialModel/components.py View File

@@ -10,7 +10,7 @@ import logging
10 10
 from collections import OrderedDict
11 11
 import hashlib
12 12
 
13
-import EditorialModel.fieldtypes as ftypes
13
+import EditorialModel
14 14
 from EditorialModel.exceptions import *
15 15
 from Lodel.utils.mlstring import MlString
16 16
 
@@ -64,9 +64,10 @@ class EmComponent(object):
64 64
     # Identify a component with his type and name
65 65
     def uniq_name(self):
66 66
         uname = self.__class__.__name__
67
-        try:
68
-            uname += '_'+self.em_class.name
69
-        except AttributeError: pass
67
+        if not isinstance(self, EditorialModel.fields.EmField):
68
+            try:
69
+                uname += '_'+self.em_class.name
70
+            except AttributeError: pass
70 71
         uname += '_'+self.name
71 72
         return uname
72 73
         

+ 5
- 1
EditorialModel/fields.py View File

@@ -1,6 +1,7 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3 3
 import importlib
4
+import warnings
4 5
 
5 6
 from EditorialModel.components import EmComponent
6 7
 from EditorialModel.exceptions import EmComponentCheckError
@@ -41,7 +42,10 @@ class EmField(EmComponent):
41 42
         self.default = default
42 43
         self.uniq = uniq
43 44
 
44
-        self.options = kwargs
45
+        if len(kwargs) > 0:
46
+            for kwargs_f in kwargs:
47
+                warnings.warn("Argument '%s' not used and will be invalid for EmField __init__"%kwargs_f,SyntaxWarning)
48
+            
45 49
 
46 50
         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)
47 51
 

+ 9
- 10
EditorialModel/migrationhandler/django.py View File

@@ -66,12 +66,11 @@ def create_model(name, fields=None, app_label='', module='', options=None, admin
66 66
 
67 67
 class DjangoMigrationHandler(object):
68 68
 
69
-    ##
69
+    ## @brief Instanciate a new DjangoMigrationHandler
70 70
     # @param app_name str : The django application name for models generation
71 71
     # @param debug bool : Set to True to be in debug mode
72
-    # @warning DONT use self.models it does not contains all the models (none of the through models for rel2type)
72
+    # @param dryrun bool : If true don't do any migration, only simulate them
73 73
     def __init__(self, app_name, debug=False, dryrun=False):
74
-        self.models = {}
75 74
         self.debug = debug
76 75
         self.app_name = app_name
77 76
         self.dryrun = dryrun
@@ -114,6 +113,9 @@ class DjangoMigrationHandler(object):
114 113
         return True
115 114
 
116 115
     ## @brief Print a debug message representing a migration
116
+    # @param uid int : The EmComponent uid
117
+    # @param initial_state dict | None : dict representing the fields that are changing
118
+    # @param new_state dict | None : dict represnting the new fields states
117 119
     def dump_migration(self, uid, initial_state, new_state):
118 120
         if self.debug:
119 121
             print("\n##############")
@@ -203,7 +205,7 @@ class DjangoMigrationHandler(object):
203 205
     # @note There is a problem with the related_name for superiors fk : The related name cannot be subordinates, it has to be the subordinates em_type name
204 206
     def em_to_models(self, edMod):
205 207
         
206
-        module_name = self.app_name+'models'
208
+        module_name = self.app_name+'.models'
207 209
 
208 210
         #Purging django models cache
209 211
         if self.app_name in django_cache.all_models:
@@ -211,9 +213,6 @@ class DjangoMigrationHandler(object):
211 213
                 del(django_cache.all_models[self.app_name][modname])
212 214
             #del(django_cache.all_models[self.app_name])
213 215
 
214
-        #This cache at instance level seems to be useless...
215
-        del(self.models)
216
-        self.models = {}
217 216
 
218 217
         app_name = self.app_name
219 218
         #Creating the document model
@@ -249,7 +248,8 @@ class DjangoMigrationHandler(object):
249 248
                     #emclass_fields[emfield.uniq_name] = models.CharField(max_length=56, default=emfield.uniq_name)
250 249
                     emclass_fields[emfield.uniq_name] = self.field_to_django(emfield, emclass)
251 250
             #print("Model for class %s created with fields : "%emclass.uniq_name, emclass_fields)
252
-            print("Model for class %s created"%emclass.uniq_name)
251
+            if self.debug:
252
+                print("Model for class %s created"%emclass.uniq_name)
253 253
             django_models['classes'][emclass.uniq_name] = create_model(emclass.uniq_name, emclass_fields, self.app_name, module_name, parent_class=django_models['doc'])
254 254
             
255 255
             #Creating the EmTypes models with EmClass inherithance
@@ -269,7 +269,6 @@ class DjangoMigrationHandler(object):
269 269
                     print("Model for type %s created"%emtype.uniq_name)
270 270
                 django_models['types'][emtype.uniq_name] = create_model(emtype.uniq_name, emtype_fields, self.app_name, module_name, parent_class=django_models['classes'][emclass.uniq_name])
271 271
 
272
-        self.models=django_models
273 272
         pass
274 273
 
275 274
     ## @brief Return a good django field type given a field
@@ -328,7 +327,7 @@ class DjangoMigrationHandler(object):
328 327
 
329 328
                 #through_model_name = f.uniq_name+assoc_comp.uniq_name+'to'+rtype.uniq_name
330 329
                 through_model_name = f.name+assoc_comp.name+'to'+rtype.name
331
-                module_name = self.app_name+'models'
330
+                module_name = self.app_name+'.models'
332 331
                 #model created
333 332
                 through_model = create_model(through_model_name, through_fields, self.app_name, module_name)
334 333
                 kwargs['through'] = through_model_name

+ 6
- 6
EditorialModel/test/me.json View File

@@ -9,7 +9,7 @@
9 9
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1"
10 10
   },
11 11
   "4" : {
12
-    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
12
+    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"3", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
13 13
   },
14 14
   "5" : {
15 15
     "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "fields_list":[7]
@@ -18,22 +18,22 @@
18 18
     "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "fields_list":[10]
19 19
   },
20 20
   "7" : {
21
-    "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
21
+    "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"3", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
22 22
   },
23 23
   "8" : {
24 24
     "component":"EmFieldGroup", "name":"civilité", "string":"{\"fre\":\"Civilité\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2"
25 25
   },
26 26
   "9" : {
27
-    "component":"EmField", "name":"nom", "string":"{\"fre\":\"Nom\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"8", "rel_to_type_id":"", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
27
+    "component":"EmField", "name":"nom", "string":"{\"fre\":\"Nom\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"8", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
28 28
   },
29 29
   "10" : {
30
-    "component":"EmField", "name":"prenom", "string":"{\"fre\":\"Preom\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"8", "rel_to_type_id":"", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
30
+    "component":"EmField", "name":"prenom", "string":"{\"fre\":\"Preom\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"8", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
31 31
   },
32 32
   "11" : {
33 33
     "component":"EmField", "name":"auteur", "string":"{\"fre\":\"Auteur\"}", "help_text":"{}", "rank":"3", "date_update":"", "date_create":"", "type":"rel2type", "fieldgroup_id":"17", "rel_to_type_id":"6", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
34 34
   },
35 35
   "12" : {
36
-    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help_text":"{}", "rank":"4", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"17", "rel_to_type_id":"", "rel_field_id":"11", "optional":0, "internal":"", "icon":"0"
36
+    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help_text":"{}", "rank":"4", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"17", "rel_field_id":"11", "optional":0, "internal":"", "icon":"0"
37 37
   },
38 38
   "13" : {
39 39
     "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
@@ -45,7 +45,7 @@
45 45
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"
46 46
   },
47 47
   "16" : {
48
-    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"15", "rel_to_type_id":"", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
48
+    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"15", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
49 49
   },
50 50
   "17" : {
51 51
     "component":"EmFieldGroup", "name":"gens", "string":"{\"fre\":\"Gens\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "class_id":"1"

Loading…
Cancel
Save