create_forms.py 1.19 KB
#-*- coding:utf-8 -*-

from django.db import connection, transaction
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    args = 'none'
    help = 'Creates forms for filtering'

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


def create_forms():
    cursor = connection.cursor()

    transaction.commit_unless_managed()
    transaction.enter_transaction_management()
    transaction.managed(True)

    cursor.execute('''delete from dictionary_lexemeform''')
    # ew. można odfiltrować te z wygenerowanymi?
    select_query = '''select l.id as lexeme_id, prefiks||rdzen||zak||sufiks as form
        from leksemy l
        join odmieniasie o on l.id = o.l_id
        join charfle ch on ch.id = o.charfl
        join wzory w on (o.w_id = w.id)
        join szablony_tabel s on (
                w.typ=s.wtyp
                and o.charfl=s.charfl)
        join klatki k on k.st_id = s.id
        join zakonczenia z on (o.w_id=z.w_id and k.efobaz=z.efobaz)
        where wariant='1' ''' # jaki wariant?
    cursor.execute('''insert into dictionary_lexemeform (lexeme_id, form)
        (%s)''' % select_query)

    transaction.commit()
    transaction.leave_transaction_management()