Commit 7c545d6aba6adaaeaf9dbe3ce4b500353c5e1a57
1 parent
5bc7c8f5
ukrywanie numeru homonimu, jeśli nie ma homonimów
Showing
2 changed files
with
10 additions
and
4 deletions
dictionary/ajax_lexeme_view.py
... | ... | @@ -165,7 +165,8 @@ def lexeme_edit_form(request, id): |
165 | 165 | lip.qualifiers.filter(vocabulary=owner) if ro_owner else []) |
166 | 166 | for lip in lips] |
167 | 167 | to_return['cross_references'] = l.cross_references(request.user) |
168 | - to_return['homonym'] = l.homonym_number | |
168 | + if l.homonym_count(request.user) > 0: | |
169 | + to_return['homonym'] = l.homonym_number | |
169 | 170 | return to_return |
170 | 171 | |
171 | 172 | |
... | ... | @@ -542,9 +543,9 @@ def clone_lexeme(request, lexeme_id): |
542 | 543 | |
543 | 544 | @ajax(method='get', login_required=True) |
544 | 545 | def homonym_count(request, entry, lexeme_id): |
545 | - lexemes = Lexeme.objects.filter(entry=entry).exclude(pk=lexeme_id) | |
546 | - lexemes = filter_visible(lexemes, request.user) | |
547 | - return {'count': lexemes.count()} | |
546 | + lexeme = Lexeme.all_objects.get(id=lexeme_id) | |
547 | + lexeme.entry = entry | |
548 | + return {'count': lexeme.homonym_count(request.user)} | |
548 | 549 | |
549 | 550 | |
550 | 551 | @ajax(method='get', login_required=True) |
... | ... |
dictionary/models.py
... | ... | @@ -638,6 +638,11 @@ class Lexeme(Model): |
638 | 638 | else: |
639 | 639 | return None |
640 | 640 | |
641 | + def homonym_count(self, user): | |
642 | + lexemes = Lexeme.objects.filter(entry=self.entry).exclude(pk=self.pk) | |
643 | + lexemes = filter_visible(lexemes, user) | |
644 | + return lexemes.count() | |
645 | + | |
641 | 646 | def attributes(self, part_of_speech=None, genders=None): |
642 | 647 | pos = part_of_speech or self.part_of_speech |
643 | 648 | if genders is None and pos.lexical_class_id == 'subst': |
... | ... |