views.py
2.38 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from collections import defaultdict
from django.shortcuts import render
from django.utils.translation import gettext as _
from phrase_expansions.models import PhraseExpansionType, PhraseExpansion
def EXPANSION_OPINION():
return {
'col' : _('potoczne'),
'dat' : _('archaiczne'),
'unc' : _('wątpliwe'),
'cer' : _('pewne'),
}
def phrase_expansions(request):
expansions = defaultdict(list)
expansions = [
{
'phrase_type' : phrase_type,
'title' : '{} – {}'.format(phrase_type, title),
'max_positions' : max(exp_type.max_positions for exp_type in PhraseExpansionType.objects.filter(phrase_type=phrase_type)),
'phrase_subtypes' : [
{
'phrase_subtype' : exp_type.phrase_subtype,
'title' : '{}({})'.format(phrase_type, exp_type.phrase_subtype),
'max_positions' : exp_type.max_positions,
'expansions' : [
{
'opinion_str' : EXPANSION_OPINION()[exp.opinion.key],
'opinion_sym' : exp.opinion.key,
'num_positions' : len(exp.positions.all()),
'positions' : [
{
'phrases' : [
{
'str' : phr.text_rep,
'desc' : phr.descriptions.get(lang=request.LANGUAGE_CODE).description,
} for phr in pos.phrases.all()
]
} for pos in exp.positions.all()
],
} for exp in exp_type.expansions.all()
],
} for exp_type in PhraseExpansionType.objects.filter(phrase_type=phrase_type)
],
} for phrase_type, title in (
('advp', _('frazy przysłówkowe')),
('xp', _('frazy okolicznikowe')),
('comprepnp', _('frazy przyimkowe z przyimkiem złożonym')),
('distrp', _('fraza dystrybutywna')),
('possp', _('fraza posesywna')),
)
]
return render(request, 'phrase_expansions.html', { 'expansions' : expansions })