Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

model.py 1.3KB

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