create_forms.py
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#-*- coding:utf-8 -*-
import sys
from django.db import connection, transaction
from django.core.management.base import BaseCommand, CommandError
from common.util import debug
from dictionary.models import Lexeme
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()