prepare_lexeme_lists.py
1.13 KB
# -*- coding: utf-8 -*-
from django.contrib.auth.models import AnonymousUser
from django.core.management.base import BaseCommand
from django.db.transaction import atomic
from common.util import json_encode
from dictionary.ajax_lexeme_slickgrid import LexemeQuery
from dictionary.models import LexemeList, Vocabulary
class Command(BaseCommand):
help = "Prepare lexeme lists for the reader view."
filter = {"group_op": "AND", "rules": []}
vocabularies = sorted(
Vocabulary.visible_vocabularies(AnonymousUser()).values_list(
'id', flat=True))
@atomic
def handle(self, *args, **options):
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()