1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-03-15 15:52:02 +01:00

Cleaning & commenting + adding warning

This commit is contained in:
Yann 2015-09-18 11:17:47 +02:00
commit d199d571bd
4 changed files with 25 additions and 21 deletions

View file

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

View file

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

View file

@ -66,12 +66,11 @@ def create_model(name, fields=None, app_label='', module='', options=None, admin
class DjangoMigrationHandler(object):
##
## @brief Instanciate a new DjangoMigrationHandler
# @param app_name str : The django application name for models generation
# @param debug bool : Set to True to be in debug mode
# @warning DONT use self.models it does not contains all the models (none of the through models for rel2type)
# @param dryrun bool : If true don't do any migration, only simulate them
def __init__(self, app_name, debug=False, dryrun=False):
self.models = {}
self.debug = debug
self.app_name = app_name
self.dryrun = dryrun
@ -114,6 +113,9 @@ class DjangoMigrationHandler(object):
return True
## @brief Print a debug message representing a migration
# @param uid int : The EmComponent uid
# @param initial_state dict | None : dict representing the fields that are changing
# @param new_state dict | None : dict represnting the new fields states
def dump_migration(self, uid, initial_state, new_state):
if self.debug:
print("\n##############")
@ -203,7 +205,7 @@ class DjangoMigrationHandler(object):
# @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
def em_to_models(self, edMod):
module_name = self.app_name+'models'
module_name = self.app_name+'.models'
#Purging django models cache
if self.app_name in django_cache.all_models:
@ -211,9 +213,6 @@ class DjangoMigrationHandler(object):
del(django_cache.all_models[self.app_name][modname])
#del(django_cache.all_models[self.app_name])
#This cache at instance level seems to be useless...
del(self.models)
self.models = {}
app_name = self.app_name
#Creating the document model
@ -249,7 +248,8 @@ class DjangoMigrationHandler(object):
#emclass_fields[emfield.uniq_name] = models.CharField(max_length=56, default=emfield.uniq_name)
emclass_fields[emfield.uniq_name] = self.field_to_django(emfield, emclass)
#print("Model for class %s created with fields : "%emclass.uniq_name, emclass_fields)
print("Model for class %s created"%emclass.uniq_name)
if self.debug:
print("Model for class %s created"%emclass.uniq_name)
django_models['classes'][emclass.uniq_name] = create_model(emclass.uniq_name, emclass_fields, self.app_name, module_name, parent_class=django_models['doc'])
#Creating the EmTypes models with EmClass inherithance
@ -269,7 +269,6 @@ class DjangoMigrationHandler(object):
print("Model for type %s created"%emtype.uniq_name)
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])
self.models=django_models
pass
## @brief Return a good django field type given a field
@ -328,7 +327,7 @@ class DjangoMigrationHandler(object):
#through_model_name = f.uniq_name+assoc_comp.uniq_name+'to'+rtype.uniq_name
through_model_name = f.name+assoc_comp.name+'to'+rtype.name
module_name = self.app_name+'models'
module_name = self.app_name+'.models'
#model created
through_model = create_model(through_model_name, through_fields, self.app_name, module_name)
kwargs['through'] = through_model_name

View file

@ -9,7 +9,7 @@
"component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1"
},
"4" : {
"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"
"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"
},
"5" : {
"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 @@
"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]
},
"7" : {
"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"
"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"
},
"8" : {
"component":"EmFieldGroup", "name":"civilité", "string":"{\"fre\":\"Civilité\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2"
},
"9" : {
"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"
"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"
},
"10" : {
"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"
"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"
},
"11" : {
"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"
},
"12" : {
"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"
"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"
},
"13" : {
"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 @@
"component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"
},
"16" : {
"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"
"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"
},
"17" : {
"component":"EmFieldGroup", "name":"gens", "string":"{\"fre\":\"Gens\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "class_id":"1"