From df9317ac366977185d2d4f628991d9c4d02d97b5 Mon Sep 17 00:00:00 2001 From: janek@kublik <janek@kublik> Date: Sun, 13 Dec 2015 14:26:01 +0100 Subject: [PATCH] migracja Cell, TableHeader --- common/util.py | 5 +++++ dictionary/management/commands/stale/convert_tables.py | 3 ++- dictionary/management/commands/stale/export_variant.py | 2 +- dictionary/management/commands/stale/import_variant.py | 2 +- dictionary/management/commands/stale/table_analyzer.py | 2 +- dictionary/migrations/0016_auto_20151213_1400.py | 22 ++++++++++++++++++++++ dictionary/migrations/0017_auto_20151213_1400.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dictionary/models.py | 146 -------------------------------------------------------------------------------------------------------------------------------------------------- management/ajax_table_view.py | 6 +++--- tables/management/commands/import_template.py | 6 +++--- tables/migrations/0003_exportcell_tablecell_tableheader.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tables/models.py | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 12 files changed, 351 insertions(+), 160 deletions(-) create mode 100644 dictionary/migrations/0016_auto_20151213_1400.py create mode 100644 dictionary/migrations/0017_auto_20151213_1400.py create mode 100644 tables/migrations/0003_exportcell_tablecell_tableheader.py diff --git a/common/util.py b/common/util.py index 97b387f..8ae175c 100644 --- a/common/util.py +++ b/common/util.py @@ -139,6 +139,11 @@ class FakeQueryset(list): def all(self): return self + def iterator(self): + return iter(self) + + _prefetch_related_lookups = False + def format_date(date): return date.strftime(force_unicode(_('%Y/%m/%d %I:%M %p'))) diff --git a/dictionary/management/commands/stale/convert_tables.py b/dictionary/management/commands/stale/convert_tables.py index 11fc523..41a111a 100644 --- a/dictionary/management/commands/stale/convert_tables.py +++ b/dictionary/management/commands/stale/convert_tables.py @@ -3,7 +3,8 @@ from django.core.management import BaseCommand from common.util import GroupDict from dictionary.models import Cell, TableTemplate, PatternType, TableTemplate, TableCell, TableHeader, \ TableHeader, LexemeAttribute, ExportCell, InflectionCharacteristic, LexemeAttributeValue -from tables.models import Variant, TableTemplate +from tables.models import Variant, TableTemplate, Cell, TableCell, ExportCell, \ + TableHeader from patterns.models import InflectionType, PatternType diff --git a/dictionary/management/commands/stale/export_variant.py b/dictionary/management/commands/stale/export_variant.py index c3ff87a..b65ca6b 100644 --- a/dictionary/management/commands/stale/export_variant.py +++ b/dictionary/management/commands/stale/export_variant.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django.core.management import BaseCommand from common.util import uniprint -from dictionary.models import Cell +from tables.models import Cell class Command(BaseCommand): diff --git a/dictionary/management/commands/stale/import_variant.py b/dictionary/management/commands/stale/import_variant.py index 2d7e7c4..237e9bf 100644 --- a/dictionary/management/commands/stale/import_variant.py +++ b/dictionary/management/commands/stale/import_variant.py @@ -5,7 +5,7 @@ from django.core.management.base import BaseCommand from common.util import uniopen from dictionary.models import TableTemplate, Cell, TableCell, PartOfSpeech, \ PatternType, InflectionCharacteristic -from tables.models import Variant, TableTemplate +from tables.models import Variant, TableTemplate, Cell, TableCell from patterns.models import BaseFormLabel, PatternType diff --git a/dictionary/management/commands/stale/table_analyzer.py b/dictionary/management/commands/stale/table_analyzer.py index 651bd20..4ac9a12 100644 --- a/dictionary/management/commands/stale/table_analyzer.py +++ b/dictionary/management/commands/stale/table_analyzer.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django.core.management import BaseCommand from dictionary.models import Cell -from tables.models import Variant +from tables.models import Variant, Cell class Command(BaseCommand): diff --git a/dictionary/migrations/0016_auto_20151213_1400.py b/dictionary/migrations/0016_auto_20151213_1400.py new file mode 100644 index 0000000..3c2ef0a --- /dev/null +++ b/dictionary/migrations/0016_auto_20151213_1400.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dictionary', '0015_auto_20151213_1328'), + ] + + database_operations = [ + migrations.AlterModelTable('tablecell', 'tables_tablecell'), + migrations.AlterModelTable('exportcell', 'tables_exportcell'), + migrations.AlterModelTable('tableheader', 'tables_tableheader'), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + database_operations=database_operations) + ] diff --git a/dictionary/migrations/0017_auto_20151213_1400.py b/dictionary/migrations/0017_auto_20151213_1400.py new file mode 100644 index 0000000..1406d85 --- /dev/null +++ b/dictionary/migrations/0017_auto_20151213_1400.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dictionary', '0016_auto_20151213_1400'), + ('tables', '0003_exportcell_tablecell_tableheader'), + ] + + state_operations = [ + migrations.RemoveField( + model_name='exportcell', + name='attribute_values', + ), + migrations.RemoveField( + model_name='exportcell', + name='base_form_label', + ), + migrations.RemoveField( + model_name='exportcell', + name='genders', + ), + migrations.RemoveField( + model_name='exportcell', + name='pattern_types', + ), + migrations.RemoveField( + model_name='exportcell', + name='table_template', + ), + migrations.RemoveField( + model_name='tablecell', + name='attribute_values', + ), + migrations.RemoveField( + model_name='tablecell', + name='base_form_label', + ), + migrations.RemoveField( + model_name='tablecell', + name='genders', + ), + migrations.RemoveField( + model_name='tablecell', + name='marked_attribute_values', + ), + migrations.RemoveField( + model_name='tablecell', + name='pattern_types', + ), + migrations.RemoveField( + model_name='tablecell', + name='table_template', + ), + migrations.RemoveField( + model_name='tableheader', + name='attribute_values', + ), + migrations.RemoveField( + model_name='tableheader', + name='genders', + ), + migrations.RemoveField( + model_name='tableheader', + name='pattern_types', + ), + migrations.RemoveField( + model_name='tableheader', + name='table_template', + ), + migrations.DeleteModel( + name='ExportCell', + ), + migrations.DeleteModel( + name='TableCell', + ), + migrations.DeleteModel( + name='TableHeader', + ), + ] + + operations = [ + migrations.SeparateDatabaseAndState(state_operations=state_operations), + ] diff --git a/dictionary/models.py b/dictionary/models.py index c16921f..7e33ffa 100644 --- a/dictionary/models.py +++ b/dictionary/models.py @@ -793,19 +793,6 @@ class LexemeInflectionPattern(Model): ordering = ['index'] -def combine_qualifiers(lip_qualifiers, e_qualifiers): - # qualifiers = set(l_qualifiers) - if not lip_qualifiers: - return e_qualifiers - qualifiers = set() - for q in list(lip_qualifiers) + list(e_qualifiers): - if q.exclusion_class: - excluded = set(q.exclusion_class.qualifier_set.all()) - qualifiers -= excluded - qualifiers.add(q) - return qualifiers - - # Sluzy do doczepienia flag do poszczegolnych form # poszczegolnych leksemow # class UncommonForm(Model): @@ -1009,139 +996,6 @@ class CrossReference(Model): db_table = 'odsylacze' -class Cell(Model): - base_form_label = ForeignKey(BaseFormLabel) - prefix = CharField(max_length=20, blank=True) - suffix = CharField(max_length=20, blank=True) - - def get_index(self): - return None - - def get_qualifier(self): - return '' - - def get_marked_attribute_values(self): - return set() - - def forms(self, base_endings=None, separator=u'', root=u'', - lip_qualifiers=None, lip_index=0, qualifiers=None, - edit_view=False, span=False, depr=None, cell_qualifier=False): - if qualifiers: - qualifiers_set = set(qualifiers) - - def filter_quals(quals): - if not qualifiers: - return set(quals) - else: - return set(quals) & qualifiers_set - - if lip_qualifiers and not edit_view: - # l_qual = filter_quals(lexeme_qualifiers) - lip_qual = filter_quals(lip_qualifiers) - else: - lip_qual = set() - endings = base_endings[self.base_form_label] - if span: - form_template = ( - '<span class="root">%s</span>' - '%s<span class="ending">%s</span>') - else: - form_template = '%s%s%s' - if self.prefix and span: - form_template = '<span class="prefix">%s</span>' + form_template - else: - form_template = '%s' + form_template - if self.suffix and span: - form_template += '<span class="suffix">%s</span>' - else: - form_template += '%s' - if depr and depr in self.get_marked_attribute_values(): - form_template = ( - '<span class="marked-form" title="%s">%s</span>' - % (depr.display_value, form_template)) - if cell_qualifier and self.get_qualifier(): - form_template += ( - ' <span class="cell-qualifier">%s</span>' - % self.get_qualifier()) - forms = [ - ( - (self.get_index(), lip_index, ending.index), - (form_template % ( - self.prefix, root, separator, ending.string, self.suffix)), - combine_qualifiers( - lip_qual, filter_quals(ending.qualifiers.all())), - ) - for ending in endings - ] - return forms - - class Meta: - abstract = True - - -class TableCell(Cell): - table_template = ForeignKey('tables.TableTemplate', related_name='table_cells') - pattern_types = ManyToManyField(PatternType) - genders = ManyToManyField(Gender) - attribute_values = ManyToManyField( - LexemeAttributeValue, related_name='table_cells') - marked_attribute_values = ManyToManyField( - LexemeAttributeValue, related_name='marked_cells') - qualifier = CharField(max_length=128, blank=True) - row = IntegerField() - col = IntegerField() - rowspan = IntegerField() - colspan = IntegerField() - index = IntegerField() - - def get_index(self): - return self.index - - def get_qualifier(self): - return self.qualifier - - def get_marked_attribute_values(self): - return set(self.marked_attribute_values.all()) - - def __unicode__(self): - return '%s:%s %s-%s-%s (%s, %s)' % ( - self.table_template.variant_id, self.table_template.name, - self.prefix, self.base_form_label.symbol, self.suffix, - self.row, self.col) - - -class ExportCell(Cell): - table_template = ForeignKey('tables.TableTemplate', related_name='export_cells') - pattern_types = ManyToManyField(PatternType) - genders = ManyToManyField(Gender) - attribute_values = ManyToManyField(LexemeAttributeValue) - tag_template = TextField() - - def __unicode__(self): - return '%s:%s %s-%s-%s (%s)' % ( - self.table_template.variant.id, self.table_template.name, - self.prefix, self.base_form_label.symbol, self.suffix, - self.tag_template) - - -class TableHeader(Model): - table_template = ForeignKey('tables.TableTemplate', related_name='headers') - pattern_types = ManyToManyField(PatternType) - genders = ManyToManyField(Gender) - attribute_values = ManyToManyField(LexemeAttributeValue) - row = IntegerField() - col = IntegerField() - rowspan = IntegerField() - colspan = IntegerField() - label = CharField(max_length=64, blank=True, db_column='nagl') - css_class = CharField(max_length=8, db_column='styl') - - def __unicode__(self): - return u'%s:%s %s (%s, %s)' % ( - self.table_template.variant_id, self.table_template.name, - self.label, self.row, self.col) - - # na szybko i brudno class ParadygmatyWSJP(Model): wariant = CharField(max_length=4) diff --git a/management/ajax_table_view.py b/management/ajax_table_view.py index e7c94b0..8fc954c 100644 --- a/management/ajax_table_view.py +++ b/management/ajax_table_view.py @@ -5,9 +5,9 @@ from dictionary.forms import LexemeClosedAttributeForm from management.forms import CellRestrictionsForm, GenderForm, \ AttributeValuesForm, BaseFormLabelForm, CSSClassForm, TemplatePreviewForm, \ TemplatePreviewGenderForm -from dictionary.models import TableCell, TableHeader, ExportCell, Gender, \ - LexemeAttributeValue -from tables.models import Variant, TableTemplate +from dictionary.models import Gender, LexemeAttributeValue +from tables.models import Variant, TableTemplate, TableCell, ExportCell, \ + TableHeader from patterns.models import BaseFormLabel, PatternType diff --git a/tables/management/commands/import_template.py b/tables/management/commands/import_template.py index 1bb4ad4..9610f47 100644 --- a/tables/management/commands/import_template.py +++ b/tables/management/commands/import_template.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- import json from django.core.management.base import BaseCommand -from dictionary.models import TableCell, \ - LexemeAttributeValue, TableHeader, ExportCell, Gender -from tables.models import Variant, TableTemplate +from dictionary.models import LexemeAttributeValue, Gender +from tables.models import Variant, TableTemplate, TableCell, ExportCell, \ + TableHeader from patterns.models import BaseFormLabel, PatternType diff --git a/tables/migrations/0003_exportcell_tablecell_tableheader.py b/tables/migrations/0003_exportcell_tablecell_tableheader.py new file mode 100644 index 0000000..aad5eef --- /dev/null +++ b/tables/migrations/0003_exportcell_tablecell_tableheader.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('patterns', '0006_auto_20151213_1153'), + ('dictionary', '0016_auto_20151213_1400'), + ('tables', '0002_tabletemplate'), + ] + + state_operations = [ + migrations.CreateModel( + name='ExportCell', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('prefix', models.CharField(max_length=20, blank=True)), + ('suffix', models.CharField(max_length=20, blank=True)), + ('tag_template', models.TextField()), + ('attribute_values', models.ManyToManyField(to='dictionary.LexemeAttributeValue')), + ('base_form_label', models.ForeignKey(to='patterns.BaseFormLabel')), + ('genders', models.ManyToManyField(to='dictionary.Gender')), + ('pattern_types', models.ManyToManyField(to='patterns.PatternType')), + ('table_template', models.ForeignKey(related_name='export_cells', to='tables.TableTemplate')), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='TableCell', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('prefix', models.CharField(max_length=20, blank=True)), + ('suffix', models.CharField(max_length=20, blank=True)), + ('qualifier', models.CharField(max_length=128, blank=True)), + ('row', models.IntegerField()), + ('col', models.IntegerField()), + ('rowspan', models.IntegerField()), + ('colspan', models.IntegerField()), + ('index', models.IntegerField()), + ('attribute_values', models.ManyToManyField(related_name='table_cells', to='dictionary.LexemeAttributeValue')), + ('base_form_label', models.ForeignKey(to='patterns.BaseFormLabel')), + ('genders', models.ManyToManyField(to='dictionary.Gender')), + ('marked_attribute_values', models.ManyToManyField(related_name='marked_cells', to='dictionary.LexemeAttributeValue')), + ('pattern_types', models.ManyToManyField(to='patterns.PatternType')), + ('table_template', models.ForeignKey(related_name='table_cells', to='tables.TableTemplate')), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='TableHeader', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('row', models.IntegerField()), + ('col', models.IntegerField()), + ('rowspan', models.IntegerField()), + ('colspan', models.IntegerField()), + ('label', models.CharField(max_length=64, db_column=b'nagl', blank=True)), + ('css_class', models.CharField(max_length=8, db_column=b'styl')), + ('attribute_values', models.ManyToManyField(to='dictionary.LexemeAttributeValue')), + ('genders', models.ManyToManyField(to='dictionary.Gender')), + ('pattern_types', models.ManyToManyField(to='patterns.PatternType')), + ('table_template', models.ForeignKey(related_name='headers', to='tables.TableTemplate')), + ], + ), + ] + + operations = [ + migrations.SeparateDatabaseAndState(state_operations=state_operations), + ] diff --git a/tables/models.py b/tables/models.py index f1f79da..d5cf6b0 100644 --- a/tables/models.py +++ b/tables/models.py @@ -2,11 +2,11 @@ from itertools import izip from django.db.models import Model, CharField, TextField, ForeignKey, \ - ManyToManyField, BooleanField + ManyToManyField, BooleanField, IntegerField from dictionary.models import PartOfSpeech, LexemeAttribute, \ - LexemeAttributeValue -from patterns.models import PatternType + LexemeAttributeValue, Gender +from patterns.models import PatternType, BaseFormLabel from tables.util import prepare_table @@ -171,4 +171,149 @@ class TableTemplate(Model): if not all(cell['type'] == 'empty' for cell in row)] def __unicode__(self): - return self.name \ No newline at end of file + return self.name + + +def combine_qualifiers(lip_qualifiers, e_qualifiers): + if not lip_qualifiers: + return e_qualifiers + qualifiers = set() + for q in list(lip_qualifiers) + list(e_qualifiers): + if q.exclusion_class: + excluded = set(q.exclusion_class.qualifier_set.all()) + qualifiers -= excluded + qualifiers.add(q) + return qualifiers + + +class Cell(Model): + base_form_label = ForeignKey(BaseFormLabel) + prefix = CharField(max_length=20, blank=True) + suffix = CharField(max_length=20, blank=True) + + def get_index(self): + return None + + def get_qualifier(self): + return '' + + def get_marked_attribute_values(self): + return set() + + def forms(self, base_endings=None, separator=u'', root=u'', + lip_qualifiers=None, lip_index=0, qualifiers=None, + edit_view=False, span=False, depr=None, cell_qualifier=False): + if qualifiers: + qualifiers_set = set(qualifiers) + + def filter_quals(quals): + if not qualifiers: + return set(quals) + else: + return set(quals) & qualifiers_set + + if lip_qualifiers and not edit_view: + # l_qual = filter_quals(lexeme_qualifiers) + lip_qual = filter_quals(lip_qualifiers) + else: + lip_qual = set() + endings = base_endings[self.base_form_label] + if span: + form_template = ( + '<span class="root">%s</span>' + '%s<span class="ending">%s</span>') + else: + form_template = '%s%s%s' + if self.prefix and span: + form_template = '<span class="prefix">%s</span>' + form_template + else: + form_template = '%s' + form_template + if self.suffix and span: + form_template += '<span class="suffix">%s</span>' + else: + form_template += '%s' + if depr and depr in self.get_marked_attribute_values(): + form_template = ( + '<span class="marked-form" title="%s">%s</span>' + % (depr.display_value, form_template)) + if cell_qualifier and self.get_qualifier(): + form_template += ( + ' <span class="cell-qualifier">%s</span>' + % self.get_qualifier()) + forms = [ + ( + (self.get_index(), lip_index, ending.index), + (form_template % ( + self.prefix, root, separator, ending.string, self.suffix)), + combine_qualifiers( + lip_qual, filter_quals(ending.qualifiers.all())), + ) + for ending in endings + ] + return forms + + class Meta: + abstract = True + + +class TableCell(Cell): + table_template = ForeignKey('tables.TableTemplate', related_name='table_cells') + pattern_types = ManyToManyField(PatternType) + genders = ManyToManyField(Gender) + attribute_values = ManyToManyField( + LexemeAttributeValue, related_name='table_cells') + marked_attribute_values = ManyToManyField( + LexemeAttributeValue, related_name='marked_cells') + qualifier = CharField(max_length=128, blank=True) + row = IntegerField() + col = IntegerField() + rowspan = IntegerField() + colspan = IntegerField() + index = IntegerField() + + def get_index(self): + return self.index + + def get_qualifier(self): + return self.qualifier + + def get_marked_attribute_values(self): + return set(self.marked_attribute_values.all()) + + def __unicode__(self): + return '%s:%s %s-%s-%s (%s, %s)' % ( + self.table_template.variant_id, self.table_template.name, + self.prefix, self.base_form_label.symbol, self.suffix, + self.row, self.col) + + +class ExportCell(Cell): + table_template = ForeignKey('tables.TableTemplate', related_name='export_cells') + pattern_types = ManyToManyField(PatternType) + genders = ManyToManyField(Gender) + attribute_values = ManyToManyField(LexemeAttributeValue) + tag_template = TextField() + + def __unicode__(self): + return '%s:%s %s-%s-%s (%s)' % ( + self.table_template.variant.id, self.table_template.name, + self.prefix, self.base_form_label.symbol, self.suffix, + self.tag_template) + + +class TableHeader(Model): + table_template = ForeignKey('tables.TableTemplate', related_name='headers') + pattern_types = ManyToManyField(PatternType) + genders = ManyToManyField(Gender) + attribute_values = ManyToManyField(LexemeAttributeValue) + row = IntegerField() + col = IntegerField() + rowspan = IntegerField() + colspan = IntegerField() + label = CharField(max_length=64, blank=True, db_column='nagl') + css_class = CharField(max_length=8, db_column='styl') + + def __unicode__(self): + return u'%s:%s %s (%s, %s)' % ( + self.table_template.variant_id, self.table_template.name, + self.label, self.row, self.col) -- libgit2 0.22.2