views.py
1.93 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
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import permission_required
from django.core.urlresolvers import reverse
from common.decorators import render
from dictionary.models import LexicalClass, editable_vocabularies, \
get_exclusion_classes, PatternType
from patterns.ajax_pattern_view import PatternQuery
@permission_required('dictionary.view_pattern')
@render()
def pattern_view(request):
lexical_class_options = [
(lc.symbol, lc.symbol) for lc in LexicalClass.objects.all()]
editable_vocabs = editable_vocabularies(request.user)
vocabs = {}
for v in editable_vocabs:
vocabs.update(dict((str(q.pk), v.id) for q in v.qualifiers.all()))
js_vars = {
'ajax_get_page': reverse('get_patterns'),
'ajax_edit_form': reverse('pattern_edit_form'),
'ajax_update_pattern': reverse('update_pattern'),
'ajax_search_index': reverse('patterns_search_index'),
'ajax_row_index': reverse('patterns_row_index'),
'ajax_save_columns': reverse('patterns_save_columns'),
'ajax_new_ending_row': reverse('new_ending_row'),
'ajax_create_pattern': reverse('create_pattern'),
'ajax_clone_pattern': reverse('clone_pattern'),
'ajax_pattern_preview': reverse('pattern_preview'),
'ajax_history_table': reverse('pattern_table'),
'exclusion_classes': get_exclusion_classes(),
'auto_search': request.user.usersettings.incremental_search,
'lexical_class_options': lexical_class_options,
'pattern_type_options': PatternType.options(),
'vocabs': vocabs,
'initial_columns': PatternQuery.default_columns,
}
session_variables = (
'pattern-filter',
'pattern-sort_rules',
'pattern-columns',
)
for var in session_variables:
if var in request.session:
js_name = var.split('-', 1)[1]
js_vars[js_name] = request.session[var]
return {'js_vars': js_vars}