# ~*~ coding: utf-8 from utils import translate class InvalidValue(Exception): pass class field(object): def getLegacy(klass): try: return klass.legacy except AttributeError: return None getLegacy = classmethod(getLegacy) def getName(klass): return klass.__name__ getName = classmethod(getName) def getTitleI18N(klass, lang): return translate(None, "field_"+klass.getName(), lang) getTitleI18N = classmethod(getTitleI18N) def getKeys(klass): return klass.choices.keys() getKeys = classmethod(getKeys) def view(klass, obj=None, trLang='en'): r = u'
\n' tr_title = klass.getTitleI18N(trLang) r += '\t\n' r += '\t
' fval = klass.default if obj is not None: fval = klass.getChoiceI18N(klass.get(obj), trLang) r += fval r += '
\n' r += '
\n' return r view = classmethod(view) def edit(klass, obj=None, trLang='en'): r = u'
\n' tr_title = klass.getTitleI18N(trLang) r += '\t\n' r += '\t
\n' r += klass.select(obj, trLang) r += '\t
\n' r += '
\n' return r edit = classmethod(edit) def select(klass, obj=None, trLang='en'): r = '\t\t\n' return r select = classmethod(select) def getChoiceI18N(klass, k, lang): if not k: k = klass.choices.get(k) return translate(None, 'fc_'+klass.getName()+'_'+k, lang) getChoiceI18N = classmethod(getChoiceI18N) def get(klass, obj): if hasattr(obj, '_dsstore'): return obj._dsstore.get(klass.__name__, klass.default) else: if obj.has_key(klass.__name__): return obj.get(klass.__name__) get = classmethod(get) def set(klass, obj, val): if not klass.choices.has_key(val): raise InvalidValue(klass.__name__ + " " + val) obj._dsstore.update({klass.__name__: val}) set = classmethod(set) class docLanguage(field): default = 'et' title = u'Document language' choices = { 'et' : u'Estonian', 'ru' : u'Russian', 'fi' : u'Finnish' } class residence(field): default = '' title = u'Residence' legacy = 'elukoht' choices = { '' : u'not important', 'tallinn': u'Tallinn/Harjumaa', 'idaviru': u'Ida-Virumaa', 'muu': u'other' } class socBackground(field): default = '' title = u'Social background' legacy = 'sots' choices = { '': u'not important', 'op': u'Student', 'ylop': u'Undergraduate', 'teenist': u'Teenistuja', 'kvaliftooline': u'qualified worker', 'lihttooline': u'Worker', 'tootu': u'Between jobs', 'kodune': u'Home', 'pension': u'Pensioner' } class age(field): default = '' title = u'Age' legacy = 'vanus' choices = { '': u'unknown', 'kuni18': u'up to 18', 'kuni26': u'up to 26', 'kuni40': u'up to 40', '41plus': u'41+' } class gender(field): default = '' title = u'Gender' legacy = 'sugu' choices = { '': u'unknown', 'mees': u'Male', 'naine': u'Female' } class motherTongue(field): default = '' title = u'Mother tongue' legacy = 'emakeel' choices = { '': u'unknown', 'vene': u'vene', 'eesti': u'eesti', 'ukraina': u'ukraina', 'valgevene': u'valgevene', 'lati': u'läti', 'leedu': u'leedu', 'saksa': u'saksa', 'soome': u'soome', 'rootsi': u'rootsi', 'inglise': u'inglise', 'jidis': u'jidiš', 'itaalia': u'itaalia', 'jaapani': u'jaapani', 'poola': u'poola', 'hollandi': u'hollandi', 'sloveenia': u'sloveenia', 'hebrea': u'hebrea', 'prantsuse': u'prantsuse', 'katalaani': u'katalaani', 'ungari': u'ungari', 'muud': u'muud' } class langAtHome(field): default = '' title = u'Language used home' legacy = 'kodus' choices = { '': u'unknown', 'vene': u'vene', 'eesti': u'eesti', 'ukraina': u'ukraina', 'valgevene': u'valgevene', 'lati': u'läti', 'leedu': u'leedu', 'saksa': u'saksa', 'soome': u'soome', 'rootsi': u'rootsi', 'inglise': u'inglise', 'jidis': u'jidiš', 'itaalia': u'itaalia', 'jaapani': u'jaapani', 'poola': u'poola', 'hollandi': u'hollandi', 'sloveenia': u'sloveenia', 'hebrea': u'hebrea', 'prantsuse': u'prantsuse', 'katalaani': u'katalaani', 'ungari': u'ungari', 'muud': u'muud' } class levOfCommand(field): default = '' title = u'Level of command' legacy = 'valdamise_tase' choices = { '': u'unknown', 'A': u'A', 'B': u'B', 'C': u'C' } class education(field): default = '' title = u'Education' legacy = 'haridus' choices = { '': u'unknown', 'pohi': u'Basic', 'kesk': u'Secondary', 'korg': u'Higher', 'muu': u'Other' } class helpingMaterials(field): default = '' title = u'Intermediate agent' legacy = 'abivahendid' choices = { '': u'unknown', 'jah': u'Yes', 'ei': u'No' } class texttype(field): default = '' title = u'Text type' legacy = 'texttype' choices = { '': u'unknown', 'isikiri': u'Personal letter', 'amtkiri': u'Formal letter', 'essee': u'Essay', 'referaat': u'referaat', 'trilumunud': u'Published in print', 'analyys': u'Analysis', 'vastkys': u'Answer to question', 'ymberjutustus': u'ümberjutustus', 'tolge': u'Translation', 'harjutus': u'Exercise', 'muu': u'Other', }