prepare_lexeme_lists.py
1.24 KB
# -*- coding: utf-8 -*-
from django.contrib.auth.models import AnonymousUser
from django.core.management.base import BaseCommand
from django.db import transaction
from common.util import json_encode
from dictionary.ajax_lexeme_slickgrid import LexemeQuery
from dictionary.models import visible_vocabularies, LexemeList, LexemeIndex
class Command(BaseCommand):
help = "Prepare lexeme lists for the reader view."
filter = {"group_op": "AND", "rules": []}
vocabularies = sorted(
visible_vocabularies(AnonymousUser()).values_list('id', flat=True))
def handle(self, *args, **options):
transaction.enter_transaction_management()
for a_fronte in (True, False):
LexemeList.objects.get_or_create(
filter=json_encode(self.filter), a_fronte=a_fronte,
vocabularies=json_encode(self.vocabularies))
sort_rules = ['a_fronte' if a_fronte else 'a_tergo']
query = LexemeQuery({
'filter': self.filter,
'sort_rules': sort_rules,
'visible_vocabs': self.vocabularies,
'reader': True
})
query.reload_lexeme_list()
transaction.commit()
transaction.leave_transaction_management()