1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-06-22 09:30:48 +02:00

EmFieldGroup: create, save and load. fieldgroups() method for EmClass.

This commit is contained in:
ArnAud 2015-06-04 16:02:50 +02:00
commit 22b9dfc4b6
2 changed files with 58 additions and 36 deletions

View file

@ -8,9 +8,7 @@
from EditorialModel.components import EmComponent, EmComponentNotExistError
from Database.sqlwrapper import SqlWrapper
from Database.sqlobject import SqlObject
import EditorialModel.classtypes
import EditorialModel.types
import EditorialModel
class EmClass(EmComponent):
table = 'em_class'
@ -61,8 +59,16 @@ class EmClass(EmComponent):
""" retrieve list of the field_groups of this class
@return field_groups [EmFieldGroup]:
"""
def field_groups(self):
pass
def fieldgroups(self):
fieldgroups_req = SqlObject(EditorialModel.fieldgroups.EmFieldGroup.table)
select = fieldgroups_req.sel
select.where(fieldgroups_req.col.class_id == self.id)
sqlresult = fieldgroups_req.rexec(select)
records = sqlresult.fetchall()
fieldgroups = [ EditorialModel.fieldgroups.EmFieldGroup(int(record.uid)) for record in records ]
return fieldgroups
""" retrieve list of fields
@return fields [EmField]:

View file

@ -1,51 +1,67 @@
#-*- coding: utf-8 -*-
from EditorialModel.components import EmComponent
from EditorialModel.components import EmComponent, EmComponentNotExistError
from Database.sqlobject import SqlObject
import EditorialModel
class EmFieldGroup(EmComponent):
""" Represents groups of EmField
EmClass fields representation is organised with EmFieldGroup
@see EmField
"""
def __init__(id_or_name):
""" Instanciate an EmFieldGroupe with data fetched from db
table = 'em_fieldgroup'
def __init__(self, id_or_name):
""" Instanciate an EmFieldGroup with data fetched from db
@param id_or_name str|int: Identify the EmFieldGroup by name or by global_id
@throw TypeError
@see component::EmComponent::__init__()
"""
super(EmFieldGroup, self).__init__()
pass
self.table = EmFieldGroup.table
super(EmFieldGroup, self).__init__(id_or_name)
@staticmethod
def create(name, em_class, ml_repr = None, ml_help = None, icon = None):
""" Create a new EmType and instanciate it
@todo Change the icon param type
@todo em_class == None => Error ?
@todo change staticmethod to classmethod ?
@param name str: The name of the new Type
@param em_class EmClass: The new EmFieldGroup will belong to this class
@param ml_repr MlString|None: Multilingual representation of the type
@param ml_help MlString|None: Multilingual help for the type
@param The string|None: filename of the icon
@return An EmFieldGroup instance
@see EmComponent::__init__()
"""
pass
def create(name, em_class):
""" Create a new EmFieldGroup, save it and instanciate it
def fields():
@param name str: The name of the new fielgroup
@param em_class EmClass: The new EmFieldGroup will belong to this class
"""
try:
exists = EmFieldGroup(name)
except EmComponentNotExistError:
uids = SqlObject('uids')
res = uids.wexec(uids.table.insert().values(table=EmFieldGroup.table))
uid = res.inserted_primary_key
emfieldgroup = SqlObject(EmFieldGroup.table)
res = emfieldgroup.wexec(emfieldgroup.table.insert().values(uid=uid, name=name, class_id=em_class.id))
return EmFieldGroup(name)
return exists
""" Use dictionary (from database) to populate the object
"""
def populate(self):
row = super(EmFieldGroup, self).populate()
self.em_class = EditorialModel.classes.EmClass(int(row.class_id))
def save(self):
# should not be here, but cannot see how to do this
if self.name is None:
self.populate()
values = {
'class_id' : self.em_class.id,
}
return super(EmFieldGroup, self).save(values)
def fields(self):
""" Get the list of associated fields
@return A list of EmField
"""
pass
def field():
""" ???
@todo : find what this function is for
"""
pass