models.py
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
from django.db.models import Model, CharField, IntegerField, ForeignKey, \
ManyToManyField
from django.utils.translation import ugettext_lazy as _
from common.util import GroupDict
class InflectionType(Model):
symbol = CharField(primary_key=True, max_length=16, db_column='czm')
color_scheme = IntegerField()
full_name = CharField(max_length=128)
def __unicode__(self):
return self.symbol
class Meta:
db_table = 'czescimowy'
class BaseFormLabel(Model):
symbol = CharField(max_length=32, blank=True, db_column='efobaz')
lexical_class = ForeignKey(InflectionType)
index = IntegerField()
def __unicode__(self):
return '%s/%s' % (self.symbol, self.lexical_class.symbol)
class Meta:
db_table = 'efobazy'
unique_together = ['symbol', 'lexical_class']
ordering = ['index']
class DummyEnding(object):
def __init__(self, string):
self.index = 0
self.string = string
from dictionary.models import Qualifier
self.qualifiers = Qualifier.objects.none()
class PatternType(Model):
lexical_class = ForeignKey(
InflectionType, db_column='czm', verbose_name=_(u'inflection type'))
# typ wzoru (np. dla rzeczowników: odmiana męska, żeńska lub nijaka)
symbol = CharField(
max_length=32, blank=True, db_column='wtyp',
verbose_name=_(u'pattern type'))
base_form_labels = ManyToManyField(BaseFormLabel)
def dummy_base_endings(self):
bfl_dict = dict(
(bfl, [DummyEnding(bfl.symbol or self.lexical_class_id)])
for bfl in self.base_form_labels.all())
return bfl_dict
@classmethod
def options(cls):
pattern_types = GroupDict()
for pt in cls.objects.all():
pattern_types.add(pt.lexical_class.symbol, (pt.id, unicode(pt)))
return sorted(pattern_types.items())
def __unicode__(self):
return self.symbol.replace('"', "''") or '[%s]' % self.lexical_class_id
# '%s (%s)' % (self.symbol, self.lexical_class_id)
class Meta:
db_table = 'typywzorow'
ordering = ['symbol']