Commit bd965883a57e6010da8e21bea4442412869c73eb
1 parent
6960025a
osobna aplikacja do tabelek
--HG-- branch : beta rename : dictionary/management/commands/export_template.py => tables/management/commands/export_template.py rename : dictionary/management/commands/export_templates.py => tables/management/commands/export_templates.py rename : dictionary/management/commands/import_template.py => tables/management/commands/import_template.py rename : dictionary/management/commands/import_templates.py => tables/management/commands/import_templates.py rename : dictionary/templates/inflection_table.html => tables/templates/inflection_table.html rename : management/templates/table_preview.html => tables/templates/table_preview.html
Showing
21 changed files
with
112 additions
and
85 deletions
dictionary/ajax_lexeme_view.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | -from django.utils import timezone | |
3 | - | |
4 | 2 | from django.core.cache import cache |
3 | +from django.db.models import Max | |
5 | 4 | from django.shortcuts import get_object_or_404 |
5 | +from django.utils import timezone | |
6 | 6 | from django.utils.encoding import force_unicode |
7 | 7 | from django.utils.translation import ugettext as _ |
8 | -from django.db.models import Max | |
9 | 8 | |
9 | +from common.decorators import ajax, AjaxError, render_ajax | |
10 | +from common.util import error_messages, bisect_left, format_date | |
10 | 11 | from dictionary.ajax_lexeme_slickgrid import LexemeQuery |
11 | 12 | from dictionary.auto_derivatives import lexeme_derivatives, create_derivative |
12 | -from dictionary.models import Lexeme, LexemeInflectionPattern, PartOfSpeech, \ | |
13 | - Vocabulary, Qualifier, ClassificationValue, CrossReference, InputLexeme, \ | |
14 | - CrossReferenceType, LexemeAttributeValue, Gender, LexemeAttribute, \ | |
15 | - LexemeAV, LexemeCV, LexemeList | |
16 | -from dictionary.util import prepare_table | |
17 | -from patterns.models import Pattern, Ending | |
18 | 13 | from dictionary.forms import LexemeEditForm, LIPEditForm, ClassificationForm, \ |
19 | 14 | CrossReferenceForm, ActionFieldForm, ACTION_FIELDS,\ |
20 | 15 | LexemeOpenAttributeForm, LexemeClosedAttributeForm, \ |
21 | 16 | LexemeMultipleAttributeForm |
22 | -from common.decorators import ajax, AjaxError, render_ajax | |
23 | -from common.util import error_messages, bisect_left, format_date | |
17 | +from dictionary.models import Lexeme, LexemeInflectionPattern, PartOfSpeech, \ | |
18 | + Vocabulary, Qualifier, ClassificationValue, CrossReference, InputLexeme, \ | |
19 | + CrossReferenceType, LexemeAttributeValue, Gender, LexemeAttribute, \ | |
20 | + LexemeAV, LexemeCV, LexemeList | |
21 | +from patterns.models import Ending | |
24 | 22 | |
25 | 23 | |
26 | 24 | @render_ajax( |
... | ... | @@ -56,43 +54,6 @@ def inflection_tables(request, variant, lexeme_id): |
56 | 54 | } |
57 | 55 | |
58 | 56 | |
59 | -@render_ajax(template='table_preview.html', method='get') | |
60 | -def table_preview(request, lexeme_id, lip_id, pattern, attr_data=None, | |
61 | - gender=None, entry=None, pos=None): | |
62 | - lexeme = Lexeme.all_objects.get(pk=lexeme_id) | |
63 | - if not lexeme.perm(request.user, 'view'): | |
64 | - raise AjaxError('access denied') | |
65 | - if pos is not None: | |
66 | - part_of_speech = PartOfSpeech.objects.get(symbol=pos) | |
67 | - else: | |
68 | - part_of_speech = lexeme.part_of_speech | |
69 | - try: | |
70 | - if entry is not None: | |
71 | - lexeme.entry = entry | |
72 | - pattern = Pattern.objects.get(name=pattern) | |
73 | - gender = Gender.objects.get(id=gender) if gender else None | |
74 | - if attr_data: | |
75 | - attr_vals = LexemeAttributeValue.objects.filter( | |
76 | - id__in=attr_data) | |
77 | - else: | |
78 | - attr_vals = None | |
79 | - if lip_id.startswith('lip_add'): | |
80 | - lip = LexemeInflectionPattern(lexeme=lexeme, index=0) | |
81 | - else: | |
82 | - lip = LexemeInflectionPattern.objects.get(pk=int(lip_id[3:])) | |
83 | - lip.pattern = pattern | |
84 | - lip.gender = gender | |
85 | - lip.root = lip.get_root() | |
86 | - qualifiers = Qualifier.visible_qualifiers(request.user) | |
87 | - table = lip.inflection_table( | |
88 | - '0', separated=True, qualifiers=qualifiers, edit_view=True, | |
89 | - attr_vals=attr_vals, pos=part_of_speech) | |
90 | - prepare_table(table) | |
91 | - except Pattern.DoesNotExist: | |
92 | - table = None | |
93 | - return {'table': table, 'color_scheme': part_of_speech.color_scheme} | |
94 | - | |
95 | - | |
96 | 57 | @ajax(template='odm_forms.html', method='get') |
97 | 58 | def odm_forms(request, lexeme_id): |
98 | 59 | to_return = {} |
... | ... |
dictionary/models.py
... | ... | @@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _, get_language |
12 | 12 | from accounts.util import users_with_perm |
13 | 13 | from common.models import NotDeletedManager |
14 | 14 | from common.util import no_history |
15 | -from dictionary.util import prepare_table | |
15 | +from tables.util import prepare_table | |
16 | 16 | from patterns.models import InflectionType, BaseFormLabel, PatternType, Pattern |
17 | 17 | |
18 | 18 | |
... | ... |
dictionary/urls.py
... | ... | @@ -25,7 +25,6 @@ urlpatterns += patterns( |
25 | 25 | url(r'^ajax/odm-forms/$', 'odm_forms'), |
26 | 26 | url(r'^ajax/lexeme-edit-form/$', 'lexeme_edit_form'), |
27 | 27 | url(r'^ajax/update-lexeme/$', 'update_lexeme'), |
28 | - url(r'^ajax/table-preview/$', 'table_preview'), | |
29 | 28 | url(r'^ajax/new-lip-row/$', 'new_lip_edit_row'), |
30 | 29 | url(r'^ajax/new-cr-row/$', 'new_cross_reference_row'), |
31 | 30 | url(r'^ajax/delete-lexeme/$', 'delete_lexeme'), |
... | ... |
dictionary/util.py
... | ... | @@ -58,36 +58,3 @@ def check_query_params(request, query_params): |
58 | 58 | reader = query_params.get('reader', True) |
59 | 59 | if not request.user.is_authenticated() and not reader: |
60 | 60 | raise AjaxError('access denied') |
61 | - | |
62 | - | |
63 | -def prepare_table(table): | |
64 | - for row in table: | |
65 | - for cell in row: | |
66 | - if type(cell) == dict and 'forms' in cell: | |
67 | - cell['forms'].sort() | |
68 | - seen_forms = [] | |
69 | - unique_forms = [] | |
70 | - form_patterns = {} | |
71 | - for form in cell['forms']: | |
72 | - if form[1] not in seen_forms: | |
73 | - seen_forms.append(form[1]) | |
74 | - unique_forms.append(form) | |
75 | - form_patterns[form[1]] = set() | |
76 | - form_patterns[form[1]].add(form[3]) | |
77 | - cell['forms'] = [ | |
78 | - { | |
79 | - 'form': form, | |
80 | - 'qualifiers': qualifiers, | |
81 | - 'patterns': form_patterns[form], | |
82 | - } | |
83 | - for (key, form, qualifiers, pattern) in unique_forms] | |
84 | - elif type(cell) == dict and 'label' in cell: | |
85 | - seen_labels = [] | |
86 | - | |
87 | - def is_new(label): | |
88 | - new = label not in seen_labels | |
89 | - seen_labels.append(label) | |
90 | - return new | |
91 | - | |
92 | - cell['label'] = filter(is_new, cell['label']) | |
93 | - return table | |
94 | 61 | \ No newline at end of file |
... | ... |
settings.py
tables/__init__.py
0 → 100644
tables/management/__init__.py
0 → 100644
tables/management/commands/__init__.py
0 → 100644
dictionary/management/commands/export_template.py renamed to tables/management/commands/export_template.py
dictionary/management/commands/export_templates.py renamed to tables/management/commands/export_templates.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from django.core.management.base import BaseCommand |
3 | + | |
3 | 4 | from common.util import uniprint, json_encode |
4 | -from dictionary.management.commands.export_template import export_template | |
5 | 5 | from dictionary.models import TableTemplate |
6 | +from tables.management.commands.export_template import export_template | |
6 | 7 | |
7 | 8 | |
8 | 9 | class Command(BaseCommand): |
... | ... |
dictionary/management/commands/import_template.py renamed to tables/management/commands/import_template.py
dictionary/management/commands/import_templates.py renamed to tables/management/commands/import_templates.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | import json |
3 | + | |
3 | 4 | from django.core.management.base import BaseCommand |
4 | -from dictionary.management.commands.import_template import import_template | |
5 | + | |
5 | 6 | from dictionary.models import TableTemplate, LexemeAttribute, \ |
6 | 7 | LexemeAttributeValue |
7 | 8 | from patterns.models import PatternType |
9 | +from tables.management.commands.import_template import import_template | |
8 | 10 | |
9 | 11 | |
10 | 12 | class Command(BaseCommand): |
... | ... |
tables/migrations/__init__.py
0 → 100644
tables/models.py
0 → 100644
dictionary/templates/inflection_table.html renamed to tables/templates/inflection_table.html
management/templates/table_preview.html renamed to tables/templates/table_preview.html
tables/tests.py
0 → 100644
tables/urls.py
0 → 100644
tables/util.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
3 | + | |
4 | +def prepare_table(table): | |
5 | + for row in table: | |
6 | + for cell in row: | |
7 | + if type(cell) == dict and 'forms' in cell: | |
8 | + cell['forms'].sort() | |
9 | + seen_forms = [] | |
10 | + unique_forms = [] | |
11 | + form_patterns = {} | |
12 | + for form in cell['forms']: | |
13 | + if form[1] not in seen_forms: | |
14 | + seen_forms.append(form[1]) | |
15 | + unique_forms.append(form) | |
16 | + form_patterns[form[1]] = set() | |
17 | + form_patterns[form[1]].add(form[3]) | |
18 | + cell['forms'] = [ | |
19 | + { | |
20 | + 'form': form, | |
21 | + 'qualifiers': qualifiers, | |
22 | + 'patterns': form_patterns[form], | |
23 | + } | |
24 | + for (key, form, qualifiers, pattern) in unique_forms] | |
25 | + elif type(cell) == dict and 'label' in cell: | |
26 | + seen_labels = [] | |
27 | + | |
28 | + def is_new(label): | |
29 | + new = label not in seen_labels | |
30 | + seen_labels.append(label) | |
31 | + return new | |
32 | + | |
33 | + cell['label'] = filter(is_new, cell['label']) | |
34 | + return table | |
... | ... |
tables/views.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | +from django.shortcuts import render | |
3 | + | |
4 | +from common.decorators import render_ajax, AjaxError | |
5 | +from dictionary.models import Lexeme, PartOfSpeech, Gender, \ | |
6 | + LexemeAttributeValue, LexemeInflectionPattern, Qualifier | |
7 | +from tables.util import prepare_table | |
8 | +from patterns.models import Pattern | |
9 | + | |
10 | + | |
11 | +@render_ajax(template='table_preview.html', method='get') | |
12 | +def table_preview(request, lexeme_id, lip_id, pattern, attr_data=None, | |
13 | + gender=None, entry=None, pos=None): | |
14 | + lexeme = Lexeme.all_objects.get(pk=lexeme_id) | |
15 | + if not lexeme.perm(request.user, 'view'): | |
16 | + raise AjaxError('access denied') | |
17 | + if pos is not None: | |
18 | + part_of_speech = PartOfSpeech.objects.get(symbol=pos) | |
19 | + else: | |
20 | + part_of_speech = lexeme.part_of_speech | |
21 | + try: | |
22 | + if entry is not None: | |
23 | + lexeme.entry = entry | |
24 | + pattern = Pattern.objects.get(name=pattern) | |
25 | + gender = Gender.objects.get(id=gender) if gender else None | |
26 | + if attr_data: | |
27 | + attr_vals = LexemeAttributeValue.objects.filter( | |
28 | + id__in=attr_data) | |
29 | + else: | |
30 | + attr_vals = None | |
31 | + if lip_id.startswith('lip_add'): | |
32 | + lip = LexemeInflectionPattern(lexeme=lexeme, index=0) | |
33 | + else: | |
34 | + lip = LexemeInflectionPattern.objects.get(pk=int(lip_id[3:])) | |
35 | + lip.pattern = pattern | |
36 | + lip.gender = gender | |
37 | + lip.root = lip.get_root() | |
38 | + qualifiers = Qualifier.visible_qualifiers(request.user) | |
39 | + table = lip.inflection_table( | |
40 | + '0', separated=True, qualifiers=qualifiers, edit_view=True, | |
41 | + attr_vals=attr_vals, pos=part_of_speech) | |
42 | + prepare_table(table) | |
43 | + except Pattern.DoesNotExist: | |
44 | + table = None | |
45 | + return {'table': table, 'color_scheme': part_of_speech.color_scheme} | |
0 | 46 | \ No newline at end of file |
... | ... |