1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-11-05 02:51:33 +01:00

EmFieldgroups: use canonical name to refer to a class

+ pep8 and pylint
This commit is contained in:
ArnAud 2015-06-25 17:12:07 +02:00
commit e72a162605

View file

@ -5,10 +5,10 @@ from EditorialModel.classes import EmClass
import EditorialModel.fieldtypes as ftypes
from Database import sqlutils
import sqlalchemy as sql
import EditorialModel
## Represents groups of EmField associated with an EmClass
#
# EmClass fields representation is organised with EmFieldGroup
@ -20,7 +20,7 @@ class EmFieldGroup(EmComponent):
## List of fields
# @todo Bad storage, here we want an ordereddict not a tuple list
_fields = [('class_id', ftypes.EmField_integer)]
## 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
@ -36,25 +36,25 @@ class EmFieldGroup(EmComponent):
# @throw ValueError If an EmFieldGroup with this name allready exists
# @throw ValueError If the specified EmClass don't exists
# @throw TypeError If an argument is of an unexepted type
def create(c, name, em_class):
def create(cls, name, em_class):
if not isinstance(em_class, EmClass):
if isinstance(em_class, int) or isinstance(em_class, str):
try:
arg = em_class
em_class = EmClass(arg)
except EmComponentNotExistError:
raise ValueError("No EmClass found with id or name '"+arg+"'")
raise ValueError("No EmClass found with id or name '" + arg + "'")
else:
raise TypeError("Excepting an EmClass, an int or a str for 'em_class' argument. Not an "+str(type(em_class))+".")
raise TypeError("Excepting an EmClass, an int or a str for 'em_class' argument. Not an " + str(type(em_class)) + ".")
if not isinstance(name, str):
raise TypeError("Excepting a string as first argument, not an "+str(type(name)))
raise TypeError("Excepting a string as first argument, not an " + str(type(name)))
try:
exists = EmFieldGroup(name)
raise ValueError("An EmFieldgroup named "+name+" allready exist")
raise ValueError("An EmFieldgroup named " + name + " allready exist")
except EmComponentNotExistError:
return super(EmFieldGroup, c).create(name=name, class_id = em_class.uid) #Check the return value ?
return super(EmFieldGroup, cls).create(name=name, class_id=em_class.uid) # Check the return value ?
return exists
@ -62,11 +62,10 @@ class EmFieldGroup(EmComponent):
# @return A list of EmField instance
# @todo Implement this method
def fields(self):
field_table = sqlutils.getTable(EmField)
field_table = sqlutils.getTable(EditorialModel.fields.EmField)
req = field_table.select(field_table.c.uid).where(field_table.c.fieldgroup_id == self.uid)
conn = self.__class__.getDbE().connect()
res = conn.execute(req)
rows = res.fetchall()
conn.close()
return [ EmField(row['uid']) for row in rows]
return [EditorialModel.fields.EmField(row['uid']) for row in rows]