diff --git a/dictionary/ajax_lexeme_view.py b/dictionary/ajax_lexeme_view.py index 8d696b1..2cfdeef 100644 --- a/dictionary/ajax_lexeme_view.py +++ b/dictionary/ajax_lexeme_view.py @@ -12,7 +12,8 @@ from dictionary.models import Lexeme, LexemeInflectionPattern, PartOfSpeech, \ InputLexeme, set_vocabulary, CrossReferenceType, filter_visible, \ editable_vocabularies, visible_qualifiers from dictionary.forms import LexemeEditForm, LIPEditForm, ClassificationForm, \ - CrossReferenceForm, ActionFieldForm, ACTION_FIELDS + CrossReferenceForm, ActionFieldForm, ACTION_FIELDS, LexemeOpenAttributeForm, \ + LexemeClosedAttributeForm, LexemeMultipleAttributeForm from common.decorators import render, ajax, AjaxError from common.util import error_messages @@ -82,6 +83,18 @@ def lexeme_edit_form(request, id): to_return['editable'] = editable owner = l.owner_vocabulary + # lepiej od razu zrobić z tego formularze... + attribute_forms = [] + for attr, v in l.attributes_values(): + if not attr.closed: + form_class = LexemeOpenAttributeForm + elif not attr.multiple: + form_class = LexemeClosedAttributeForm + else: + form_class = LexemeMultipleAttributeForm + attribute_forms.append(form_class(attribute=attr, initial_value=v)) + to_return['attribute_forms'] = attribute_forms + editable_vocabs = editable_vocabularies(request.user) ro_owner = owner not in editable_vocabs to_return['multiple_editable'] = editable and editable_vocabs.count() > 1 diff --git a/dictionary/forms.py b/dictionary/forms.py index ae000c4..6ad28e1 100644 --- a/dictionary/forms.py +++ b/dictionary/forms.py @@ -5,7 +5,8 @@ from common.forms import hidden_id from dictionary.models import Lexeme, LexemeInflectionPattern, Ending, \ InflectionCharacteristic, Pattern, PatternType, Classification, \ ClassificationValue, Vocabulary, CrossReference, Qualifier, \ - QualifierExclusionClass, Variant, editable_vocabularies, editable_qualifiers + QualifierExclusionClass, Variant, editable_vocabularies, editable_qualifiers, LexemeAttribute, LexemeAttributeValue + def disable_field(field): if type(field.widget) in (Textarea, TextInput): @@ -127,6 +128,47 @@ class LexemeEditForm(ModelForm): 'pronunciation': TextInput(attrs={'size': 40}), } +# abstract +class LexemeAttributeForm(Form): + attr = ModelChoiceField( + queryset=LexemeAttribute.objects.all(), + widget=HiddenInput()) + + def __init__(self, attribute, **kwargs): + super(LexemeAttributeForm, self).__init__(**kwargs) + self.fields['attr'].initial = attribute + self.fields['value'].label = attribute.name + +class LexemeOpenAttributeForm(LexemeAttributeForm): + value = CharField( + widget=TextInput(attrs={'class': 'pattern', 'size': '10'}), + required=False) + + def __init__(self, attribute, initial_value, **kwargs): + assert not attribute.closed and not attribute.multiple + super(LexemeOpenAttributeForm, self).__init__(attribute, **kwargs) + self.fields['value'].initial = initial_value.value + +class LexemeClosedAttributeForm(LexemeAttributeForm): + value = ModelChoiceField( + queryset=LexemeAttributeValue.objects.none(), required=False) + + def __init__(self, attribute, initial_value, **kwargs): + assert attribute.closed and not attribute.multiple + super(LexemeClosedAttributeForm, self).__init__(attribute, **kwargs) + self.fields['value'].queryset = attribute.values + self.fields['value'].initial = initial_value + +class LexemeMultipleAttributeForm(LexemeAttributeForm): + value = ModelMultipleChoiceField( + queryset=LexemeAttributeValue.objects.none(), required=False) + + def __init__(self, attribute, initial_value, **kwargs): + assert attribute.closed and attribute.multiple + super(LexemeMultipleAttributeForm, self).__init__(attribute, **kwargs) + self.fields['value'].queryset = attribute.values + self.fields['value'].initial = initial_value + class LIPEditForm(ModelForm): pattern_name = CharField(widget=TextInput( attrs={'class': 'pattern', 'size': '10'}), label=u'Wzór') diff --git a/dictionary/migrations/0013_auto__add_field_lexemeattribute_multiple.py b/dictionary/migrations/0013_auto__add_field_lexemeattribute_multiple.py new file mode 100644 index 0000000..4b5391f --- /dev/null +++ b/dictionary/migrations/0013_auto__add_field_lexemeattribute_multiple.py @@ -0,0 +1,318 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'LexemeAttribute.multiple' + db.add_column(u'dictionary_lexemeattribute', 'multiple', + self.gf('django.db.models.fields.BooleanField')(default=False), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'LexemeAttribute.multiple' + db.delete_column(u'dictionary_lexemeattribute', 'multiple') + + + models = { + u'auth.group': { + 'Meta': {'object_name': 'Group'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'auth.permission': { + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + u'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + u'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + u'dictionary.baseformlabel': { + 'Meta': {'object_name': 'BaseFormLabel', 'db_table': "'efobazy'"}, + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'efobaz'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) + }, + u'dictionary.cell': { + 'Meta': {'ordering': "['index']", 'object_name': 'Cell', 'db_table': "'klatki'"}, + 'base_form_label': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'kind'"}), + 'prefix': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_column': "'prefiks'", 'blank': 'True'}), + 'suffix': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_column': "'sufiks'", 'blank': 'True'}), + 'table_template': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.TableTemplate']", 'db_column': "'st_id'"}), + 'tag': ('django.db.models.fields.TextField', [], {'db_column': "'tag'", 'blank': 'True'}) + }, + u'dictionary.classification': { + 'Meta': {'object_name': 'Classification', 'db_table': "'klasyfikacje'"}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_column': "'nazwa'"}) + }, + u'dictionary.classificationvalue': { + 'Meta': {'object_name': 'ClassificationValue', 'db_table': "'wartosci_klasyfikacji'"}, + 'classification': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'values'", 'db_column': "'klas_id'", 'to': u"orm['dictionary.Classification']"}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_column': "'usunieta'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'label': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_column': "'nazwa'"}), + 'lexemes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Lexeme']", 'symmetrical': 'False', 'blank': 'True'}), + 'parent_node': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'child_nodes'", 'null': 'True', 'db_column': "'rodzic'", 'to': u"orm['dictionary.ClassificationValue']"}) + }, + u'dictionary.crossreference': { + 'Meta': {'object_name': 'CrossReference', 'db_table': "'odsylacze'"}, + 'from_lexeme': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'refs_to'", 'db_column': "'l_id_od'", 'to': u"orm['dictionary.Lexeme']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'to_lexeme': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'refs_from'", 'db_column': "'l_id_do'", 'to': u"orm['dictionary.Lexeme']"}), + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.CrossReferenceType']", 'db_column': "'typods_id'"}) + }, + u'dictionary.crossreferencetype': { + 'Meta': {'object_name': 'CrossReferenceType', 'db_table': "'typyodsylaczy'"}, + 'desc': ('django.db.models.fields.CharField', [], {'max_length': '40', 'db_column': "'naglowek'"}), + 'from_pos': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'crtype_to'", 'db_column': "'pos1'", 'to': u"orm['dictionary.PartOfSpeech']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'kolejnosc'"}), + 'symbol': ('django.db.models.fields.CharField', [], {'max_length': '10', 'db_column': "'typods'"}), + 'to_pos': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'crtype_from'", 'db_column': "'pos2'", 'to': u"orm['dictionary.PartOfSpeech']"}) + }, + u'dictionary.ending': { + 'Meta': {'ordering': "['index']", 'unique_together': "(('pattern', 'base_form_label', 'index'),)", 'object_name': 'Ending', 'db_table': "'zakonczenia'"}, + 'base_form_label': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'zind'"}), + 'pattern': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'endings'", 'db_column': "'w_id'", 'to': u"orm['dictionary.Pattern']"}), + 'qualifiers': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Qualifier']", 'symmetrical': 'False', 'db_table': "'kwalifikatory_zakonczen'", 'blank': 'True'}), + 'string': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_column': "'zak'", 'blank': 'True'}) + }, + u'dictionary.history': { + 'Meta': {'object_name': 'History', 'db_table': "'history'"}, + 'column_name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_column': "'column_name_'", 'blank': 'True'}), + 'column_ord': ('django.db.models.fields.IntegerField', [], {'db_column': "'ordinal_position_of_column_'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']", 'null': 'True', 'db_column': "'lexeme_id_'", 'blank': 'True'}), + 'new_value': ('django.db.models.fields.TextField', [], {'db_column': "'new_value_'", 'blank': 'True'}), + 'old_value': ('django.db.models.fields.TextField', [], {'db_column': "'old_value_'", 'blank': 'True'}), + 'operation': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_column': "'operation_'"}), + 'pattern': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Pattern']", 'null': 'True', 'db_column': "'pattern_id_'", 'blank': 'True'}), + 'row_id': ('django.db.models.fields.IntegerField', [], {'db_column': "'id_'"}), + 'table_name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_column': "'table_name_'"}), + 'table_oid': ('django.db.models.fields.IntegerField', [], {'db_column': "'table_oid_'"}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'db_column': "'timestamp_'"}), + 'transaction_began': ('django.db.models.fields.DateTimeField', [], {'db_column': "'transaction_began_'"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'db_column': "'user_id_'"}) + }, + u'dictionary.inflectioncharacteristic': { + 'Meta': {'unique_together': "(('entry', 'part_of_speech'),)", 'object_name': 'InflectionCharacteristic', 'db_table': "'charfle'"}, + 'basic_form_label': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}), + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_column': "'charfl'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'part_of_speech': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PartOfSpeech']", 'db_column': "'pos'"}) + }, + u'dictionary.inputform': { + 'Meta': {'object_name': 'InputForm'}, + 'form': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_index': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'input_lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InputLexeme']"}) + }, + u'dictionary.inputlexeme': { + 'Meta': {'object_name': 'InputLexeme'}, + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_index': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) + }, + u'dictionary.lexeme': { + 'Meta': {'object_name': 'Lexeme', 'db_table': "'leksemy'"}, + 'comment': ('django.db.models.fields.TextField', [], {'db_column': "'komentarz'", 'blank': 'True'}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_column': "'usuniety'"}), + 'entry': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '64', 'db_column': "'haslo'", 'blank': 'True'}), + 'entry_suffix': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_column': "'haslosuf'", 'blank': 'True'}), + 'gloss': ('django.db.models.fields.TextField', [], {'db_column': "'glosa'", 'blank': 'True'}), + 'homonym_number': ('django.db.models.fields.IntegerField', [], {'default': '1', 'db_column': "'hom'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_column': "'data_modyfikacji'", 'blank': 'True'}), + 'note': ('django.db.models.fields.TextField', [], {'db_column': "'nota'", 'blank': 'True'}), + 'owner_vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owned_lexemes'", 'db_column': "'slownik'", 'to': u"orm['dictionary.Vocabulary']"}), + 'part_of_speech': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PartOfSpeech']", 'db_column': "'pos'"}), + 'patterns': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Pattern']", 'through': u"orm['dictionary.LexemeInflectionPattern']", 'symmetrical': 'False'}), + 'pronunciation': ('django.db.models.fields.TextField', [], {'db_column': "'wymowa'", 'blank': 'True'}), + 'qualifiers': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Qualifier']", 'symmetrical': 'False', 'db_table': "'kwalifikatory_leksemow'", 'blank': 'True'}), + 'responsible': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'db_column': "'odpowiedzialny'", 'blank': 'True'}), + 'source': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'zrodlo'", 'blank': 'True'}), + 'status': ('django.db.models.fields.CharField', [], {'max_length': '8', 'db_column': "'status'"}) + }, + u'dictionary.lexemeassociation': { + 'Meta': {'object_name': 'LexemeAssociation', 'db_table': "'leksemy_w_slownikach'"}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']", 'db_column': "'l_id'"}), + 'vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Vocabulary']", 'db_column': "'slownik'"}) + }, + u'dictionary.lexemeattribute': { + 'Meta': {'object_name': 'LexemeAttribute'}, + 'closed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'inflection_characteristic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'null': 'True', 'blank': 'True'}), + 'lexical_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.LexicalClass']", 'null': 'True', 'blank': 'True'}), + 'multiple': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'part_of_speech': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PartOfSpeech']", 'null': 'True', 'blank': 'True'}) + }, + u'dictionary.lexemeattributevalue': { + 'Meta': {'object_name': 'LexemeAttributeValue'}, + 'attribute': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'values'", 'to': u"orm['dictionary.LexemeAttribute']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lexemes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Lexeme']", 'symmetrical': 'False', 'blank': 'True'}), + 'value': ('django.db.models.fields.CharField', [], {'max_length': '32'}) + }, + u'dictionary.lexemeform': { + 'Meta': {'object_name': 'LexemeForm'}, + 'form': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']"}) + }, + u'dictionary.lexemeinflectionpattern': { + 'Meta': {'ordering': "['index']", 'unique_together': "(('lexeme', 'index'),)", 'object_name': 'LexemeInflectionPattern', 'db_table': "'odmieniasie'"}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.IntegerField', [], {'db_column': "'oind'"}), + 'inflection_characteristic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'db_column': "'charfl'"}), + 'lexeme': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Lexeme']", 'db_column': "'l_id'"}), + 'pattern': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Pattern']", 'db_column': "'w_id'"}), + 'qualifiers': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['dictionary.Qualifier']", 'symmetrical': 'False', 'db_table': "'kwalifikatory_odmieniasiow'", 'blank': 'True'}), + 'root': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'rdzen'"}) + }, + u'dictionary.lexicalclass': { + 'Meta': {'object_name': 'LexicalClass', 'db_table': "'czescimowy'"}, + 'symbol': ('django.db.models.fields.CharField', [], {'max_length': '16', 'primary_key': 'True', 'db_column': "'czm'"}) + }, + u'dictionary.paradygmatywsjp': { + 'Meta': {'object_name': 'ParadygmatyWSJP', 'db_table': "'paradygmatywsjp'"}, + 'charfl': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'db_column': "'charfl'"}), + 'col': ('django.db.models.fields.IntegerField', [], {}), + 'colspan': ('django.db.models.fields.IntegerField', [], {}), + 'efobaz': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.BaseFormLabel']", 'db_column': "'efobaz'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'kskl': ('django.db.models.fields.IntegerField', [], {}), + 'morf': ('django.db.models.fields.TextField', [], {}), + 'podparad': ('django.db.models.fields.CharField', [], {'max_length': '4', 'blank': 'True'}), + 'pref': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}), + 'row': ('django.db.models.fields.IntegerField', [], {}), + 'rowspan': ('django.db.models.fields.IntegerField', [], {}), + 'suf': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}), + 'typr': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PatternType']", 'db_column': "'typr'"}), + 'wariant': ('django.db.models.fields.CharField', [], {'max_length': '4'}) + }, + u'dictionary.partofspeech': { + 'Meta': {'ordering': "['symbol']", 'object_name': 'PartOfSpeech', 'db_table': "'klasygramatyczne'"}, + 'lexical_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.LexicalClass']", 'db_column': "'czm'"}), + 'symbol': ('django.db.models.fields.CharField', [], {'max_length': '16', 'primary_key': 'True', 'db_column': "'pos'"}) + }, + u'dictionary.pattern': { + 'Meta': {'ordering': "['name']", 'object_name': 'Pattern', 'db_table': "'wzory'"}, + 'basic_form_ending': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'zakp'", 'blank': 'True'}), + 'comment': ('django.db.models.fields.TextField', [], {'db_column': "'komentarz'", 'blank': 'True'}), + 'example': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'przyklad'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32', 'db_column': "'w_id'"}), + 'status': ('django.db.models.fields.CharField', [], {'max_length': '8'}), + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PatternType']", 'db_column': "'typ'"}) + }, + u'dictionary.patterntype': { + 'Meta': {'object_name': 'PatternType', 'db_table': "'typywzorow'"}, + 'entry': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_column': "'wtyp'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'lexical_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.LexicalClass']", 'db_column': "'czm'"}) + }, + u'dictionary.qualifier': { + 'Meta': {'ordering': "['label']", 'unique_together': "(('label', 'vocabulary'),)", 'object_name': 'Qualifier', 'db_table': "'kwalifikatory'"}, + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_column': "'usuniety'"}), + 'exclusion_class': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.QualifierExclusionClass']", 'null': 'True', 'db_column': "'klasa'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'label': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'kwal'"}), + 'vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'qualifiers'", 'db_column': "'slownik'", 'to': u"orm['dictionary.Vocabulary']"}) + }, + u'dictionary.qualifierexclusionclass': { + 'Meta': {'object_name': 'QualifierExclusionClass', 'db_table': "'klasy_wykluczania'"}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_column': "'nazwa'"}), + 'vocabulary': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Vocabulary']", 'db_column': "'slownik'"}) + }, + u'dictionary.savedexportdata': { + 'Meta': {'object_name': 'SavedExportData'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'}), + 'serialized_data': ('django.db.models.fields.TextField', [], {}) + }, + u'dictionary.savedfilter': { + 'Meta': {'unique_together': "(('name', 'user'),)", 'object_name': 'SavedFilter'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'serialized_filter': ('django.db.models.fields.TextField', [], {}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}) + }, + u'dictionary.tablecell': { + 'Meta': {'object_name': 'TableCell', 'db_table': "'komorki_tabel'"}, + 'cell': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['dictionary.Cell']", 'unique': 'True', 'db_column': "'k_id'"}), + 'col': ('django.db.models.fields.IntegerField', [], {}), + 'colspan': ('django.db.models.fields.IntegerField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'row': ('django.db.models.fields.IntegerField', [], {}), + 'rowspan': ('django.db.models.fields.IntegerField', [], {}) + }, + u'dictionary.tableheader': { + 'Meta': {'object_name': 'TableHeader', 'db_table': "'naglowki_tabel'"}, + 'col': ('django.db.models.fields.IntegerField', [], {}), + 'colspan': ('django.db.models.fields.IntegerField', [], {}), + 'css_class': ('django.db.models.fields.CharField', [], {'max_length': '8', 'db_column': "'styl'"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'label': ('django.db.models.fields.CharField', [], {'max_length': '64', 'db_column': "'nagl'", 'blank': 'True'}), + 'row': ('django.db.models.fields.IntegerField', [], {}), + 'rowspan': ('django.db.models.fields.IntegerField', [], {}), + 'table_template': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.TableTemplate']", 'db_column': "'st_id'"}) + }, + u'dictionary.tabletemplate': { + 'Meta': {'object_name': 'TableTemplate', 'db_table': "'szablony_tabel'"}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'inflection_characteristic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.InflectionCharacteristic']", 'db_column': "'charfl'"}), + 'pattern_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.PatternType']", 'db_column': "'wtyp'"}), + 'variant': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['dictionary.Variant']", 'db_column': "'wariant'"}) + }, + u'dictionary.variant': { + 'Meta': {'object_name': 'Variant', 'db_table': "'warianty'"}, + 'id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'primary_key': 'True', 'db_column': "'wariant'"}) + }, + u'dictionary.vocabulary': { + 'Meta': {'object_name': 'Vocabulary', 'db_table': "'slowniki'"}, + 'classifications': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'vocabularies'", 'blank': 'True', 'to': u"orm['dictionary.Classification']"}), + 'editors': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'editable_vocabularies'", 'blank': 'True', 'to': u"orm['auth.User']"}), + 'id': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True', 'db_column': "'slownik'"}), + 'lexemes': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'vocabularies'", 'blank': 'True', 'through': u"orm['dictionary.LexemeAssociation']", 'to': u"orm['dictionary.Lexeme']"}), + 'managers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'managed_vocabularies'", 'blank': 'True', 'to': u"orm['auth.User']"}), + 'viewers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'visible_vocabularies'", 'blank': 'True', 'to': u"orm['auth.User']"}) + } + } + + complete_apps = ['dictionary'] \ No newline at end of file diff --git a/dictionary/models.py b/dictionary/models.py index 9bba203..e3d36ec 100644 --- a/dictionary/models.py +++ b/dictionary/models.py @@ -435,6 +435,29 @@ class Lexeme(Model): self.homonym_number = i break + def attributes(self): + lips = self.lexemeinflectionpattern_set.all() + ics = tuple(lip.inflection_characteristic for lip in lips) + attrs = LexemeAttribute.objects.all() + attrs = (attrs.filter(lexical_class=self.part_of_speech.lexical_class) + | attrs.filter(lexical_class=None)) + attrs = (attrs.filter(part_of_speech=self.part_of_speech) + | attrs.filter(part_of_speech=None)) + attrs = (attrs.filter(inflection_characteristic__in=ics) + | attrs.filter(inflection_characteristic=None)) + return attrs + + def attributes_values(self): + for attr in self.attributes(): + if attr.multiple: + v = attr.values.filter(lexemes=self) + else: + try: + v = attr.values.get(lexemes=self) + except LexemeAttributeValue.DoesNotExist: + v = None + yield (attr, v) + def perm(self, user, action): if action == 'view': vocabs = self.vocabularies.all() @@ -496,17 +519,24 @@ def get_root(basic_form, pos, pattern, ic, use_pattern_ending=False): class LexemeAttribute(Model): name = CharField(max_length=32) closed = BooleanField() # czy jest zamknięta lista wartości + multiple = BooleanField() lexical_class = ForeignKey(LexicalClass, blank=True, null=True) part_of_speech = ForeignKey(PartOfSpeech, blank=True, null=True) inflection_characteristic = ForeignKey( InflectionCharacteristic, blank=True, null=True) + def __unicode__(self): + return self.name + class LexemeAttributeValue(Model): value = CharField(max_length=32) attribute = ForeignKey(LexemeAttribute, related_name='values') lexemes = ManyToManyField(Lexeme, blank=True) + def __unicode__(self): + return self.value + class LexemeInflectionPattern(Model): lexeme = ForeignKey(Lexeme, db_column='l_id') diff --git a/dictionary/templates/lexeme_edit_form.html b/dictionary/templates/lexeme_edit_form.html index f2fb390..6acee11 100644 --- a/dictionary/templates/lexeme_edit_form.html +++ b/dictionary/templates/lexeme_edit_form.html @@ -12,6 +12,9 @@ </p> {% endif %} {% endfor %} + {% for form in attribute_forms %} + {{ form.as_p }} + {% endfor %} <p> Sposoby odmiany: <input type="hidden" name="id" value="{{ id }}"/> diff --git a/sql/history.sql b/sql/history.sql index 425ab0a..e572984 100644 --- a/sql/history.sql +++ b/sql/history.sql @@ -2,7 +2,8 @@ ALTER TABLE history ALTER user_id_ SET DEFAULT current_setting('var.user_id'::text)::integer, - ALTER transaction_began_ SET DEFAULT transaction_timestamp(); + ALTER transaction_began_ SET DEFAULT transaction_timestamp(), + ALTER timestamp_ SET DEFAULT clock_timestamp(); -- make_history_