# ~*~ coding: utf-8 from fields import * def all(): return [BasicSchema, ExamSchema, ArvamusSchema] def get_schema(name): for x in all(): if x.name == name: return x def get_field(name): return globals().get(name) class SchemaFunc(object): """ schema functionality """ def view(klass, obj=None, trLang='en'): r = u'' for f in klass.fields: r += f.view(obj, trLang) return r view = classmethod(view) def edit(klass, obj=None, trLang='en'): r = u'' for f in klass.fields: r += f.edit(obj, trLang) return r edit = classmethod(edit) def update(klass, obj, vals): """ vals as dict object """ for f in klass.fields: if vals.has_key(f.__name__): fval = vals.get(f.__name__) f.set(obj, fval) update = classmethod(update) def getFieldNames(klass): return [ f.getName() for f in klass.fields ] getFieldNames = classmethod(getFieldNames) def getValue(klass, field, obj): """ get object's value for a given field """ return get_field(field).get(obj) getValue = classmethod(getValue) def getPrintable(klass): """ get schemas printable title """ return klass.printable getPrintable = classmethod(getPrintable) class BasicSchema(SchemaFunc): """ basic schema """ name = 'BasicSchema' printable = 'Standard' fields = [ docLanguage, texttype, residence, socBackground, age, gender, motherTongue, langAtHome, levOfCommand, education, helpingMaterials ] class ExamSchema(SchemaFunc): """ national exam documents """ name = 'ExamSchema' printable = 'Exam' fields = [ docLanguage, texttype, residence, socBackground, age, gender, motherTongue, langAtHome, levOfCommand, education, helpingMaterials ] class ArvamusSchema(SchemaFunc): """Arvamuslood""" name="ArvamusSchema" printable="Arvamus" fields = [ docLanguage, texttype, allikas ]