1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-03-14 15:22:02 +01:00
lodel2_mirror/EditorialModel/model.py
2015-07-17 13:52:32 +02:00

51 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
## @file editorialmodel.py
# Manage instance of an editorial model
from EditorialModel.classes import EmClass
from EditorialModel.fieldgroups import EmFieldGroup
## Manages the Editorial Model
class Model(object):
componentClass = EmClass
componentFieldGroup = EmFieldGroup
## Constructor
#
# @param backend unknown: A backend object instanciated from one of the classes in the backend module
def __init__(self, backend):
self.backend = backend
self.uids = {}
self.load()
## Loads the structure of the Editorial Model
#
# Gets all the objects contained in that structure and creates a list indexed by their uids
def load(self):
data = self.backend.load()
for uid, component in data.items():
cls_name = 'component' + component['component']
cls = getattr(Model, cls_name)
if cls:
component['uid'] = uid
self.uids[uid] = cls(component)
print (self.uids[uid])
## Saves data using the current backend
def save(self):
return self.backend.save()
## Changes the current backend
#
# @param backend unknown: A backend object
def set_backend(self, backend):
self.backend = backend
## Returns a list of all the EmClass objects of the model
def classes(self):
classes = [component for _, component in self.uids if isinstance(component, EmClass)]
return classes