No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fieldgroups.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #-*- coding: utf-8 -*-
  2. from EditorialModel.components import EmComponent, EmComponentNotExistError
  3. from Database import sqlutils
  4. import sqlalchemy as sql
  5. import EditorialModel
  6. class EmFieldGroup(EmComponent):
  7. """ Represents groups of EmField
  8. EmClass fields representation is organised with EmFieldGroup
  9. @see EmField
  10. """
  11. table = 'em_fieldgroup'
  12. def __init__(self, id_or_name):
  13. """ Instanciate an EmFieldGroup with data fetched from db
  14. @param id_or_name str|int: Identify the EmFieldGroup by name or by global_id
  15. @throw TypeError
  16. @see component::EmComponent::__init__()
  17. """
  18. self.table = EmFieldGroup.table
  19. super(EmFieldGroup, self).__init__(id_or_name)
  20. @classmethod
  21. def create(c, name, em_class):
  22. """ Create a new EmFieldGroup, save it and instanciate it
  23. @param name str: The name of the new fielgroup
  24. @param em_class EmClass: The new EmFieldGroup will belong to this class
  25. """
  26. try:
  27. exists = EmFieldGroup(name)
  28. except EmComponentNotExistError:
  29. return super(EmFieldGroup, c).create({'name': name, 'class_id':em_class.id}) #Check the return value ?
  30. return exists
  31. """ Use dictionary (from database) to populate the object
  32. """
  33. def populate(self):
  34. row = super(EmFieldGroup, self).populate()
  35. self.em_class = EditorialModel.classes.EmClass(int(row.class_id))
  36. def save(self):
  37. # should not be here, but cannot see how to do this
  38. if self.name is None:
  39. self.populate()
  40. values = {
  41. 'class_id' : self.em_class.id,
  42. }
  43. return super(EmFieldGroup, self).save(values)
  44. def fields(self):
  45. """ Get the list of associated fields
  46. @return A list of EmField
  47. """
  48. pass