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.

model.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. ## @file editorialmodel.py
  3. # Manage instance of an editorial model
  4. from EditorialModel.classes import EmClass
  5. from EditorialModel.fieldgroups import EmFieldGroup
  6. ## Manages the Editorial Model
  7. class Model(object):
  8. componentClass = EmClass
  9. componentFieldGroup = EmFieldGroup
  10. ## Constructor
  11. #
  12. # @param backend unknown: A backend object instanciated from one of the classes in the backend module
  13. def __init__(self, backend):
  14. self.backend = backend
  15. self.uids = {}
  16. self.load()
  17. ## Loads the structure of the Editorial Model
  18. #
  19. # Gets all the objects contained in that structure and creates a list indexed by their uids
  20. def load(self):
  21. data = self.backend.load()
  22. for uid, component in data.items():
  23. cls_name = 'component' + component['component']
  24. cls = getattr(Model, cls_name)
  25. if cls:
  26. component['uid'] = uid
  27. self.uids[uid] = cls(component)
  28. print (self.uids[uid])
  29. ## Saves data using the current backend
  30. def save(self):
  31. return self.backend.save()
  32. ## Changes the current backend
  33. #
  34. # @param backend unknown: A backend object
  35. def set_backend(self, backend):
  36. self.backend = backend
  37. ## Returns a list of all the EmClass objects of the model
  38. def classes(self):
  39. classes = [component for _, component in self.uids if isinstance(component, EmClass)]
  40. return classes