Commit f6e452c59326be6544fd3691a801ba3a535e3291
1 parent
d317815e
rozdzielone zmienne sesyjne redaktora/użytkowniczki + kolumny przekazywane bezpośrednio
Showing
10 changed files
with
45 additions
and
42 deletions
dictionary/ajax_lexeme_slickgrid.py
... | ... | @@ -381,12 +381,14 @@ def search_index(request, query_params, search=''): |
381 | 381 | |
382 | 382 | |
383 | 383 | @ajax(login_required=False, method='get') |
384 | -def get_lexemes(request, from_page, to_page, rows, query_params, | |
384 | +def get_lexemes(request, from_page, to_page, rows, query_params, columns, | |
385 | 385 | force_reload=False): |
386 | 386 | check_query_params(request, query_params) |
387 | - request.session['sort_rules'] = query_params['sort_rules'] | |
388 | - request.session['filter'] = query_params['filter'] | |
389 | - columns = request.session.get('columns') | |
387 | + reader = query_params['reader'] | |
388 | + session_prefix = 'reader_' if reader else '' | |
389 | + request.session[session_prefix + 'sort_rules'] = query_params['sort_rules'] | |
390 | + request.session[session_prefix + 'filter'] = query_params['filter'] | |
391 | + request.session[session_prefix + 'columns'] = columns | |
390 | 392 | query = LexemeQuery(query_params, columns=columns) |
391 | 393 | start, response_rowcount = query.count_pages(from_page, to_page, rows) |
392 | 394 | if query.lexeme_list: |
... | ... |
dictionary/ajax_lexeme_view.py
... | ... | @@ -730,9 +730,3 @@ def execute_group_actions(request, actions, filter): |
730 | 730 | def get_entry(request, lexeme_id): |
731 | 731 | lexeme = get_object_or_404(Lexeme, id=lexeme_id) |
732 | 732 | return {'entry': lexeme.entry} |
733 | - | |
734 | - | |
735 | -@ajax(method='post') | |
736 | -def save_columns(request, columns): | |
737 | - request.session['columns'] = columns | |
738 | - return {} | |
... | ... |
dictionary/static/js/remotemodel.js
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | var ajax_request = null; |
12 | 12 | var sort_rules = null; |
13 | 13 | var filter = {group_op: "AND", rules: []}; |
14 | + var columns = null; | |
14 | 15 | var force_reload = false; |
15 | 16 | |
16 | 17 | // events |
... | ... | @@ -94,7 +95,8 @@ |
94 | 95 | from_page: fromPage, |
95 | 96 | to_page: toPage, |
96 | 97 | force_reload: force_reload, |
97 | - query_params: slickgrid.query_params() | |
98 | + query_params: slickgrid.query_params(), | |
99 | + columns: getColumns() | |
98 | 100 | }; |
99 | 101 | force_reload = false; |
100 | 102 | |
... | ... | @@ -161,6 +163,14 @@ |
161 | 163 | return filter; |
162 | 164 | } |
163 | 165 | |
166 | + function setColumns(new_columns) { | |
167 | + columns = new_columns; | |
168 | + } | |
169 | + | |
170 | + function getColumns() { | |
171 | + return columns; | |
172 | + } | |
173 | + | |
164 | 174 | function searchRow(search_text, callback) { |
165 | 175 | var data = { |
166 | 176 | search: search_text, |
... | ... | @@ -192,6 +202,8 @@ |
192 | 202 | "setSearch": setSearch, |
193 | 203 | "setFilter": setFilter, |
194 | 204 | "getFilter": getFilter, |
205 | + "setColumns": setColumns, | |
206 | + "getColumns": getColumns, | |
195 | 207 | "searchRow": searchRow, |
196 | 208 | |
197 | 209 | // events |
... | ... |
dictionary/static/js/slickgrid.js
... | ... | @@ -133,14 +133,8 @@ function set_columns() { |
133 | 133 | slickgrid.update_sort_button(slickgrid.loader.getSort()); |
134 | 134 | } |
135 | 135 | slickgrid.grid.autosizeColumns(); |
136 | - $.ajaxJSON({ | |
137 | - method: 'post', | |
138 | - url: $dj.ajax_save_columns, | |
139 | - data: {columns: chosen_column_ids}, | |
140 | - callback: function() { | |
141 | - slickgrid.reload_data(); | |
142 | - } | |
143 | - }); | |
136 | + slickgrid.loader.setColumns(chosen_column_ids); | |
137 | + slickgrid.reload_data(); | |
144 | 138 | } |
145 | 139 | |
146 | 140 | function columns_from_ids(column_ids) { |
... | ... | @@ -327,6 +321,7 @@ $(function() { |
327 | 321 | slickgrid.grid = new Slick.Grid( |
328 | 322 | slickgrid.element, slickgrid.loader.data, columns_from_ids(columns), |
329 | 323 | options); |
324 | + slickgrid.loader.setColumns(columns); | |
330 | 325 | |
331 | 326 | slickgrid.grid.onViewportChanged.subscribe(function () { |
332 | 327 | slickgrid.ensure_data(); |
... | ... |
dictionary/urls.py
... | ... | @@ -27,7 +27,6 @@ urlpatterns += patterns( |
27 | 27 | url(r'^ajax/update-lexeme/$', 'update_lexeme'), |
28 | 28 | url(r'^ajax/table-preview/$', 'table_preview'), |
29 | 29 | url(r'^ajax/new-lip-row/$', 'new_lip_edit_row'), |
30 | - url(r'^ajax/save-columns/$', 'save_columns'), | |
31 | 30 | url(r'^ajax/new-cr-row/$', 'new_cross_reference_row'), |
32 | 31 | url(r'^ajax/delete-lexeme/$', 'delete_lexeme'), |
33 | 32 | url(r'^ajax/check-pos/$', 'check_pos'), |
... | ... |
dictionary/views.py
... | ... | @@ -32,7 +32,7 @@ def main(request): |
32 | 32 | return HttpResponseRedirect(reverse('auth_login')) # niezbyt prawdopodobne |
33 | 33 | |
34 | 34 | |
35 | -def common_lexeme_js_vars(request, visible): | |
35 | +def common_lexeme_js_vars(request, visible, reader=False): | |
36 | 36 | qualifier_options = [] |
37 | 37 | lexeme_qualifier_options = [] |
38 | 38 | form_qualifier_options = [] |
... | ... | @@ -76,7 +76,6 @@ def common_lexeme_js_vars(request, visible): |
76 | 76 | 'ajax_search_index': reverse('search_index'), |
77 | 77 | 'ajax_search_by_form': reverse('search_by_form'), |
78 | 78 | 'ajax_row_index': reverse('row_index'), |
79 | - 'ajax_save_columns': reverse('save_columns'), | |
80 | 79 | 'ajax_export_list': reverse('export_list'), |
81 | 80 | 'ajax_get_entry': reverse('get_entry'), |
82 | 81 | 'lexeme_qualifier_options': lexeme_qualifier_options, |
... | ... | @@ -99,7 +98,11 @@ def common_lexeme_js_vars(request, visible): |
99 | 98 | 'commonness': Classification.objects.get(name=u'pospolitość').pk, |
100 | 99 | 'initial_columns': LexemeQuery.default_columns, |
101 | 100 | } |
102 | - session_variables = ('filter', 'sort_rules', 'columns') | |
101 | + session_prefix = 'reader_' if reader else '' | |
102 | + session_variables = ( | |
103 | + session_prefix + 'filter', | |
104 | + session_prefix + 'sort_rules', | |
105 | + session_prefix + 'columns') | |
103 | 106 | js_vars.update(dict( |
104 | 107 | (var, request.session[var]) |
105 | 108 | for var in session_variables if var in request.session)) |
... | ... | @@ -165,7 +168,7 @@ def lexeme_view(request): |
165 | 168 | @render('reader_view.html') |
166 | 169 | def reader_view(request): |
167 | 170 | visible = visible_vocabularies(AnonymousUser()) |
168 | - js_vars = common_lexeme_js_vars(request, visible) | |
171 | + js_vars = common_lexeme_js_vars(request, visible, reader=True) | |
169 | 172 | js_vars.update({ |
170 | 173 | 'reader': True, |
171 | 174 | 'vocabs': {}, |
... | ... |
patterns/ajax_pattern_view.py
... | ... | @@ -54,10 +54,12 @@ def search_index(request, query_params, search=''): |
54 | 54 | |
55 | 55 | |
56 | 56 | @ajax(login_required=False, method='get') |
57 | -def get_patterns(request, from_page, to_page, rows, query_params): | |
58 | - request.session['pattern-sort_rules'] = query_params['sort_rules'] | |
59 | - request.session['pattern-filter'] = query_params['filter'] | |
60 | - columns = request.session.get('pattern-columns') | |
57 | +def get_patterns(request, from_page, to_page, rows, query_params, columns): | |
58 | + session_prefix = 'reader_' if query_params['reader'] else '' | |
59 | + request.session[session_prefix + 'pattern-sort_rules'] = \ | |
60 | + query_params['sort_rules'] | |
61 | + request.session[session_prefix + 'pattern-filter'] = query_params['filter'] | |
62 | + request.session[session_prefix + 'pattern-columns'] = columns | |
61 | 63 | query = PatternQuery(query_params, columns=columns) |
62 | 64 | rows, count = query.get_page(from_page, to_page, rows) |
63 | 65 | return { |
... | ... | @@ -187,12 +189,6 @@ def update_pattern(request, form_data): |
187 | 189 | return {} |
188 | 190 | |
189 | 191 | |
190 | -@ajax(method='post') | |
191 | -def save_columns(request, columns): | |
192 | - request.session['pattern-columns'] = columns | |
193 | - return {} | |
194 | - | |
195 | - | |
196 | 192 | @ajax(method='post', permission_required='dictionary.change_pattern') |
197 | 193 | def create_pattern(request): |
198 | 194 | new_name = u'nowy wzór %s' |
... | ... |
patterns/static/js/pattern-view.js
... | ... | @@ -56,7 +56,8 @@ $.extend(slickgrid, { |
56 | 56 | "use strict"; |
57 | 57 | return { |
58 | 58 | sort_rules: slickgrid.loader.getSort(), |
59 | - filter: slickgrid.loader.getFilter() | |
59 | + filter: slickgrid.loader.getFilter(), | |
60 | + reader: $dj.reader | |
60 | 61 | }; |
61 | 62 | } |
62 | 63 | }); |
63 | 64 | \ No newline at end of file |
... | ... |
patterns/urls.py
... | ... | @@ -14,7 +14,6 @@ urlpatterns += patterns( |
14 | 14 | url(r'^ajax/query/$', 'get_patterns'), |
15 | 15 | url(r'^ajax/search-index/$', 'search_index', name='patterns_search_index'), |
16 | 16 | url(r'^ajax/row-index/$', 'row_index', name='patterns_row_index'), |
17 | - url(r'^ajax/save-columns/$', 'save_columns', name='patterns_save_columns'), | |
18 | 17 | url(r'^ajax/pattern-edit-form/$', 'pattern_edit_form'), |
19 | 18 | url(r'^ajax/new-ending-row/$', 'new_ending_row'), |
20 | 19 | url(r'^ajax/new-bfl-row/$', 'new_ending_table_row'), |
... | ... |
patterns/views.py
... | ... | @@ -7,7 +7,7 @@ from dictionary.models import LexicalClass, editable_vocabularies, \ |
7 | 7 | from patterns.ajax_pattern_view import PatternQuery |
8 | 8 | |
9 | 9 | |
10 | -def common_pattern_js_vars(request): | |
10 | +def common_pattern_js_vars(request, reader=False): | |
11 | 11 | lexical_class_options = [ |
12 | 12 | (lc.symbol, lc.symbol) for lc in LexicalClass.objects.all()] |
13 | 13 | base_form_labels = dict( |
... | ... | @@ -18,7 +18,6 @@ def common_pattern_js_vars(request): |
18 | 18 | 'ajax_get_page': reverse('get_patterns'), |
19 | 19 | 'ajax_search_index': reverse('patterns_search_index'), |
20 | 20 | 'ajax_row_index': reverse('patterns_row_index'), |
21 | - 'ajax_save_columns': reverse('patterns_save_columns'), | |
22 | 21 | 'ajax_pattern_preview': reverse('pattern_preview'), |
23 | 22 | 'ajax_get_name': reverse('get_name'), |
24 | 23 | 'lexical_class_options': lexical_class_options, |
... | ... | @@ -27,10 +26,11 @@ def common_pattern_js_vars(request): |
27 | 26 | 'bfl_symbols': bfl_symbols, |
28 | 27 | 'initial_columns': PatternQuery.default_columns, |
29 | 28 | } |
29 | + session_prefix = 'reader_' if reader else '' | |
30 | 30 | session_variables = ( |
31 | - 'pattern-filter', | |
32 | - 'pattern-sort_rules', | |
33 | - 'pattern-columns', | |
31 | + session_prefix + 'pattern-filter', | |
32 | + session_prefix + 'pattern-sort_rules', | |
33 | + session_prefix + 'pattern-columns', | |
34 | 34 | ) |
35 | 35 | js_vars.update(dict( |
36 | 36 | (var.split('-', 1)[1], request.session[var]) |
... | ... | @@ -47,6 +47,7 @@ def pattern_view(request): |
47 | 47 | vocabs.update(dict((str(q.pk), v.id) for q in v.qualifiers.all())) |
48 | 48 | js_vars = common_pattern_js_vars(request) |
49 | 49 | js_vars.update({ |
50 | + 'reader': False, | |
50 | 51 | 'ajax_edit_form': reverse('pattern_edit_form'), |
51 | 52 | 'ajax_update_pattern': reverse('update_pattern'), |
52 | 53 | 'ajax_new_ending_row': reverse('new_ending_row'), |
... | ... | @@ -63,8 +64,9 @@ def pattern_view(request): |
63 | 64 | |
64 | 65 | @render('pattern_reader_view.html') |
65 | 66 | def pattern_reader_view(request): |
66 | - js_vars = common_pattern_js_vars(request) | |
67 | + js_vars = common_pattern_js_vars(request, reader=True) | |
67 | 68 | js_vars.update({ |
69 | + 'reader': True, | |
68 | 70 | 'auto_search': True, |
69 | 71 | 'vocabs': {}, |
70 | 72 | }) |
... | ... |