Skip to content

Commit

Permalink
Only fetch from the db if we need to
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed Jul 9, 2012
1 parent 903b341 commit e636630
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions dictionary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,17 @@ def confirm(request, grade):

# create a default for all unconfirmed homographs which have no default, i.e. no restriction word entry
unconfirmed_homographs = set(LocalWord.objects.filter(grade=grade, type=5, isConfirmed=False).values_list('untranslated', flat=True))
covered_entries = set(chain(
LocalWord.objects.filter(grade=grade, type=0, untranslated__in=unconfirmed_homographs).values_list('untranslated', flat=True),
GlobalWord.objects.filter(grade=grade, type=0, untranslated__in=unconfirmed_homographs).values_list('untranslated', flat=True)))

for word in unconfirmed_homographs - covered_entries:
document = Document.objects.filter(localword__grade=grade, localword__type=5, localword__isConfirmed=False, localword__untranslated=word)[0]
w = LocalWord(untranslated=word,
braille=louis.translateString(getTables(grade), word),
grade=grade, type=0, document=document)
w.save()
if unconfirmed_homographs:
covered_entries = set(chain(
LocalWord.objects.filter(grade=grade, type=0, untranslated__in=unconfirmed_homographs).values_list('untranslated', flat=True),
GlobalWord.objects.filter(grade=grade, type=0, untranslated__in=unconfirmed_homographs).values_list('untranslated', flat=True)))

for word in unconfirmed_homographs - covered_entries:
document = Document.objects.filter(localword__grade=grade, localword__type=5, localword__isConfirmed=False, localword__untranslated=word)[0]
w = LocalWord(untranslated=word,
braille=louis.translateString(getTables(grade), word),
grade=grade, type=0, document=document)
w.save()

words_to_confirm = LocalWord.objects.filter(grade=grade,isConfirmed=False).order_by('untranslated', 'type').values('untranslated', 'braille', 'type', 'homograph_disambiguation', 'isLocal').distinct()
paginator = Paginator(words_to_confirm, MAX_WORDS_PER_PAGE)
Expand Down

0 comments on commit e636630

Please sign in to comment.