mirror of
https://github.com/yweber/lodel2.git
synced 2025-11-21 13:19:16 +01:00
Fieldgroups are deleted
This commit is contained in:
parent
cb7a37e7a2
commit
10379c6a95
16 changed files with 475 additions and 767 deletions
|
|
@ -18,9 +18,6 @@ class EmClass(EmComponent):
|
|||
|
||||
ranked_in = 'classtype'
|
||||
|
||||
## @brief default fieldgroup name
|
||||
default_fieldgroup = '_default'
|
||||
|
||||
## EmClass instanciation
|
||||
# @todo Classtype initialisation and test is not good EmClassType should give an answer or something like that
|
||||
# @todo defines types check for icon and sortcolumn
|
||||
|
|
@ -60,19 +57,14 @@ class EmClass(EmComponent):
|
|||
for emtype in self.model.components(EditorialModel.types.EmType):
|
||||
if emtype.class_id == self.uid:
|
||||
return False
|
||||
for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
|
||||
if fieldgroup.name == self.default_fieldgroup:
|
||||
#checking that the default fieldgroup contains only default fields
|
||||
for fname in [f.name for f in fieldgroup.fields()]:
|
||||
if fname not in EmClassType.get(self.classtype)['default_fields'].keys():
|
||||
return False
|
||||
elif fieldgroup.class_id == self.uid and fieldgroup.name != self.default_fieldgroup:
|
||||
return False
|
||||
#If the class contains EmField that are not added by default, you cannot delete the EmClass
|
||||
if len([f for f in self.fields() if f.name not in self.default_fields_list().keys()]) > 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
## Retrieve list of the field_groups of this class
|
||||
# @return A list of fieldgroups instance
|
||||
def fieldgroups(self):
|
||||
def _fieldgroups(self):
|
||||
ret = []
|
||||
for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
|
||||
if fieldgroup.class_id == self.uid:
|
||||
|
|
@ -82,11 +74,7 @@ class EmClass(EmComponent):
|
|||
## Retrieve list of fields
|
||||
# @return fields [EmField]:
|
||||
def fields(self, relational = True):
|
||||
fieldgroups = self.fieldgroups()
|
||||
fields = []
|
||||
for fieldgroup in fieldgroups:
|
||||
fields += fieldgroup.fields(relational=relational)
|
||||
return fields
|
||||
return [ f for f in self.model.components('EmField') if f.class_id == self.uid ]
|
||||
|
||||
## Retrieve list of type of this class
|
||||
# @return types [EditorialModel.types.EmType]:
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class EmComponent(object):
|
|||
attributes_dump[attr_name] = attributes_dump[attr_name].uid
|
||||
elif isinstance(attributes_dump[attr_name], MlString):
|
||||
attributes_dump[attr_name] = attributes_dump[attr_name].__str__()
|
||||
attributes_dump['component'] = 'EmField' if isinstance(self, EditorialModel.fields.EmField) else self.__class__.__name__
|
||||
attributes_dump['component'] = self.__class__.__name__
|
||||
|
||||
return attributes_dump
|
||||
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
from EditorialModel.components import EmComponent
|
||||
from EditorialModel.fields import EmField
|
||||
from EditorialModel.classes import EmClass
|
||||
from EditorialModel.exceptions import EmComponentCheckError
|
||||
|
||||
|
||||
## Represents groups of EmField associated with an EmClass
|
||||
#
|
||||
# EmClass fields representation is organised with EmFieldGroup
|
||||
# @see EditorialModel::fields::EmField EditorialModel::classes::EmClass
|
||||
class EmFieldGroup(EmComponent):
|
||||
|
||||
ranked_in = 'class_id'
|
||||
|
||||
## EmFieldGroup instanciation
|
||||
def __init__(self, model, uid, name, class_id, string=None, help_text=None, date_update=None, date_create=None, rank=None):
|
||||
self.class_id = class_id
|
||||
self.check_type('class_id', int)
|
||||
super(EmFieldGroup, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
|
||||
|
||||
@property
|
||||
def em_class(self):
|
||||
return self.model.component(self.class_id)
|
||||
|
||||
## Check if the EmFieldGroup is valid
|
||||
# @throw EmComponentCheckError if fails
|
||||
def check(self):
|
||||
super(EmFieldGroup, self).check()
|
||||
em_class = self.model.component(self.class_id)
|
||||
if not em_class:
|
||||
raise EmComponentCheckError("class_id contains a non existing uid '%s'" % str(self.class_id))
|
||||
if not isinstance(em_class, EmClass):
|
||||
raise EmComponentCheckError("class_id cointains an uid from a component that is not an EmClass but an %s" % type(em_class))
|
||||
|
||||
## Deletes a fieldgroup
|
||||
# @return True if the deletion is possible, False if not
|
||||
def delete_check(self):
|
||||
# all the EmField objects contained in this fieldgroup should be deleted first
|
||||
fieldgroup_fields = self.fields()
|
||||
if len(fieldgroup_fields) > 0:
|
||||
raise NotEmptyError("This Fieldgroup still contains fields. It can't be deleted then")
|
||||
return True
|
||||
|
||||
## Get the list of associated fields
|
||||
# if type_id, the fields will be filtered to represent selected fields of this EmType
|
||||
# @param type_id int|None : if not None the fields will be filtered to represent selected fields of the EmType identified by this uid
|
||||
# @param relational bool : If False don't returns the relational fields
|
||||
# @return A list of EmField instance
|
||||
def fields(self, type_id=None, relational=True):
|
||||
if type_id is None:
|
||||
fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
|
||||
else:
|
||||
# for an EmType, fields have to be filtered
|
||||
em_type = self.model.component(type_id)
|
||||
fields = []
|
||||
for field in self.model.components(EmField):
|
||||
if field.fieldgroup_id != self.uid or (field.optional and field.uid not in em_type.fields_list):
|
||||
continue
|
||||
# don't include relational field if parent should not be included
|
||||
if field.rel_field_id:
|
||||
parent = self.model.component(field.rel_field_id)
|
||||
if parent.optional and parent.uid not in em_type.fields_list:
|
||||
continue
|
||||
fields.append(field)
|
||||
|
||||
if not relational:
|
||||
fields = [ f for f in fields if f.rel_field_id is None and f.fieldtype != 'rel2type' ]
|
||||
|
||||
return fields
|
||||
|
||||
|
||||
class NotEmptyError(Exception):
|
||||
pass
|
||||
|
|
@ -16,7 +16,7 @@ import EditorialModel.fieldtypes
|
|||
# Represents one data for a lodel2 document
|
||||
class EmField(EmComponent):
|
||||
|
||||
ranked_in = 'fieldgroup_id'
|
||||
ranked_in = 'class_id'
|
||||
|
||||
## Instanciate a new EmField
|
||||
# @todo define and test type for icon
|
||||
|
|
@ -30,10 +30,10 @@ class EmField(EmComponent):
|
|||
# @param nullable bool : If True None values are allowed
|
||||
# @param uniq bool : if True the value should be uniq in the db table
|
||||
# @param **kwargs : more keywords arguments for the fieldtype
|
||||
def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable=False, uniq=False, **kwargs):
|
||||
def __init__(self, model, uid, name, class_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable=False, uniq=False, **kwargs):
|
||||
|
||||
self.fieldgroup_id = fieldgroup_id
|
||||
self.check_type('fieldgroup_id', int)
|
||||
self.class_id = class_id
|
||||
self.check_type('class_id', int)
|
||||
self.optional = bool(optional)
|
||||
|
||||
if not internal:
|
||||
|
|
@ -80,13 +80,13 @@ class EmField(EmComponent):
|
|||
|
||||
##@brief Return the EmFieldgroup this EmField belongs to
|
||||
@property
|
||||
def fieldgroup(self):
|
||||
def _fieldgroup(self):
|
||||
return self.model.component(self.fieldgroup_id)
|
||||
|
||||
## @brief Returns the EmClass this EmField belongs to
|
||||
@property
|
||||
def em_class(self):
|
||||
return self.fieldgroup.em_class
|
||||
return self.model.component(self.class_id)
|
||||
|
||||
## @brief Get the fieldtype instance
|
||||
# @return a fieldtype instance
|
||||
|
|
@ -111,12 +111,14 @@ class EmField(EmComponent):
|
|||
# @return True if valid False if not
|
||||
def check(self):
|
||||
super(EmField, self).check()
|
||||
"""
|
||||
#Fieldgroup check
|
||||
em_fieldgroup = self.model.component(self.fieldgroup_id)
|
||||
if not em_fieldgroup:
|
||||
raise EmComponentCheckError("fieldgroup_id contains a non existing uid : '%d'" % self.fieldgroup_id)
|
||||
if not isinstance(em_fieldgroup, EditorialModel.fieldgroups.EmFieldGroup):
|
||||
raise EmComponentCheckError("fieldgroup_id contains an uid from a component that is not an EmFieldGroup but a %s" % str(type(em_fieldgroup)))
|
||||
"""
|
||||
#Uniq Name check
|
||||
if len([ f for f in self.em_class.fields() if f.name == self.name]) > 1:
|
||||
raise EmComponentCheckError("The field %d has a name '%s' that is not uniq in the EmClass %d"%(self.uid, self.name, self.em_class.uid))
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import EditorialModel
|
|||
from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
|
||||
from EditorialModel.backend.dummy_backend import EmBackendDummy
|
||||
from EditorialModel.classes import EmClass
|
||||
from EditorialModel.fieldgroups import EmFieldGroup
|
||||
#from EditorialModel.fieldgroups import EmFieldGroup
|
||||
from EditorialModel.fields import EmField
|
||||
from EditorialModel.types import EmType
|
||||
from EditorialModel.exceptions import EmComponentCheckError, EmComponentNotExistError, MigrationHandlerChangeError
|
||||
|
|
@ -17,7 +17,7 @@ import hashlib
|
|||
## @brief Manages the Editorial Model
|
||||
class Model(object):
|
||||
|
||||
components_class = [EmClass, EmType, EmFieldGroup, EmField]
|
||||
components_class = [EmClass, EmType, EmField]
|
||||
|
||||
## Constructor
|
||||
#
|
||||
|
|
@ -33,7 +33,7 @@ class Model(object):
|
|||
self.backend = None
|
||||
self.set_backend(backend)
|
||||
|
||||
self._components = {'uids': {}, 'EmClass': [], 'EmType': [], 'EmField': [], 'EmFieldGroup': []}
|
||||
self._components = {'uids': {}, 'EmClass': [], 'EmType': [], 'EmField': []}
|
||||
self.load()
|
||||
|
||||
def __hash__(self):
|
||||
|
|
@ -232,7 +232,8 @@ class Model(object):
|
|||
emclass = self._components['uids'][class_uid]
|
||||
if not isinstance(emclass, EditorialModel.classes.EmClass):
|
||||
raise ValueError("The uid '%d' is not an EmClass uid"%class_uid)
|
||||
|
||||
|
||||
"""
|
||||
fgroup_name = EmClass.default_fieldgroup
|
||||
|
||||
if fgroup_name not in [fg.name for fg in emclass.fieldgroups() ]:
|
||||
|
|
@ -245,13 +246,14 @@ class Model(object):
|
|||
if fg.name == fgroup_name:
|
||||
fgid = fg.uid
|
||||
break
|
||||
"""
|
||||
|
||||
default_fields = emclass.default_fields_list()
|
||||
for fname, fdatas in default_fields.items():
|
||||
if not (fname in [ f.name for f in emclass.fields() ]):
|
||||
#Adding the field
|
||||
fdatas['name'] = fname
|
||||
fdatas['fieldgroup_id'] = fgid
|
||||
fdatas['class_id'] = class_uid
|
||||
self.create_component('EmField', fdatas)
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -1,548 +1,579 @@
|
|||
{
|
||||
"1": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"classtype": "entity",
|
||||
"string": "{\"fre\": \"Texte\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"name": "textes",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"component": "EmClass",
|
||||
"rank": 1
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"classtype": "entity",
|
||||
"icon": "0",
|
||||
"rank": 1,
|
||||
"name": "textes",
|
||||
"help_text": "",
|
||||
"string": "{\"fre\": \"Texte\"}"
|
||||
},
|
||||
"2": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"classtype": "person",
|
||||
"string": "{\"fre\": \"Personnes\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"name": "personnes",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"component": "EmClass",
|
||||
"rank": 1
|
||||
},
|
||||
"3": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Info\"}",
|
||||
"class_id": 1,
|
||||
"help_text": "",
|
||||
"name": "info",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"classtype": "person",
|
||||
"icon": "0",
|
||||
"rank": 1,
|
||||
"component": "EmFieldGroup"
|
||||
"name": "personnes",
|
||||
"help_text": "",
|
||||
"string": "{\"fre\": \"Personnes\"}"
|
||||
},
|
||||
"4": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "{\"fre\": \"Titre\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Titre\"}",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 3,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "titre",
|
||||
"help_text": "",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "titre"
|
||||
},
|
||||
"5": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Article\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"fields_list": [
|
||||
7
|
||||
],
|
||||
"rank": 1,
|
||||
"class_id": 1,
|
||||
"icon": "0",
|
||||
"name": "article",
|
||||
"superiors_list": {
|
||||
"parent": [
|
||||
14
|
||||
]
|
||||
},
|
||||
"name": "article",
|
||||
"component": "EmType"
|
||||
"fields_list": [
|
||||
7
|
||||
],
|
||||
"string": "{\"fre\": \"Article\"}",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"component": "EmType",
|
||||
"rank": 1,
|
||||
"help_text": "",
|
||||
"sortcolumn": "rank"
|
||||
},
|
||||
"6": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Personne\"}",
|
||||
"class_id": 2,
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"name": "personne",
|
||||
"superiors_list": {},
|
||||
"fields_list": [
|
||||
10
|
||||
],
|
||||
"string": "{\"fre\": \"Personne\"}",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"component": "EmType",
|
||||
"rank": 1,
|
||||
"class_id": 2,
|
||||
"superiors_list": {},
|
||||
"name": "personne",
|
||||
"component": "EmType"
|
||||
"help_text": "",
|
||||
"sortcolumn": "rank"
|
||||
},
|
||||
"7": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": true,
|
||||
"string": "{\"fre\": \"Sous-titre\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Sous-titre\"}",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"fieldgroup_id": 3,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "soustitre",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
},
|
||||
"8": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Civilit\\u00e9\"}",
|
||||
"class_id": 2,
|
||||
"help_text": "",
|
||||
"name": "civilit\u00e9",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"component": "EmFieldGroup"
|
||||
"internal": false,
|
||||
"rel_field_id": null,
|
||||
"name": "soustitre"
|
||||
},
|
||||
"9": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "{\"fre\": \"Nom\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Nom\"}",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 8,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "nom",
|
||||
"help_text": "",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "nom"
|
||||
},
|
||||
"10": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": true,
|
||||
"string": "{\"fre\": \"Pr\\u00e9nom\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Pr\\u00e9nom\"}",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"fieldgroup_id": 8,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "prenom",
|
||||
"help_text": "",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "prenom"
|
||||
},
|
||||
"11": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "{\"fre\": \"Auteur\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 17,
|
||||
"nullable": false,
|
||||
"fieldtype": "rel2type",
|
||||
"rel_to_type_id": 6,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"name": "auteur",
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Auteur\"}",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_to_type_id": 6,
|
||||
"rank": 1,
|
||||
"fieldtype": "rel2type",
|
||||
"help_text": "",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "auteur"
|
||||
},
|
||||
"12": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": 11,
|
||||
"optional": false,
|
||||
"string": "{\"fre\": \"Adresse\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Adresse\"}",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"fieldgroup_id": 17,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "adresse",
|
||||
"help_text": "",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
"rel_field_id": 11,
|
||||
"name": "adresse"
|
||||
},
|
||||
"13": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"classtype": "entity",
|
||||
"string": "{\"fre\": \"Publication\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"name": "publication",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"component": "EmClass",
|
||||
"rank": 2
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"classtype": "entity",
|
||||
"icon": "0",
|
||||
"rank": 2,
|
||||
"name": "publication",
|
||||
"help_text": "",
|
||||
"string": "{\"fre\": \"Publication\"}"
|
||||
},
|
||||
"14": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Rubrique\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"fields_list": [],
|
||||
"rank": 1,
|
||||
"class_id": 13,
|
||||
"icon": "0",
|
||||
"name": "rubrique",
|
||||
"superiors_list": {
|
||||
"parent": [
|
||||
14,
|
||||
19
|
||||
]
|
||||
},
|
||||
"name": "rubrique",
|
||||
"component": "EmType"
|
||||
},
|
||||
"15": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Info\"}",
|
||||
"class_id": 13,
|
||||
"help_text": "",
|
||||
"name": "info",
|
||||
"fields_list": [],
|
||||
"string": "{\"fre\": \"Rubrique\"}",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"component": "EmType",
|
||||
"rank": 1,
|
||||
"component": "EmFieldGroup"
|
||||
"help_text": "",
|
||||
"sortcolumn": "rank"
|
||||
},
|
||||
"16": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "{\"fre\": \"Titre\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Titre\"}",
|
||||
"class_id": 13,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 15,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "titre",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
},
|
||||
"17": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Gens\"}",
|
||||
"class_id": 1,
|
||||
"help_text": "",
|
||||
"name": "gens",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"component": "EmFieldGroup"
|
||||
"internal": false,
|
||||
"rel_field_id": null,
|
||||
"name": "titre"
|
||||
},
|
||||
"18": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": true,
|
||||
"string": "{\"fre\": \"Age\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Age\"}",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"fieldgroup_id": 8,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "age",
|
||||
"help_text": "",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "age"
|
||||
},
|
||||
"19": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Num\\u00e9ro\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"sortcolumn": "rank",
|
||||
"fields_list": [],
|
||||
"rank": 2,
|
||||
"class_id": 13,
|
||||
"superiors_list": {},
|
||||
"icon": "0",
|
||||
"name": "numero",
|
||||
"component": "EmType"
|
||||
},
|
||||
"20": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "{\"fre\": \"Couleurs\"}",
|
||||
"class_id": 1,
|
||||
"help_text": "",
|
||||
"name": "couleurs",
|
||||
"superiors_list": {},
|
||||
"fields_list": [],
|
||||
"string": "{\"fre\": \"Num\\u00e9ro\"}",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"component": "EmFieldGroup"
|
||||
"component": "EmType",
|
||||
"rank": 2,
|
||||
"help_text": "",
|
||||
"sortcolumn": "rank"
|
||||
},
|
||||
"21": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": true,
|
||||
"string": "{\"fre\": \"Bleu\"}",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "{\"fre\": \"Bleu\"}",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 20,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"uniq": false,
|
||||
"name": "bleu",
|
||||
"internal": false,
|
||||
"component": "EmField"
|
||||
},
|
||||
"22": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"string": "",
|
||||
"class_id": 1,
|
||||
"help_text": "",
|
||||
"name": "_default",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 4,
|
||||
"component": "EmFieldGroup"
|
||||
"internal": false,
|
||||
"rel_field_id": null,
|
||||
"name": "bleu"
|
||||
},
|
||||
"23": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 0,
|
||||
"fieldgroup_id": 22,
|
||||
"nullable": false,
|
||||
"fieldtype": "integer",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"name": "class_id",
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldtype": "integer",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "class_id"
|
||||
},
|
||||
"24": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 22,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"max_length": 128,
|
||||
"uniq": false,
|
||||
"icon": "0",
|
||||
"optional": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"name": "string",
|
||||
"rank": 2,
|
||||
"fieldtype": "char",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"uniq": false
|
||||
},
|
||||
"25": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"fieldgroup_id": 22,
|
||||
"nullable": false,
|
||||
"fieldtype": "integer",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"name": "type_id",
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"fieldtype": "integer",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "type_id"
|
||||
},
|
||||
"26": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"fieldgroup_id": 22,
|
||||
"nullable": false,
|
||||
"fieldtype": "pk",
|
||||
"uniq": false,
|
||||
"name": "lodel_id",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
},
|
||||
"27": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 2,
|
||||
"help_text": "",
|
||||
"name": "_default",
|
||||
"class_id": 1,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"component": "EmFieldGroup"
|
||||
"rank": 4,
|
||||
"fieldtype": "pk",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"rel_field_id": null,
|
||||
"name": "lodel_id"
|
||||
},
|
||||
"28": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 0,
|
||||
"fieldgroup_id": 27,
|
||||
"nullable": false,
|
||||
"fieldtype": "integer",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"name": "class_id",
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldtype": "integer",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "class_id"
|
||||
},
|
||||
"29": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 27,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"max_length": 128,
|
||||
"uniq": false,
|
||||
"icon": "0",
|
||||
"optional": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"name": "string",
|
||||
"rank": 2,
|
||||
"fieldtype": "char",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"uniq": false
|
||||
},
|
||||
"30": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"fieldgroup_id": 27,
|
||||
"nullable": false,
|
||||
"fieldtype": "integer",
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"name": "type_id",
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"fieldtype": "integer",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "type_id"
|
||||
},
|
||||
"31": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"fieldgroup_id": 27,
|
||||
"nullable": false,
|
||||
"fieldtype": "pk",
|
||||
"uniq": false,
|
||||
"name": "lodel_id",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
},
|
||||
"32": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 13,
|
||||
"help_text": "",
|
||||
"name": "_default",
|
||||
"class_id": 2,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"component": "EmFieldGroup"
|
||||
"rank": 4,
|
||||
"fieldtype": "pk",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"rel_field_id": null,
|
||||
"name": "lodel_id"
|
||||
},
|
||||
"33": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 0,
|
||||
"fieldgroup_id": 32,
|
||||
"nullable": false,
|
||||
"fieldtype": "integer",
|
||||
"uniq": false,
|
||||
"name": "class_id",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
},
|
||||
"34": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 13,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 1,
|
||||
"fieldgroup_id": 32,
|
||||
"nullable": false,
|
||||
"fieldtype": "char",
|
||||
"max_length": 128,
|
||||
"uniq": false,
|
||||
"name": "string",
|
||||
"fieldtype": "integer",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "class_id"
|
||||
},
|
||||
"34": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"max_length": 128,
|
||||
"icon": "0",
|
||||
"optional": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 13,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"name": "string",
|
||||
"rank": 2,
|
||||
"fieldtype": "char",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"rel_field_id": null,
|
||||
"uniq": false
|
||||
},
|
||||
"35": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 2,
|
||||
"fieldgroup_id": 32,
|
||||
"nullable": false,
|
||||
"fieldtype": "integer",
|
||||
"uniq": false,
|
||||
"name": "type_id",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
},
|
||||
"36": {
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"rel_field_id": null,
|
||||
"optional": false,
|
||||
"string": "",
|
||||
"icon": "0",
|
||||
"help_text": "",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 13,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 3,
|
||||
"fieldgroup_id": 32,
|
||||
"nullable": false,
|
||||
"fieldtype": "pk",
|
||||
"uniq": false,
|
||||
"name": "lodel_id",
|
||||
"fieldtype": "integer",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"component": "EmField"
|
||||
"rel_field_id": null,
|
||||
"name": "type_id"
|
||||
},
|
||||
"36": {
|
||||
"nullable": false,
|
||||
"date_update": "Fri Oct 16 11:05:04 2015",
|
||||
"optional": false,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 13,
|
||||
"date_create": "Fri Oct 16 11:05:04 2015",
|
||||
"rank": 4,
|
||||
"fieldtype": "pk",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"rel_field_id": null,
|
||||
"name": "lodel_id"
|
||||
},
|
||||
"37": {
|
||||
"nullable": false,
|
||||
"date_update": "Wed Nov 4 10:52:13 2015",
|
||||
"optional": false,
|
||||
"rank": 5,
|
||||
"icon": "0",
|
||||
"name": "modification_date",
|
||||
"component": "EmField",
|
||||
"string": "",
|
||||
"class_id": 1,
|
||||
"date_create": "Wed Nov 4 10:52:13 2015",
|
||||
"now_on_create": true,
|
||||
"internal": "automatic",
|
||||
"fieldtype": "datetime",
|
||||
"now_on_update": true,
|
||||
"help_text": "",
|
||||
"rel_field_id": null,
|
||||
"uniq": false
|
||||
},
|
||||
"38": {
|
||||
"nullable": false,
|
||||
"date_update": "Wed Nov 4 10:52:13 2015",
|
||||
"rel_field_id": null,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"now_on_create": true,
|
||||
"class_id": 1,
|
||||
"date_create": "Wed Nov 4 10:52:13 2015",
|
||||
"rank": 6,
|
||||
"string": "",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"optional": false,
|
||||
"name": "creation_date",
|
||||
"fieldtype": "datetime"
|
||||
},
|
||||
"39": {
|
||||
"nullable": false,
|
||||
"date_update": "Wed Nov 4 10:52:13 2015",
|
||||
"rel_field_id": null,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"now_on_create": true,
|
||||
"class_id": 2,
|
||||
"date_create": "Wed Nov 4 10:52:13 2015",
|
||||
"rank": 5,
|
||||
"string": "",
|
||||
"now_on_update": true,
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"optional": false,
|
||||
"name": "modification_date",
|
||||
"fieldtype": "datetime"
|
||||
},
|
||||
"40": {
|
||||
"nullable": false,
|
||||
"date_update": "Wed Nov 4 10:52:13 2015",
|
||||
"rel_field_id": null,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"now_on_create": true,
|
||||
"class_id": 2,
|
||||
"date_create": "Wed Nov 4 10:52:13 2015",
|
||||
"rank": 6,
|
||||
"string": "",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"optional": false,
|
||||
"name": "creation_date",
|
||||
"fieldtype": "datetime"
|
||||
},
|
||||
"41": {
|
||||
"nullable": false,
|
||||
"date_update": "Wed Nov 4 10:52:13 2015",
|
||||
"rel_field_id": null,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"now_on_create": true,
|
||||
"class_id": 13,
|
||||
"date_create": "Wed Nov 4 10:52:13 2015",
|
||||
"rank": 5,
|
||||
"string": "",
|
||||
"now_on_update": true,
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"optional": false,
|
||||
"name": "modification_date",
|
||||
"fieldtype": "datetime"
|
||||
},
|
||||
"42": {
|
||||
"nullable": false,
|
||||
"date_update": "Wed Nov 4 10:52:13 2015",
|
||||
"rel_field_id": null,
|
||||
"icon": "0",
|
||||
"uniq": false,
|
||||
"component": "EmField",
|
||||
"now_on_create": true,
|
||||
"class_id": 13,
|
||||
"date_create": "Wed Nov 4 10:52:13 2015",
|
||||
"rank": 6,
|
||||
"string": "",
|
||||
"help_text": "",
|
||||
"internal": "automatic",
|
||||
"optional": false,
|
||||
"name": "creation_date",
|
||||
"fieldtype": "datetime"
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import unittest
|
|||
import EditorialModel
|
||||
from EditorialModel.classes import EmClass
|
||||
from EditorialModel.classtypes import EmClassType
|
||||
from EditorialModel.fieldgroups import EmFieldGroup
|
||||
from EditorialModel.types import EmType
|
||||
from EditorialModel.fields import EmField
|
||||
from EditorialModel.model import Model
|
||||
|
|
@ -74,12 +73,8 @@ class TestEmClassCreation(ClassesTestCase):
|
|||
default_fields = ctype['default_fields']
|
||||
default_fields.update(EditorialModel.classtypes.common_fields)
|
||||
|
||||
fgs = test_class.fieldgroups()
|
||||
self.assertEqual(len(fgs), 1, "Only one fieldgroup should be created when an EmClass is created")
|
||||
self.assertEqual(fgs[0].name, EmClass.default_fieldgroup)
|
||||
fnames = [ f.name for f in fgs[0].fields() ]
|
||||
fnames = [ f.name for f in test_class.fields() ]
|
||||
self.assertEqual(sorted(fnames), sorted(list(default_fields.keys())))
|
||||
|
||||
|
||||
|
||||
# Testing class deletion (and associated table drop)
|
||||
|
|
@ -105,17 +100,10 @@ class TestEmClassDeletion(ClassesTestCase):
|
|||
def test_table_refuse_delete(self):
|
||||
""" Test delete on an EmClass that has fieldgroup """
|
||||
test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testfgclass1', 'classtype': EmClassType.entity['name']})
|
||||
fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testsubfg1', 'class_id': test_class.uid})
|
||||
self.assertFalse(EM_TEST_OBJECT.delete_component(test_class.uid), "delete method returns True but the class has fieldgroup(s)")
|
||||
|
||||
try:
|
||||
EM_TEST_OBJECT.component(test_class.uid)
|
||||
except Exception:
|
||||
self.fail("The class has been deleted but it has fieldgroups")
|
||||
|
||||
test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassFalseEmpty', 'classtype': EmClassType.entity['name']})
|
||||
foo_field = EM_TEST_OBJECT.create_component('EmField', {'name': 'ahah', 'fieldtype':'char', 'fieldgroup_id':test_class.fieldgroups()[0].uid})
|
||||
self.assertFalse(EM_TEST_OBJECT.delete_component(test_class.uid), "delete method returns True but the class has a non-default field in the default fieldgroup")
|
||||
foo_field = EM_TEST_OBJECT.create_component('EmField', {'name': 'ahah', 'fieldtype':'char', 'class_id':test_class.uid})
|
||||
self.assertFalse(EM_TEST_OBJECT.delete_component(test_class.uid), "delete method returns True but the class has a non-default field")
|
||||
|
||||
# TODO check : "table has been deleted but the class has fieldgroup"
|
||||
|
||||
|
|
@ -125,34 +113,6 @@ class TestEmClassDeletion(ClassesTestCase):
|
|||
self.fail("The class has been deleted but it has non-default field in the default fieldgroup")
|
||||
|
||||
|
||||
# Interface to fieldgroups
|
||||
class TestEmClassFieldgrousp(ClassesTestCase):
|
||||
|
||||
def setUp(self):
|
||||
ClassesTestCase.setUpClass()
|
||||
self.test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassFg', 'classtype': EmClassType.entity['name']})
|
||||
|
||||
# tests if fieldgroups() returns a list of EmFieldGroup
|
||||
def test_fieldgroups(self):
|
||||
""" Tests if fieldgroups method returns the right list of EmFieldGroup """
|
||||
test_class = EM_TEST_OBJECT.component(self.test_class.uid)
|
||||
EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg1', 'class_id': test_class.uid})
|
||||
EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFg2', 'class_id': test_class.uid})
|
||||
|
||||
fieldgroups = test_class.fieldgroups()
|
||||
self.assertIsInstance(fieldgroups, list)
|
||||
for fieldgroup in fieldgroups:
|
||||
self.assertIsInstance(fieldgroup, EmFieldGroup)
|
||||
|
||||
# with no fieldgroups, fieldgroups() should return an empty list
|
||||
def test_no_fieldgroups(self):
|
||||
""" Test fieldgroups method on an 'empty' EmClass """
|
||||
test_class = EM_TEST_OBJECT.create_component(EmClass.__name__, {'name': 'testClassFg3', 'classtype': EmClassType.entity['name']})
|
||||
fieldgroups = test_class.fieldgroups()
|
||||
self.assertEqual(len(fieldgroups), 1)
|
||||
self.assertEqual(fieldgroups[0].name, EmClass.default_fieldgroup)
|
||||
|
||||
|
||||
# Interface to types
|
||||
class TestEmClassTypes(ClassesTestCase):
|
||||
|
||||
|
|
@ -198,9 +158,8 @@ class TestEmClassFields(ClassesTestCase):
|
|||
def test_fields(self):
|
||||
""" testing fields method """
|
||||
test_class = EM_TEST_OBJECT.component(self.test_class.uid)
|
||||
fg = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testClassFieldsFg', 'class_id': test_class.uid})
|
||||
EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f1', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
|
||||
EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f2', 'fieldgroup_id': fg.uid, 'fieldtype': 'char'})
|
||||
EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f1', 'class_id': test_class.uid, 'fieldtype': 'char'})
|
||||
EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'f2', 'class_id': test_class.uid, 'fieldtype': 'char'})
|
||||
fields = test_class.fields()
|
||||
self.assertIsInstance(fields, list)
|
||||
for field in fields:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ from EditorialModel.model import Model
|
|||
from EditorialModel.components import EmComponent
|
||||
from EditorialModel.classes import EmClass
|
||||
from EditorialModel.types import EmType
|
||||
from EditorialModel.fieldgroups import EmFieldGroup
|
||||
from EditorialModel.fields import EmField
|
||||
|
||||
from Lodel.utils.mlstring import MlString
|
||||
|
|
@ -22,7 +21,7 @@ class TestEmComponent(unittest.TestCase):
|
|||
me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
|
||||
me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DummyMigrationHandler())
|
||||
|
||||
for comp_class in [EmClass, EmType, EmField, EmFieldGroup]:
|
||||
for comp_class in [EmClass, EmType, EmField]:
|
||||
comp_l1 = me1.components(comp_class)
|
||||
comp_l2 = me2.components(comp_class)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class FieldTestCase(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.test_fieldtype = 'integer'
|
||||
self.test_fieldgroup = EM_TEST_OBJECT.component(3)
|
||||
self.test_class = EM_TEST_OBJECT.components('EmClass')[0]
|
||||
|
||||
|
||||
## TestField (Class)
|
||||
|
|
@ -48,7 +48,7 @@ class TestField(FieldTestCase):
|
|||
# tests the creation process of a field
|
||||
def test_create(self):
|
||||
|
||||
field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testfield1', 'fieldgroup_id': self.test_fieldgroup.uid, 'fieldtype': self.test_fieldtype})
|
||||
field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testfield1', 'class_id': self.test_class.uid, 'fieldtype': self.test_fieldtype})
|
||||
|
||||
# We check that the field has been added
|
||||
field_records = EM_TEST_OBJECT.component(field.uid)
|
||||
|
|
@ -61,7 +61,7 @@ class TestField(FieldTestCase):
|
|||
def test_invalid_internal(self):
|
||||
""" Test that internal='object' is reserved for common_fields """
|
||||
with self.assertRaises(ValueError, msg="Only common_fields should be internal='object'"):
|
||||
field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testbadinternal','internal': 'object', 'fieldgroup_id': self.test_fieldgroup.uid, 'fieldtype': self.test_fieldtype})
|
||||
field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testbadinternal','internal': 'object', 'class_id': self.test_class.uid, 'fieldtype': self.test_fieldtype})
|
||||
|
||||
def test_double_rel2type(self):
|
||||
""" Test the rel2type unicity """
|
||||
|
|
@ -69,10 +69,10 @@ class TestField(FieldTestCase):
|
|||
emtype = em.components('EmType')[0]
|
||||
emclass = [c for c in em.components('EmClass') if c != emtype.em_class][0]
|
||||
|
||||
f1 = em.create_component('EmField', {'name': 'testr2t', 'fieldgroup_id': emclass.fieldgroups()[0].uid, 'fieldtype': 'rel2type', 'rel_to_type_id': emtype.uid})
|
||||
f1 = em.create_component('EmField', {'name': 'testr2t', 'class_id': emclass.uid, 'fieldtype': 'rel2type', 'rel_to_type_id': emtype.uid})
|
||||
|
||||
with self.assertRaises(EmComponentCheckError):
|
||||
f2 = em.create_component('EmField', {'name': 'testr2t2', 'fieldgroup_id': emclass.fieldgroups()[0].uid, 'fieldtype': 'rel2type', 'rel_to_type_id': emtype.uid})
|
||||
f2 = em.create_component('EmField', {'name': 'testr2t2', 'class_id': emclass.uid, 'fieldtype': 'rel2type', 'rel_to_type_id': emtype.uid})
|
||||
|
||||
def test_same_name(self):
|
||||
""" Test the name unicity is the same EmClass"""
|
||||
|
|
@ -80,10 +80,10 @@ class TestField(FieldTestCase):
|
|||
emtype = em.components('EmType')[0]
|
||||
emclass = [c for c in em.components('EmClass') if c != emtype.em_class][0]
|
||||
|
||||
f1 = em.create_component('EmField', {'name': 'samename', 'fieldgroup_id': emclass.fieldgroups()[0].uid, 'fieldtype': 'char'})
|
||||
f1 = em.create_component('EmField', {'name': 'samename', 'class_id': emclass.uid, 'fieldtype': 'char'})
|
||||
|
||||
with self.assertRaises(EmComponentCheckError):
|
||||
f2 = em.create_component('EmField', {'name': 'samename', 'fieldgroup_id': emclass.fieldgroups()[1].uid, 'fieldtype': 'integer'} )
|
||||
f2 = em.create_component('EmField', {'name': 'samename', 'class_id': emclass.uid, 'fieldtype': 'integer'} )
|
||||
|
||||
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ class TestField(FieldTestCase):
|
|||
|
||||
# We create the two fields
|
||||
for name in field_names:
|
||||
fields.append(EM_TEST_OBJECT.create_component(EmField.__name__, {'name': name, 'fieldgroup_id': self.test_fieldgroup.uid, 'fieldtype': self.test_fieldtype}))
|
||||
fields.append(EM_TEST_OBJECT.create_component(EmField.__name__, {'name': name, 'class_id': self.test_class.uid, 'fieldtype': self.test_fieldtype}))
|
||||
|
||||
for field in fields:
|
||||
# We check if the delete process was performed to the end
|
||||
|
|
@ -113,4 +113,3 @@ class TestField(FieldTestCase):
|
|||
""" Test if the EmField.em_class @property method is correct """
|
||||
for field in EM_TEST_OBJECT.components(EmField):
|
||||
self.assertIn(field, field.em_class.fields())
|
||||
self.assertIn(field.fieldgroup, field.em_class.fieldgroups())
|
||||
|
|
|
|||
|
|
@ -1,192 +0,0 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from EditorialModel.fieldgroups import EmFieldGroup
|
||||
from EditorialModel.classes import EmClass
|
||||
from EditorialModel.types import EmType
|
||||
from EditorialModel.fields import EmField
|
||||
from Lodel.utils.mlstring import MlString
|
||||
from EditorialModel.model import Model
|
||||
from EditorialModel.backend.json_backend import EmBackendJson
|
||||
|
||||
#=###########=#
|
||||
# TESTS SETUP #
|
||||
#=###########=#
|
||||
|
||||
TEST_FIELDGROUP_DBNAME = 'test_em_fieldgroup_db.sqlite'
|
||||
|
||||
EM_TEST = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'me.json')
|
||||
EM_TEST_OBJECT = None
|
||||
|
||||
|
||||
def setUpModule():
|
||||
global EM_TEST_OBJECT
|
||||
EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST))
|
||||
|
||||
logging.basicConfig(level=logging.CRITICAL)
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
pass
|
||||
|
||||
|
||||
class FieldGroupTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
|
||||
#======================#
|
||||
# EmFielgroup.__init__ #
|
||||
#======================#
|
||||
class TestInit(FieldGroupTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestInit, self).setUp()
|
||||
self.tfgs = [
|
||||
{"name": "testfg1", "string": MlString({"fre": "Gens"}), "help_text": MlString({}), "class_id": 1},
|
||||
{"name": "testfg2", "string": MlString({"fre": "Gens"}), "help_text": MlString({}), "class_id": 1},
|
||||
{"name": "testfg3", "string": MlString({"fre": "Civilité"}), "help_text": MlString({}), "class_id": 2}
|
||||
]
|
||||
for tfg in self.tfgs:
|
||||
fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, tfg)
|
||||
|
||||
def test_init(self):
|
||||
""" Test that EmFieldgroup are correctly instanciated compare to self.tfg """
|
||||
for tfg in self.tfgs:
|
||||
fieldgroup = EM_TEST_OBJECT.component(tfg['uid'])
|
||||
for attr in tfg:
|
||||
if attr != 'uid':
|
||||
v = tfg[attr]
|
||||
self.assertEqual(getattr(fieldgroup, attr), v, "The '" + attr + "' property fetched from backend doesn't match the excepted value")
|
||||
|
||||
def test_init_badargs(self):
|
||||
""" Tests that EmFieldGroup init fails when bad arguments are given"""
|
||||
baduid = self.tfgs[2]['uid'] + 4096
|
||||
badname = 'NonExistingName'
|
||||
|
||||
# TODO Voir si on garde le return False de Model.component() ou si on utilise plutôt une exception EmComponentNotExistError en modifiant le reste du code source pour gérer ce cas
|
||||
self.assertFalse(EM_TEST_OBJECT.component(baduid), msg="Should be False because fieldgroup with id " + str(baduid) + " should not exist")
|
||||
self.assertFalse(EM_TEST_OBJECT.component(badname), msg="Should be False because fieldgroup with id " + str(badname) + " should not exist")
|
||||
self.assertFalse(EM_TEST_OBJECT.component(print), msg="Should be False when a function name is given as argument")
|
||||
with self.assertRaises(TypeError, msg="Should raise when crazy arguments are given"):
|
||||
fieldgroup = EM_TEST_OBJECT.component(['hello', 'world'])
|
||||
|
||||
|
||||
#=====================#
|
||||
# EmFieldgroup.create #
|
||||
#=====================#
|
||||
class TestCreate(FieldGroupTestCase):
|
||||
|
||||
def test_create(self):
|
||||
"""Does create actually create a fieldgroup ?"""
|
||||
params = {
|
||||
'EmClass entity instance': EM_TEST_OBJECT.component(1),
|
||||
'EmClass entry instance': EM_TEST_OBJECT.component(2)
|
||||
}
|
||||
|
||||
for i, param_name in enumerate(params):
|
||||
arg = params[param_name]
|
||||
if isinstance(arg, EmClass):
|
||||
cl = arg
|
||||
else:
|
||||
cl = EM_TEST_OBJECT.component(arg)
|
||||
|
||||
fieldgroup_name = 'new_fg' + str(i)
|
||||
fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': fieldgroup_name, 'class_id': arg.uid})
|
||||
self.assertEqual(fieldgroup.name, fieldgroup_name, "Model.create_component() doesn't instanciate name correctly")
|
||||
self.assertEqual(fieldgroup.class_id, cl.uid, "Model.create_component() doesn't instanciate class_id correctly")
|
||||
|
||||
nfg = EM_TEST_OBJECT.component(fieldgroup.uid)
|
||||
|
||||
# Checking object property
|
||||
for fname in fieldgroup.__dict__:
|
||||
self.assertEqual(getattr(nfg, fname), getattr(fieldgroup, fname), "Msg inconsistency when a created fieldgroup is fetched from the backend (in " + fname + " property)")
|
||||
|
||||
def test_create_badargs(self):
|
||||
""" Does create fails when badargs given ? """
|
||||
badargs = {
|
||||
'EmClass type (not an instance)': EmClass,
|
||||
'Non Existing id': 9000,
|
||||
'Another component instance': EM_TEST_OBJECT.create_component(EmType.__name__, {'name': 'fooType', 'class_id': EM_TEST_OBJECT.component(1).uid}),
|
||||
'A function': print
|
||||
}
|
||||
|
||||
for i, badarg_name in enumerate(badargs):
|
||||
with self.assertRaises(TypeError, msg="Should raise because trying to give " + badarg_name + " an em_class object as value"):
|
||||
fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'new_fg' + i, 'class_id': badargs[badarg_name].uid})
|
||||
|
||||
# Creating a fieldgroup to test duplicate name
|
||||
exfg = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'existingfg', 'class_id': EM_TEST_OBJECT.component(1).uid})
|
||||
badargs = {
|
||||
'an integer': (42, AttributeError),
|
||||
'a function': (print, AttributeError),
|
||||
'an EmClass': (EM_TEST_OBJECT.component(2), AttributeError)
|
||||
}
|
||||
for badarg_name in badargs:
|
||||
(badarg, expt) = badargs[badarg_name]
|
||||
with self.assertRaises(expt, msg="Should raise because trying to give " + badarg_name + " as first argument"):
|
||||
fieldgroup = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': badarg, 'class_id': EM_TEST_OBJECT.component(1).uid})
|
||||
|
||||
|
||||
#=====================#
|
||||
# EmFieldgroup.fields #
|
||||
#=====================#
|
||||
class TestFields(FieldGroupTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFields, self).setUp()
|
||||
self.fg1 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testfg1', 'class_id': EM_TEST_OBJECT.component(1).uid})
|
||||
self.fg2 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testfg2', 'class_id': EM_TEST_OBJECT.component(2).uid})
|
||||
self.fg3 = EM_TEST_OBJECT.create_component(EmFieldGroup.__name__, {'name': 'testfg3', 'class_id': EM_TEST_OBJECT.component(1).uid})
|
||||
|
||||
def test_fields(self):
|
||||
""" Does it returns actually associated fields ? """
|
||||
# Creating fields
|
||||
test_fields1 = [
|
||||
{'name': 'field1', 'fieldgroup_id': self.fg1.uid, 'fieldtype': 'integer'},
|
||||
{'name': 'field2', 'fieldgroup_id': self.fg1.uid, 'fieldtype': 'integer'},
|
||||
{'name': 'field4', 'fieldgroup_id': self.fg1.uid, 'fieldtype': 'integer'}
|
||||
]
|
||||
|
||||
test_fields2 = [
|
||||
{'name': 'field3', 'fieldgroup_id': self.fg2.uid, 'fieldtype': 'integer'}
|
||||
]
|
||||
|
||||
expected1 = []
|
||||
|
||||
for finfo in test_fields1:
|
||||
field = EM_TEST_OBJECT.create_component(EmField.__name__, finfo)
|
||||
expected1.append(field.uid)
|
||||
|
||||
for finfo in test_fields2:
|
||||
field = EM_TEST_OBJECT.create_component(EmField.__name__, finfo)
|
||||
|
||||
expected1 = set(expected1)
|
||||
|
||||
tests = {
|
||||
'newly': EM_TEST_OBJECT.component(self.fg1.uid),
|
||||
'old': self.fg1
|
||||
}
|
||||
|
||||
for name in tests:
|
||||
fieldgroup = tests[name]
|
||||
flist = fieldgroup.fields()
|
||||
res = []
|
||||
for field in flist:
|
||||
res.append(field.uid)
|
||||
self.assertEqual(set(res), set(expected1))
|
||||
|
||||
def test_non_relational(self):
|
||||
""" Check that relationnal=False returns only non relational fields """
|
||||
for fgrp in [ self.fg1, self.fg2, self.fg3 ]:
|
||||
for field in fgrp.fields(relational=False):
|
||||
self.assertTrue(field.fieldtype != 'rel2type' and field.rel_field_id is None)
|
||||
|
||||
def test_empty_fields(self):
|
||||
""" Testing fields method on an empty fieldgroup """
|
||||
fieldgroup = self.fg3
|
||||
fields_list = fieldgroup.fields()
|
||||
self.assertEqual(len(fields_list), 0)
|
||||
|
|
@ -4,7 +4,6 @@ from unittest.mock import patch
|
|||
from EditorialModel.model import Model
|
||||
from EditorialModel.classes import EmClass
|
||||
from EditorialModel.types import EmType
|
||||
from EditorialModel.fieldgroups import EmFieldGroup
|
||||
from EditorialModel.fields import EmField
|
||||
from EditorialModel.components import EmComponent
|
||||
from Lodel.utils.mlstring import MlString
|
||||
|
|
@ -40,7 +39,7 @@ class TestModel(unittest.TestCase):
|
|||
def test_components(self):
|
||||
""" Test components fetching """
|
||||
uid_l = list()
|
||||
for comp_class in [EmClass, EmType, EmField, EmFieldGroup]:
|
||||
for comp_class in [EmClass, EmType, EmField]:
|
||||
comp_l = self.ed_mod.components(comp_class)
|
||||
#Testing types of returned components
|
||||
for component in comp_l:
|
||||
|
|
@ -139,18 +138,11 @@ class TestModel(unittest.TestCase):
|
|||
'fields_list': [],
|
||||
}
|
||||
},
|
||||
'EmFieldGroup': {
|
||||
'cls': EmFieldGroup,
|
||||
'cdats': {
|
||||
'name': 'FooFG',
|
||||
'class_id': self.ed_mod.components(EmClass)[0].uid,
|
||||
},
|
||||
},
|
||||
'EmField': {
|
||||
'cls': EmField,
|
||||
'cdats': {
|
||||
'name': 'FooField',
|
||||
'fieldgroup_id': self.ed_mod.components(EmFieldGroup)[0].uid,
|
||||
'class_id': self.ed_mod.components(EmClass)[0].uid,
|
||||
'fieldtype': 'char',
|
||||
'max_length': 64,
|
||||
'optional': True,
|
||||
|
|
@ -305,7 +297,7 @@ class TestModel(unittest.TestCase):
|
|||
|
||||
def test_compclass_getter(self):
|
||||
""" Test the Model methods that handles name <-> EmComponent conversion """
|
||||
for classname in ['EmField', 'EmClass', 'EmFieldGroup', 'EmType']:
|
||||
for classname in ['EmField', 'EmClass', 'EmType']:
|
||||
cls = Model.emclass_from_name(classname)
|
||||
self.assertNotEqual(cls, False, "emclass_from_name return False when '%s' given as parameter" % classname)
|
||||
self.assertEqual(cls.__name__, classname)
|
||||
|
|
@ -313,7 +305,7 @@ class TestModel(unittest.TestCase):
|
|||
for classname in ['EmComponent', 'EmFoobar', int, EmClass]:
|
||||
self.assertFalse(Model.emclass_from_name(classname))
|
||||
|
||||
for comp_cls in [EmClass, EmFieldGroup, EmType]:
|
||||
for comp_cls in [EmClass, EmField, EmType]:
|
||||
self.assertEqual(Model.name_from_emclass(comp_cls), comp_cls.__name__)
|
||||
for comp in self.ed_mod.components(EmField):
|
||||
self.assertEqual(Model.name_from_emclass(comp.__class__), 'EmField')
|
||||
|
|
|
|||
|
|
@ -97,22 +97,6 @@ class TestTypeHierarchy(TypeTestCase):
|
|||
self.article.del_superior(self.numero, EmNature.PARENT)
|
||||
|
||||
|
||||
class TestTypesMisc(TypeTestCase):
|
||||
|
||||
def test_fieldgroups(self):
|
||||
|
||||
# should not send empty fieldgroups
|
||||
self.assertNotIn(self.couleur_group, self.article.fieldgroups())
|
||||
|
||||
# add a field, fieldgroup should now appear
|
||||
self.article.select_field(self.couleur_field)
|
||||
self.assertIn(self.couleur_group, self.article.fieldgroups())
|
||||
|
||||
# delete it, fieldgroup should disappear
|
||||
self.article.unselect_field(self.couleur_field)
|
||||
self.assertNotIn(self.couleur_group, self.article.fieldgroups())
|
||||
|
||||
|
||||
class TestDeleteTypes(TypeTestCase):
|
||||
|
||||
def test_delete_types(self):
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class EmType(EmComponent):
|
|||
|
||||
## Get the list of non empty associated fieldgroups
|
||||
# @return A list of EmFieldGroup instance
|
||||
def fieldgroups(self):
|
||||
def _fieldgroups(self):
|
||||
fieldgroups = [fieldgroup for fieldgroup in self.em_class.fieldgroups() if len(fieldgroup.fields(self.uid))]
|
||||
return fieldgroups
|
||||
|
||||
|
|
@ -102,10 +102,7 @@ class EmType(EmComponent):
|
|||
## Return the list of associated fields
|
||||
# @return A list of EmField instance
|
||||
def fields(self, relational = False):
|
||||
fields = [field for fieldgroup in self.fieldgroups() for field in fieldgroup.fields(self.uid)]
|
||||
if not relational:
|
||||
fields = [ f for f in fields if f.rel_field_id is None and f.fieldtype != 'rel2type' ]
|
||||
return fields
|
||||
return [ field for field in self.em_class.fields() if not field.optional or (field.optional and field.uid in self.fields_list) ]
|
||||
|
||||
## Select_field (Function)
|
||||
#
|
||||
|
|
@ -323,8 +320,10 @@ class EmType(EmComponent):
|
|||
raise EmComponentCheckError("The element %d of selected_field is not an EmField but a %s" % (i, str(type(field))))
|
||||
if not field.optional:
|
||||
raise EmComponentCheckError("The element %d of selected_field is an EmField not optional" % i)
|
||||
"""
|
||||
if field.fieldgroup_id not in [fg.uid for fg in self.fieldgroups()]:
|
||||
raise EmComponentCheckError("The element %d of selected_field is an EmField that is part of an EmFieldGroup that is not associated with this EmType" % i)
|
||||
"""
|
||||
|
||||
for nature, superiors_uid in self.superiors_list.items():
|
||||
for superior_uid in superiors_uid:
|
||||
|
|
|
|||
|
|
@ -200,3 +200,43 @@ class LeDataSourceSQL(DummyDatasource):
|
|||
prepared_filters[prepared_filter_key] = prepared_filter_value
|
||||
|
||||
return prepared_filters
|
||||
|
||||
## @brief Link two object given a relation nature, depth and rank
|
||||
# @param lesup LeObject : a LeObject
|
||||
# @param lesub LeObject : a LeObject
|
||||
# @param nature str|None : The relation nature or None if rel2type
|
||||
# @param rank int : a rank
|
||||
def add_relation(self, lesup, lesub, nature=None, depth=None, rank=None, **rel_attr):
|
||||
if len(rel_attr) > 0 and not (nature is None):
|
||||
#not a rel2type but have some relation attribute
|
||||
raise AttributeError("No relation attributes allowed for non rel2type relations")
|
||||
|
||||
with self.connection() as cur:
|
||||
sql = insert(RELATIONS_TABLE_NAME, {'id_sup':lesup.lodel_id, 'id_sub':lesub.lodel_id, 'nature':nature,'rank':rank, 'depth':depth})
|
||||
if cur.execute(sql) != 1:
|
||||
raise RuntimeError("Unknow SQL error")
|
||||
|
||||
if len(rel_attr) > 0:
|
||||
#a relation table exists
|
||||
cur.execute('SELECT last_insert_id()')
|
||||
relation_id, = cur.fetchone()
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
## @brief Delete a link between two objects given a relation nature
|
||||
# @param lesup LeObject : a LeObject
|
||||
# @param lesub LeObject : a LeObject
|
||||
# @param nature str|None : The relation nature
|
||||
def del_relation(self, lesup, lesub, nature=None):
|
||||
raise NotImplementedError()
|
||||
|
||||
## @brief Return all relation of a lodel_id given a position and a nature
|
||||
# @param lodel_id int : We want the relations of this lodel_id
|
||||
# @param superior bool : If true search the relations where lodel_id is in id_sup
|
||||
# @param nature str|None : Search for relations with the given nature (if None rel2type)
|
||||
# @param return an array of dict with keys [ id_sup, id_sub, rank, depth, nature ]
|
||||
def get_relations(self, lodel_id, superior=True, nature=None):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -75,19 +75,11 @@ class LeFactory(object):
|
|||
for field in emclass.fields(relational = False):
|
||||
cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
|
||||
fti = field.fieldtype_instance()
|
||||
|
||||
# Populating fieldgroup attr
|
||||
cls_fieldgroup = dict()
|
||||
for fieldgroup in emclass.fieldgroups():
|
||||
cls_fieldgroup[fieldgroup.name] = list()
|
||||
for field in fieldgroup.fields(relational = False):
|
||||
cls_fieldgroup[fieldgroup.name].append(field.name)
|
||||
|
||||
return """
|
||||
#Initialisation of {name} class attributes
|
||||
{name}._fieldtypes = {ftypes}
|
||||
{name}._linked_types = {ltypes}
|
||||
{name}._fieldgroups = {fgroups}
|
||||
{name}._classtype = {classtype}
|
||||
""".format(
|
||||
name = LeFactory.name2classname(emclass.name),
|
||||
|
|
@ -102,7 +94,6 @@ class LeFactory(object):
|
|||
]))+']'
|
||||
) for lt, ltattr in cls_linked_types.items()
|
||||
]))+'}',
|
||||
fgroups = repr(cls_fieldgroup),
|
||||
classtype = repr(emclass.classtype)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -62,17 +62,6 @@ class TestLeFactory(TestCase):
|
|||
#Testing inheritance
|
||||
self.assertEqual(set(leclass.__bases__), set([dyncode.LeObject, leobject.leclass.LeClass]))
|
||||
|
||||
#Testing _fieldgroups attr
|
||||
self.assertEqual(
|
||||
set([ fg.name for fg in emclass.fieldgroups()]),
|
||||
set(leclass._fieldgroups.keys())
|
||||
)
|
||||
for fgroup in emclass.fieldgroups():
|
||||
self.assertEqual(
|
||||
set([ f.name for f in fgroup.fields(relational=False)]),
|
||||
set(leclass._fieldgroups[fgroup.name])
|
||||
)
|
||||
|
||||
#Testing _linked_types attr
|
||||
self.assertEqual(
|
||||
set([ LeFactory.name2classname(lt.name) for lt in emclass.linked_types()]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue