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

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

class Command(BaseCommand):
  args = 'none'
  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.filter(deleted=False)
  for l in sgjp.owned_lexemes.filter(deleted=False):
    LexemeAssociation.objects.get_or_create(lexeme=l, vocabulary=pm)
  for l in existing.filter(owner_vocabulary__id='Morfologik'):
    if not existing.filter(entry=l.entry, owner_vocabulary__id='SGJP'):
      LexemeAssociation.objects.get_or_create(lexeme=l, vocabulary=pm)