Commit c996c44c390fc9c4d7e13903ef32d7498f5ed154

Authored by janek37
1 parent d1d43f52

wyświetlanie dodatkowych atrybutów

dictionary/ajax_lexeme_view.py
... ... @@ -12,7 +12,8 @@ from dictionary.models import Lexeme, LexemeInflectionPattern, PartOfSpeech, \
12 12 InputLexeme, set_vocabulary, CrossReferenceType, filter_visible, \
13 13 editable_vocabularies, visible_qualifiers
14 14 from dictionary.forms import LexemeEditForm, LIPEditForm, ClassificationForm, \
15   - CrossReferenceForm, ActionFieldForm, ACTION_FIELDS
  15 + CrossReferenceForm, ActionFieldForm, ACTION_FIELDS, LexemeOpenAttributeForm, \
  16 + LexemeClosedAttributeForm, LexemeMultipleAttributeForm
16 17 from common.decorators import render, ajax, AjaxError
17 18 from common.util import error_messages
18 19  
... ... @@ -82,6 +83,18 @@ def lexeme_edit_form(request, id):
82 83 to_return['editable'] = editable
83 84 owner = l.owner_vocabulary
84 85  
  86 + # lepiej od razu zrobić z tego formularze...
  87 + attribute_forms = []
  88 + for attr, v in l.attributes_values():
  89 + if not attr.closed:
  90 + form_class = LexemeOpenAttributeForm
  91 + elif not attr.multiple:
  92 + form_class = LexemeClosedAttributeForm
  93 + else:
  94 + form_class = LexemeMultipleAttributeForm
  95 + attribute_forms.append(form_class(attribute=attr, initial_value=v))
  96 + to_return['attribute_forms'] = attribute_forms
  97 +
85 98 editable_vocabs = editable_vocabularies(request.user)
86 99 ro_owner = owner not in editable_vocabs
87 100 to_return['multiple_editable'] = editable and editable_vocabs.count() > 1
... ...
dictionary/forms.py
... ... @@ -5,7 +5,8 @@ from common.forms import hidden_id
5 5 from dictionary.models import Lexeme, LexemeInflectionPattern, Ending, \
6 6 InflectionCharacteristic, Pattern, PatternType, Classification, \
7 7 ClassificationValue, Vocabulary, CrossReference, Qualifier, \
8   - QualifierExclusionClass, Variant, editable_vocabularies, editable_qualifiers
  8 + QualifierExclusionClass, Variant, editable_vocabularies, editable_qualifiers, LexemeAttribute, LexemeAttributeValue
  9 +
9 10  
10 11 def disable_field(field):
11 12 if type(field.widget) in (Textarea, TextInput):
... ... @@ -127,6 +128,47 @@ class LexemeEditForm(ModelForm):
127 128 'pronunciation': TextInput(attrs={'size': 40}),
128 129 }
129 130  
  131 +# abstract
  132 +class LexemeAttributeForm(Form):
  133 + attr = ModelChoiceField(
  134 + queryset=LexemeAttribute.objects.all(),
  135 + widget=HiddenInput())
  136 +
  137 + def __init__(self, attribute, **kwargs):
  138 + super(LexemeAttributeForm, self).__init__(**kwargs)
  139 + self.fields['attr'].initial = attribute
  140 + self.fields['value'].label = attribute.name
  141 +
  142 +class LexemeOpenAttributeForm(LexemeAttributeForm):
  143 + value = CharField(
  144 + widget=TextInput(attrs={'class': 'pattern', 'size': '10'}),
  145 + required=False)
  146 +
  147 + def __init__(self, attribute, initial_value, **kwargs):
  148 + assert not attribute.closed and not attribute.multiple
  149 + super(LexemeOpenAttributeForm, self).__init__(attribute, **kwargs)
  150 + self.fields['value'].initial = initial_value.value
  151 +
  152 +class LexemeClosedAttributeForm(LexemeAttributeForm):
  153 + value = ModelChoiceField(
  154 + queryset=LexemeAttributeValue.objects.none(), required=False)
  155 +
  156 + def __init__(self, attribute, initial_value, **kwargs):
  157 + assert attribute.closed and not attribute.multiple
  158 + super(LexemeClosedAttributeForm, self).__init__(attribute, **kwargs)
  159 + self.fields['value'].queryset = attribute.values
  160 + self.fields['value'].initial = initial_value
  161 +
  162 +class LexemeMultipleAttributeForm(LexemeAttributeForm):
  163 + value = ModelMultipleChoiceField(
  164 + queryset=LexemeAttributeValue.objects.none(), required=False)
  165 +
  166 + def __init__(self, attribute, initial_value, **kwargs):
  167 + assert attribute.closed and attribute.multiple
  168 + super(LexemeMultipleAttributeForm, self).__init__(attribute, **kwargs)
  169 + self.fields['value'].queryset = attribute.values
  170 + self.fields['value'].initial = initial_value
  171 +
130 172 class LIPEditForm(ModelForm):
131 173 pattern_name = CharField(widget=TextInput(
132 174 attrs={'class': 'pattern', 'size': '10'}), label=u'Wzór')
... ...
dictionary/migrations/0013_auto__add_field_lexemeattribute_multiple.py 0 → 100644
  1 +# -*- coding: utf-8 -*-
  2 +import datetime
  3 +from south.db import db
  4 +from south.v2 import SchemaMigration
  5 +from django.db import models
  6 +
  7 +
  8 +class Migration(SchemaMigration):
  9 +
  10 + def forwards(self, orm):
  11 + # Adding field 'LexemeAttribute.multiple'
  12 + db.add_column(u'dictionary_lexemeattribute', 'multiple',
  13 + self.gf('django.db.models.fields.BooleanField')(default=False),
  14 + keep_default=False)
  15 +
  16 +
  17 + def backwards(self, orm):
  18 + # Deleting field 'LexemeAttribute.multiple'
  19 + db.delete_column(u'dictionary_lexemeattribute', 'multiple')
  20 +
  21 +
  22 + models = {
  23 + u'auth.group': {
  24 + 'Meta': {'object_name': 'Group'},
  25 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  26 + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
  27 + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
  28 + },
  29 + u'auth.permission': {
  30 + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
  31 + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  32 + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
  33 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  34 + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
  35 + },
  36 + u'auth.user': {
  37 + 'Meta': {'object_name': 'User'},
  38 + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
  39 + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
  40 + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
  41 + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
  42 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  43 + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
  44 + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  45 + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  46 + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
  47 + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
  48 + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
  49 + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
  50 + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
  51 + },
  52 + u'contenttypes.contenttype': {
  53 + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
  54 + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  55 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  56 + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  57 + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
  58 + },
  59 + u'dictionary.baseformlabel': {
  60 + 'Meta': {'object_name': 'BaseFormLabel', 'db_table': "'efobazy'"},
  61 + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'efobaz'", 'blank': 'True'}),
  62 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
  63 + },
  64 + u'dictionary.cell': {
  65 + 'Meta': {'ordering': "['index']", 'object_name': 'Cell', 'db_table': "'klatki'"},
  66 + 'base_form_label': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}),
  67 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  68 + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'kind'"}),
  69 + 'prefix': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_column': "'prefiks'", 'blank': 'True'}),
  70 + 'suffix': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_column': "'sufiks'", 'blank': 'True'}),
  71 + 'table_template': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.TableTemplate']", 'db_column': "'st_id'"}),
  72 + 'tag': ('django.db.models.fields.TextField', [], {'db_column': "'tag'", 'blank': 'True'})
  73 + },
  74 + u'dictionary.classification': {
  75 + 'Meta': {'object_name': 'Classification', 'db_table': "'klasyfikacje'"},
  76 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  77 + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_column': "'nazwa'"})
  78 + },
  79 + u'dictionary.classificationvalue': {
  80 + 'Meta': {'object_name': 'ClassificationValue', 'db_table': "'wartosci_klasyfikacji'"},
  81 + 'classification': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'values'", 'db_column': "'klas_id'", 'to': u"orm['dictionary.Classification']"}),
  82 + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_column': "'usunieta'"}),
  83 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  84 + 'label': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_column': "'nazwa'"}),
  85 + 'lexemes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Lexeme']", 'symmetrical': 'False', 'blank': 'True'}),
  86 + 'parent_node': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'child_nodes'", 'null': 'True', 'db_column': "'rodzic'", 'to': u"orm['dictionary.ClassificationValue']"})
  87 + },
  88 + u'dictionary.crossreference': {
  89 + 'Meta': {'object_name': 'CrossReference', 'db_table': "'odsylacze'"},
  90 + 'from_lexeme': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'refs_to'", 'db_column': "'l_id_od'", 'to': u"orm['dictionary.Lexeme']"}),
  91 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  92 + 'to_lexeme': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'refs_from'", 'db_column': "'l_id_do'", 'to': u"orm['dictionary.Lexeme']"}),
  93 + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.CrossReferenceType']", 'db_column': "'typods_id'"})
  94 + },
  95 + u'dictionary.crossreferencetype': {
  96 + 'Meta': {'object_name': 'CrossReferenceType', 'db_table': "'typyodsylaczy'"},
  97 + 'desc': ('django.db.models.fields.CharField', [], {'max_length': '40', 'db_column': "'naglowek'"}),
  98 + 'from_pos': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'crtype_to'", 'db_column': "'pos1'", 'to': u"orm['dictionary.PartOfSpeech']"}),
  99 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  100 + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'kolejnosc'"}),
  101 + 'symbol': ('django.db.models.fields.CharField', [], {'max_length': '10', 'db_column': "'typods'"}),
  102 + 'to_pos': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'crtype_from'", 'db_column': "'pos2'", 'to': u"orm['dictionary.PartOfSpeech']"})
  103 + },
  104 + u'dictionary.ending': {
  105 + 'Meta': {'ordering': "['index']", 'unique_together': "(('pattern', 'base_form_label', 'index'),)", 'object_name': 'Ending', 'db_table': "'zakonczenia'"},
  106 + 'base_form_label': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}),
  107 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  108 + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'zind'"}),
  109 + 'pattern': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'endings'", 'db_column': "'w_id'", 'to': u"orm['dictionary.Pattern']"}),
  110 + 'qualifiers': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Qualifier']", 'symmetrical': 'False', 'db_table': "'kwalifikatory_zakonczen'", 'blank': 'True'}),
  111 + 'string': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_column': "'zak'", 'blank': 'True'})
  112 + },
  113 + u'dictionary.history': {
  114 + 'Meta': {'object_name': 'History', 'db_table': "'history'"},
  115 + 'column_name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_column': "'column_name_'", 'blank': 'True'}),
  116 + 'column_ord': ('django.db.models.fields.IntegerField', [], {'db_column': "'ordinal_position_of_column_'"}),
  117 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  118 + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']", 'null': 'True', 'db_column': "'lexeme_id_'", 'blank': 'True'}),
  119 + 'new_value': ('django.db.models.fields.TextField', [], {'db_column': "'new_value_'", 'blank': 'True'}),
  120 + 'old_value': ('django.db.models.fields.TextField', [], {'db_column': "'old_value_'", 'blank': 'True'}),
  121 + 'operation': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_column': "'operation_'"}),
  122 + 'pattern': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Pattern']", 'null': 'True', 'db_column': "'pattern_id_'", 'blank': 'True'}),
  123 + 'row_id': ('django.db.models.fields.IntegerField', [], {'db_column': "'id_'"}),
  124 + 'table_name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_column': "'table_name_'"}),
  125 + 'table_oid': ('django.db.models.fields.IntegerField', [], {'db_column': "'table_oid_'"}),
  126 + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'db_column': "'timestamp_'"}),
  127 + 'transaction_began': ('django.db.models.fields.DateTimeField', [], {'db_column': "'transaction_began_'"}),
  128 + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'db_column': "'user_id_'"})
  129 + },
  130 + u'dictionary.inflectioncharacteristic': {
  131 + 'Meta': {'unique_together': "(('entry', 'part_of_speech'),)", 'object_name': 'InflectionCharacteristic', 'db_table': "'charfle'"},
  132 + 'basic_form_label': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}),
  133 + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_column': "'charfl'", 'blank': 'True'}),
  134 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  135 + 'part_of_speech': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PartOfSpeech']", 'db_column': "'pos'"})
  136 + },
  137 + u'dictionary.inputform': {
  138 + 'Meta': {'object_name': 'InputForm'},
  139 + 'form': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_index': 'True'}),
  140 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  141 + 'input_lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InputLexeme']"})
  142 + },
  143 + u'dictionary.inputlexeme': {
  144 + 'Meta': {'object_name': 'InputLexeme'},
  145 + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_index': 'True'}),
  146 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
  147 + },
  148 + u'dictionary.lexeme': {
  149 + 'Meta': {'object_name': 'Lexeme', 'db_table': "'leksemy'"},
  150 + 'comment': ('django.db.models.fields.TextField', [], {'db_column': "'komentarz'", 'blank': 'True'}),
  151 + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_column': "'usuniety'"}),
  152 + 'entry': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '64', 'db_column': "'haslo'", 'blank': 'True'}),
  153 + 'entry_suffix': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_column': "'haslosuf'", 'blank': 'True'}),
  154 + 'gloss': ('django.db.models.fields.TextField', [], {'db_column': "'glosa'", 'blank': 'True'}),
  155 + 'homonym_number': ('django.db.models.fields.IntegerField', [], {'default': '1', 'db_column': "'hom'"}),
  156 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  157 + 'last_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_column': "'data_modyfikacji'", 'blank': 'True'}),
  158 + 'note': ('django.db.models.fields.TextField', [], {'db_column': "'nota'", 'blank': 'True'}),
  159 + 'owner_vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owned_lexemes'", 'db_column': "'slownik'", 'to': u"orm['dictionary.Vocabulary']"}),
  160 + 'part_of_speech': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PartOfSpeech']", 'db_column': "'pos'"}),
  161 + 'patterns': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Pattern']", 'through': u"orm['dictionary.LexemeInflectionPattern']", 'symmetrical': 'False'}),
  162 + 'pronunciation': ('django.db.models.fields.TextField', [], {'db_column': "'wymowa'", 'blank': 'True'}),
  163 + 'qualifiers': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Qualifier']", 'symmetrical': 'False', 'db_table': "'kwalifikatory_leksemow'", 'blank': 'True'}),
  164 + 'responsible': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'db_column': "'odpowiedzialny'", 'blank': 'True'}),
  165 + 'source': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'zrodlo'", 'blank': 'True'}),
  166 + 'status': ('django.db.models.fields.CharField', [], {'max_length': '8', 'db_column': "'status'"})
  167 + },
  168 + u'dictionary.lexemeassociation': {
  169 + 'Meta': {'object_name': 'LexemeAssociation', 'db_table': "'leksemy_w_slownikach'"},
  170 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  171 + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']", 'db_column': "'l_id'"}),
  172 + 'vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Vocabulary']", 'db_column': "'slownik'"})
  173 + },
  174 + u'dictionary.lexemeattribute': {
  175 + 'Meta': {'object_name': 'LexemeAttribute'},
  176 + 'closed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  177 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  178 + 'inflection_characteristic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'null': 'True', 'blank': 'True'}),
  179 + 'lexical_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.LexicalClass']", 'null': 'True', 'blank': 'True'}),
  180 + 'multiple': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  181 + 'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
  182 + 'part_of_speech': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PartOfSpeech']", 'null': 'True', 'blank': 'True'})
  183 + },
  184 + u'dictionary.lexemeattributevalue': {
  185 + 'Meta': {'object_name': 'LexemeAttributeValue'},
  186 + 'attribute': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'values'", 'to': u"orm['dictionary.LexemeAttribute']"}),
  187 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  188 + 'lexemes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Lexeme']", 'symmetrical': 'False', 'blank': 'True'}),
  189 + 'value': ('django.db.models.fields.CharField', [], {'max_length': '32'})
  190 + },
  191 + u'dictionary.lexemeform': {
  192 + 'Meta': {'object_name': 'LexemeForm'},
  193 + 'form': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
  194 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  195 + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']"})
  196 + },
  197 + u'dictionary.lexemeinflectionpattern': {
  198 + 'Meta': {'ordering': "['index']", 'unique_together': "(('lexeme', 'index'),)", 'object_name': 'LexemeInflectionPattern', 'db_table': "'odmieniasie'"},
  199 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  200 + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'oind'"}),
  201 + 'inflection_characteristic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'db_column': "'charfl'"}),
  202 + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']", 'db_column': "'l_id'"}),
  203 + 'pattern': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Pattern']", 'db_column': "'w_id'"}),
  204 + 'qualifiers': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Qualifier']", 'symmetrical': 'False', 'db_table': "'kwalifikatory_odmieniasiow'", 'blank': 'True'}),
  205 + 'root': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'rdzen'"})
  206 + },
  207 + u'dictionary.lexicalclass': {
  208 + 'Meta': {'object_name': 'LexicalClass', 'db_table': "'czescimowy'"},
  209 + 'symbol': ('django.db.models.fields.CharField', [], {'max_length': '16', 'primary_key': 'True', 'db_column': "'czm'"})
  210 + },
  211 + u'dictionary.paradygmatywsjp': {
  212 + 'Meta': {'object_name': 'ParadygmatyWSJP', 'db_table': "'paradygmatywsjp'"},
  213 + 'charfl': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'db_column': "'charfl'"}),
  214 + 'col': ('django.db.models.fields.IntegerField', [], {}),
  215 + 'colspan': ('django.db.models.fields.IntegerField', [], {}),
  216 + 'efobaz': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}),
  217 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  218 + 'kskl': ('django.db.models.fields.IntegerField', [], {}),
  219 + 'morf': ('django.db.models.fields.TextField', [], {}),
  220 + 'podparad': ('django.db.models.fields.CharField', [], {'max_length': '4', 'blank': 'True'}),
  221 + 'pref': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
  222 + 'row': ('django.db.models.fields.IntegerField', [], {}),
  223 + 'rowspan': ('django.db.models.fields.IntegerField', [], {}),
  224 + 'suf': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
  225 + 'typr': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PatternType']", 'db_column': "'typr'"}),
  226 + 'wariant': ('django.db.models.fields.CharField', [], {'max_length': '4'})
  227 + },
  228 + u'dictionary.partofspeech': {
  229 + 'Meta': {'ordering': "['symbol']", 'object_name': 'PartOfSpeech', 'db_table': "'klasygramatyczne'"},
  230 + 'lexical_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.LexicalClass']", 'db_column': "'czm'"}),
  231 + 'symbol': ('django.db.models.fields.CharField', [], {'max_length': '16', 'primary_key': 'True', 'db_column': "'pos'"})
  232 + },
  233 + u'dictionary.pattern': {
  234 + 'Meta': {'ordering': "['name']", 'object_name': 'Pattern', 'db_table': "'wzory'"},
  235 + 'basic_form_ending': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'zakp'", 'blank': 'True'}),
  236 + 'comment': ('django.db.models.fields.TextField', [], {'db_column': "'komentarz'", 'blank': 'True'}),
  237 + 'example': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'przyklad'"}),
  238 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  239 + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32', 'db_column': "'w_id'"}),
  240 + 'status': ('django.db.models.fields.CharField', [], {'max_length': '8'}),
  241 + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PatternType']", 'db_column': "'typ'"})
  242 + },
  243 + u'dictionary.patterntype': {
  244 + 'Meta': {'object_name': 'PatternType', 'db_table': "'typywzorow'"},
  245 + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'wtyp'", 'blank': 'True'}),
  246 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  247 + 'lexical_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.LexicalClass']", 'db_column': "'czm'"})
  248 + },
  249 + u'dictionary.qualifier': {
  250 + 'Meta': {'ordering': "['label']", 'unique_together': "(('label', 'vocabulary'),)", 'object_name': 'Qualifier', 'db_table': "'kwalifikatory'"},
  251 + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_column': "'usuniety'"}),
  252 + 'exclusion_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.QualifierExclusionClass']", 'null': 'True', 'db_column': "'klasa'", 'blank': 'True'}),
  253 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  254 + 'label': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'kwal'"}),
  255 + 'vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'qualifiers'", 'db_column': "'slownik'", 'to': u"orm['dictionary.Vocabulary']"})
  256 + },
  257 + u'dictionary.qualifierexclusionclass': {
  258 + 'Meta': {'object_name': 'QualifierExclusionClass', 'db_table': "'klasy_wykluczania'"},
  259 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  260 + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_column': "'nazwa'"}),
  261 + 'vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Vocabulary']", 'db_column': "'slownik'"})
  262 + },
  263 + u'dictionary.savedexportdata': {
  264 + 'Meta': {'object_name': 'SavedExportData'},
  265 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  266 + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'}),
  267 + 'serialized_data': ('django.db.models.fields.TextField', [], {})
  268 + },
  269 + u'dictionary.savedfilter': {
  270 + 'Meta': {'unique_together': "(('name', 'user'),)", 'object_name': 'SavedFilter'},
  271 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  272 + 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
  273 + 'serialized_filter': ('django.db.models.fields.TextField', [], {}),
  274 + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
  275 + },
  276 + u'dictionary.tablecell': {
  277 + 'Meta': {'object_name': 'TableCell', 'db_table': "'komorki_tabel'"},
  278 + 'cell': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['dictionary.Cell']", 'unique': 'True', 'db_column': "'k_id'"}),
  279 + 'col': ('django.db.models.fields.IntegerField', [], {}),
  280 + 'colspan': ('django.db.models.fields.IntegerField', [], {}),
  281 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  282 + 'row': ('django.db.models.fields.IntegerField', [], {}),
  283 + 'rowspan': ('django.db.models.fields.IntegerField', [], {})
  284 + },
  285 + u'dictionary.tableheader': {
  286 + 'Meta': {'object_name': 'TableHeader', 'db_table': "'naglowki_tabel'"},
  287 + 'col': ('django.db.models.fields.IntegerField', [], {}),
  288 + 'colspan': ('django.db.models.fields.IntegerField', [], {}),
  289 + 'css_class': ('django.db.models.fields.CharField', [], {'max_length': '8', 'db_column': "'styl'"}),
  290 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  291 + 'label': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'nagl'", 'blank': 'True'}),
  292 + 'row': ('django.db.models.fields.IntegerField', [], {}),
  293 + 'rowspan': ('django.db.models.fields.IntegerField', [], {}),
  294 + 'table_template': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.TableTemplate']", 'db_column': "'st_id'"})
  295 + },
  296 + u'dictionary.tabletemplate': {
  297 + 'Meta': {'object_name': 'TableTemplate', 'db_table': "'szablony_tabel'"},
  298 + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  299 + 'inflection_characteristic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'db_column': "'charfl'"}),
  300 + 'pattern_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PatternType']", 'db_column': "'wtyp'"}),
  301 + 'variant': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Variant']", 'db_column': "'wariant'"})
  302 + },
  303 + u'dictionary.variant': {
  304 + 'Meta': {'object_name': 'Variant', 'db_table': "'warianty'"},
  305 + 'id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'primary_key': 'True', 'db_column': "'wariant'"})
  306 + },
  307 + u'dictionary.vocabulary': {
  308 + 'Meta': {'object_name': 'Vocabulary', 'db_table': "'slowniki'"},
  309 + 'classifications': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'vocabularies'", 'blank': 'True', 'to': u"orm['dictionary.Classification']"}),
  310 + 'editors': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'editable_vocabularies'", 'blank': 'True', 'to': u"orm['auth.User']"}),
  311 + 'id': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True', 'db_column': "'slownik'"}),
  312 + 'lexemes': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'vocabularies'", 'blank': 'True', 'through': u"orm['dictionary.LexemeAssociation']", 'to': u"orm['dictionary.Lexeme']"}),
  313 + 'managers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'managed_vocabularies'", 'blank': 'True', 'to': u"orm['auth.User']"}),
  314 + 'viewers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'visible_vocabularies'", 'blank': 'True', 'to': u"orm['auth.User']"})
  315 + }
  316 + }
  317 +
  318 + complete_apps = ['dictionary']
0 319 \ No newline at end of file
... ...
dictionary/models.py
... ... @@ -435,6 +435,29 @@ class Lexeme(Model):
435 435 self.homonym_number = i
436 436 break
437 437  
  438 + def attributes(self):
  439 + lips = self.lexemeinflectionpattern_set.all()
  440 + ics = tuple(lip.inflection_characteristic for lip in lips)
  441 + attrs = LexemeAttribute.objects.all()
  442 + attrs = (attrs.filter(lexical_class=self.part_of_speech.lexical_class)
  443 + | attrs.filter(lexical_class=None))
  444 + attrs = (attrs.filter(part_of_speech=self.part_of_speech)
  445 + | attrs.filter(part_of_speech=None))
  446 + attrs = (attrs.filter(inflection_characteristic__in=ics)
  447 + | attrs.filter(inflection_characteristic=None))
  448 + return attrs
  449 +
  450 + def attributes_values(self):
  451 + for attr in self.attributes():
  452 + if attr.multiple:
  453 + v = attr.values.filter(lexemes=self)
  454 + else:
  455 + try:
  456 + v = attr.values.get(lexemes=self)
  457 + except LexemeAttributeValue.DoesNotExist:
  458 + v = None
  459 + yield (attr, v)
  460 +
438 461 def perm(self, user, action):
439 462 if action == 'view':
440 463 vocabs = self.vocabularies.all()
... ... @@ -496,17 +519,24 @@ def get_root(basic_form, pos, pattern, ic, use_pattern_ending=False):
496 519 class LexemeAttribute(Model):
497 520 name = CharField(max_length=32)
498 521 closed = BooleanField() # czy jest zamknięta lista wartości
  522 + multiple = BooleanField()
499 523 lexical_class = ForeignKey(LexicalClass, blank=True, null=True)
500 524 part_of_speech = ForeignKey(PartOfSpeech, blank=True, null=True)
501 525 inflection_characteristic = ForeignKey(
502 526 InflectionCharacteristic, blank=True, null=True)
503 527  
  528 + def __unicode__(self):
  529 + return self.name
  530 +
504 531  
505 532 class LexemeAttributeValue(Model):
506 533 value = CharField(max_length=32)
507 534 attribute = ForeignKey(LexemeAttribute, related_name='values')
508 535 lexemes = ManyToManyField(Lexeme, blank=True)
509 536  
  537 + def __unicode__(self):
  538 + return self.value
  539 +
510 540  
511 541 class LexemeInflectionPattern(Model):
512 542 lexeme = ForeignKey(Lexeme, db_column='l_id')
... ...
dictionary/templates/lexeme_edit_form.html
... ... @@ -12,6 +12,9 @@
12 12 </p>
13 13 {% endif %}
14 14 {% endfor %}
  15 + {% for form in attribute_forms %}
  16 + {{ form.as_p }}
  17 + {% endfor %}
15 18 <p>
16 19 Sposoby odmiany:
17 20 <input type="hidden" name="id" value="{{ id }}"/>
... ...
sql/history.sql
... ... @@ -2,7 +2,8 @@
2 2  
3 3 ALTER TABLE history
4 4 ALTER user_id_ SET DEFAULT current_setting('var.user_id'::text)::integer,
5   - ALTER transaction_began_ SET DEFAULT transaction_timestamp();
  5 + ALTER transaction_began_ SET DEFAULT transaction_timestamp(),
  6 + ALTER timestamp_ SET DEFAULT clock_timestamp();
6 7  
7 8  
8 9 -- make_history_
... ...