init_polimorf.py 696 Bytes
# -*- coding: utf-8 -*-

from django.core.management.base import BaseCommand
from common.util import no_history
from dictionary.models import Lexeme, Vocabulary


class Command(BaseCommand):
    help = 'Initiates PoliMorf'

    def handle(self, **options):
        init_polimorf()


def init_polimorf():
    no_history()
    pm, created = Vocabulary.objects.get_or_create(id='PoliMorf')
    sgjp = Vocabulary.objects.get(id='SGJP')
    existing = Lexeme.objects
    for l in sgjp.owned_lexemes.all():
        pm.add_lexeme(l)
    for l in existing.filter(owner_vocabulary__id='Morfologik'):
        if not existing.filter(entry=l.entry, owner_vocabulary__id='SGJP'):
            pm.add_lexeme(l)