Commit dd653a8fbfce46af88abf502a66f387853ba9bb7
1 parent
e863450e
automatyczny id leksemów
--HG-- branch : beta
Showing
5 changed files
with
34 additions
and
42 deletions
dictionary/ajax_lexeme_view.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from django.core.cache import cache |
3 | -from django.db.models import Max | |
4 | 3 | from django.shortcuts import get_object_or_404 |
5 | 4 | from django.utils import timezone |
6 | 5 | from django.utils.encoding import force_unicode |
... | ... | @@ -529,7 +528,8 @@ def update_back_references(request, deleted_cr, created_cr): |
529 | 528 | |
530 | 529 | def update_lexeme_qualifiers(lexeme, user, form_dict, form_data): |
531 | 530 | owner = lexeme.owner_vocabulary |
532 | - editable_vocabs = Vocabulary.editable_vocabularies(user).exclude(pk=owner.pk) | |
531 | + editable_vocabs = Vocabulary.editable_vocabularies(user)\ | |
532 | + .exclude(pk=owner.pk) | |
533 | 533 | # l_editable_vocabs = lexeme.editable_vocabularies(user) |
534 | 534 | l_editable_vocabs = Vocabulary.editable_vocabularies(user) |
535 | 535 | qualifiers = Qualifier.objects.filter(vocabulary__in=l_editable_vocabs) |
... | ... | @@ -585,22 +585,15 @@ def check_pos(request, pos_id, had_gender): |
585 | 585 | return {'answer': 'no'} |
586 | 586 | |
587 | 587 | |
588 | -START_ID = 1000000 | |
589 | - | |
590 | - | |
591 | 588 | @ajax(method='post') |
592 | 589 | def create_lexeme(request): |
593 | 590 | owner = request.user.usersettings.get_default_owner() |
594 | 591 | pos_id = request.user.usersettings.default_pos_id or 'subst' |
595 | 592 | if not owner: |
596 | 593 | raise AjaxError(_(u'Empty owner dictionary')) |
597 | - next_id = Lexeme.all_objects.filter( | |
598 | - pk__gte=START_ID).aggregate(Max('id'))['id__max'] | |
599 | - next_id = next_id + 1 if next_id else START_ID | |
600 | 594 | l = Lexeme.objects.create( |
601 | - id=next_id, part_of_speech_id=pos_id, | |
602 | - owner_vocabulary=owner, status=Lexeme.STATUS_CANDIDATE, | |
603 | - responsible=request.user, deleted=True) | |
595 | + part_of_speech_id=pos_id, owner_vocabulary=owner, | |
596 | + status=Lexeme.STATUS_CANDIDATE, responsible=request.user, deleted=True) | |
604 | 597 | owner.add_lexeme(l) |
605 | 598 | return {'id': l.id} |
606 | 599 | |
... | ... | @@ -614,17 +607,14 @@ def clone_lexeme(request, lexeme_id): |
614 | 607 | owner = request.user.usersettings.get_default_owner() |
615 | 608 | if not owner: |
616 | 609 | raise AjaxError(_(u'Empty owner dictionary')) |
617 | - next_id = Lexeme.all_objects.filter( | |
618 | - pk__gte=START_ID).aggregate(Max('id'))['id__max'] | |
619 | - next_id = next_id + 1 if next_id else START_ID | |
620 | - comment = u'Leksem sklonowany %s – z %s' % (format_date(timezone.now()), lexeme.entry) | |
610 | + comment = u'Leksem sklonowany %s – z %s' % ( | |
611 | + format_date(timezone.now()), lexeme.entry) | |
621 | 612 | new_lexeme = Lexeme.objects.create( |
622 | - id=next_id, part_of_speech_id=lexeme.part_of_speech_id, | |
623 | - entry=lexeme.entry, pronunciation=lexeme.pronunciation, | |
624 | - valence=lexeme.valence, source=lexeme.source, | |
625 | - borrowing_source_id=lexeme.borrowing_source_id, note=lexeme.note, | |
626 | - extended_note=lexeme.extended_note, specialist=lexeme.specialist, | |
627 | - status=lexeme.status, comment=comment, | |
613 | + part_of_speech_id=lexeme.part_of_speech_id, entry=lexeme.entry, | |
614 | + pronunciation=lexeme.pronunciation, valence=lexeme.valence, | |
615 | + source=lexeme.source, borrowing_source_id=lexeme.borrowing_source_id, | |
616 | + note=lexeme.note, extended_note=lexeme.extended_note, | |
617 | + specialist=lexeme.specialist, status=lexeme.status, comment=comment, | |
628 | 618 | owner_vocabulary_id=owner, responsible=request.user) |
629 | 619 | owner.add_lexeme(new_lexeme) |
630 | 620 | new_lexeme.fix_homonym_number() # nie zadziałał :/ |
... | ... |
dictionary/auto_derivatives.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | -from django.db.models import Max | |
3 | 2 | from dictionary.models import Lexeme, Inflection, Gender, LexemeAttribute, \ |
4 | 3 | LexemeAttributeValue, REVERSE_CR_TYPE |
5 | 4 | from patterns.models import Pattern, Ending |
... | ... | @@ -153,10 +152,9 @@ def lexeme_derivatives(lexeme): |
153 | 152 | |
154 | 153 | def create_derivative(lexeme, part_of_speech, cr_type, entry, index, pl=None): |
155 | 154 | negation = cr_type.endswith('nie') |
156 | - next_id = Lexeme.all_objects.aggregate(Max('id'))['id__max'] + 1 | |
157 | 155 | der = Lexeme.objects.create( |
158 | - id=next_id, entry=entry, part_of_speech_id=part_of_speech, | |
159 | - status=lexeme.status, owner_vocabulary_id=lexeme.owner_vocabulary_id, | |
156 | + entry=entry, part_of_speech_id=part_of_speech, status=lexeme.status, | |
157 | + owner_vocabulary_id=lexeme.owner_vocabulary_id, | |
160 | 158 | specialist=lexeme.specialist, |
161 | 159 | borrowing_source_id=lexeme.borrowing_source_id) |
162 | 160 | der.fix_homonym_number() |
... | ... |
dictionary/management/commands/import_skr.py
... | ... | @@ -2,7 +2,6 @@ |
2 | 2 | |
3 | 3 | from django.db import connection |
4 | 4 | from django.core.management.base import BaseCommand |
5 | -from django.db.models import Max | |
6 | 5 | from django.db.transaction import atomic |
7 | 6 | |
8 | 7 | from common.util import no_history, get_cursor |
... | ... | @@ -54,7 +53,6 @@ def import_skr(db_name): |
54 | 53 | name=attr_name, closed=closed) |
55 | 54 | la.parts_of_speech = ('skrl', 'skrw', 'skrf') |
56 | 55 | attrs[attr_name] = la |
57 | - next_id = Lexeme.objects.aggregate(Max('id'))['id__max'] + 1 | |
58 | 56 | |
59 | 57 | for row in sqlite_cursor.execute('SELECT * FROM skroty'): |
60 | 58 | entry = row['leksem'] |
... | ... | @@ -75,9 +73,8 @@ def import_skr(db_name): |
75 | 73 | comment = row['motywacja'] |
76 | 74 | l = Lexeme.objects.create( |
77 | 75 | entry=entry, part_of_speech_id=pos, valence=valence, source=source, |
78 | - comment=comment, owner_vocabulary=vocab, status=status, id=next_id, | |
76 | + comment=comment, owner_vocabulary=vocab, status=status, | |
79 | 77 | source_id=row['Identyfikator']) |
80 | - next_id += 1 | |
81 | 78 | vocab.add_lexeme(l) |
82 | 79 | Inflection.objects.create( |
83 | 80 | lexeme=l, pattern=pattern, index=1, root=entry) |
... | ... |
dictionary/management/commands/import_witek.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | import sys |
3 | 3 | from django.core.management.base import BaseCommand |
4 | -from django.db.models import Max | |
5 | 4 | from django.db.transaction import atomic |
6 | 5 | |
7 | 6 | from common.util import uniopen, no_history |
... | ... | @@ -34,19 +33,10 @@ def import_lexemes(lines, comment): |
34 | 33 | import_adj(elements, comment) |
35 | 34 | |
36 | 35 | |
37 | -next_id = None | |
38 | - | |
39 | - | |
40 | 36 | def new_lexeme(entry, pos, comment): |
41 | - global next_id | |
42 | - if next_id: | |
43 | - next_id += 1 | |
44 | - else: | |
45 | - next_id = Lexeme.all_objects.aggregate(Max('id'))['id__max'] + 1 | |
46 | 37 | l = Lexeme( |
47 | - id=next_id, entry=entry, part_of_speech_id=pos, | |
48 | - status=Lexeme.STATUS_DESCRIBED, owner_vocabulary_id=WSJP, | |
49 | - comment=comment) | |
38 | + entry=entry, part_of_speech_id=pos, status=Lexeme.STATUS_DESCRIBED, | |
39 | + owner_vocabulary_id=WSJP, comment=comment) | |
50 | 40 | l.save() |
51 | 41 | WSJP.add_lexeme(l) |
52 | 42 | return l |
... | ... | @@ -145,4 +135,4 @@ def import_adj(elements, comment): |
145 | 135 | pattern = Pattern.objects.get(name=pattern_name) |
146 | 136 | inflection = Inflection(lexeme=l, index=1, pattern=pattern) |
147 | 137 | inflection.root = inflection.get_root() |
148 | - inflection.save() | |
149 | 138 | \ No newline at end of file |
139 | + inflection.save() | |
... | ... |
dictionary/migrations/0021_auto_20160115_1328.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | +from __future__ import unicode_literals | |
3 | + | |
4 | +from django.db import migrations, models | |
5 | + | |
6 | + | |
7 | +class Migration(migrations.Migration): | |
8 | + | |
9 | + dependencies = [ | |
10 | + ('dictionary', '0020_auto_20151223_1151'), | |
11 | + ] | |
12 | + | |
13 | + operations = [ | |
14 | + migrations.RunSQL( | |
15 | + "SELECT setval('leksemy_id_seq', " | |
16 | + "COALESCE((SELECT MAX(id)+1 FROM leksemy), 1), false);"), | |
17 | + ] | |
... | ... |