Commit 4e471eb01ef00f552376a251bfada57819e87755
merge z default
--HG-- branch : beta rename : dictionary/static/js/slickgrid.js => common/static/js/slickgrid.js
Showing
13 changed files
with
194 additions
and
145 deletions
common/static/js/slickgrid.js
... | ... | @@ -89,6 +89,30 @@ var slickgrid = { |
89 | 89 | slickgrid.search(); |
90 | 90 | }, |
91 | 91 | |
92 | + row_index: function(id) { | |
93 | + "use strict"; | |
94 | + $.ajaxJSON({ | |
95 | + url: $dj.ajax_row_index, | |
96 | + method: 'get', | |
97 | + data: { | |
98 | + id: id, | |
99 | + query_params: slickgrid.query_params() | |
100 | + }, | |
101 | + callback: function(data) { | |
102 | + var index = data.index; | |
103 | + if (index === null) { | |
104 | + slickgrid.load_content(id); | |
105 | + slickgrid.last_active_row = undefined; | |
106 | + slickgrid.grid.resetActiveCell(); | |
107 | + } else { | |
108 | + slickgrid.set_active_when_loaded = index; | |
109 | + slickgrid.grid.scrollRowToCenter(index); | |
110 | + slickgrid.ensure_data(); | |
111 | + } | |
112 | + } | |
113 | + }); | |
114 | + }, | |
115 | + | |
92 | 116 | ensure_data: function() { |
93 | 117 | "use strict"; |
94 | 118 | var filter_button = $('#filter-button'); |
... | ... | @@ -626,8 +650,7 @@ $(function() { |
626 | 650 | function export_list(filename) { |
627 | 651 | "use strict"; |
628 | 652 | var param = { |
629 | - filter: JSON.stringify(slickgrid.loader.getFilter()), | |
630 | - sort_rules: JSON.stringify(slickgrid.loader.getSort()), | |
653 | + query_params: JSON.stringify(slickgrid.query_params()), | |
631 | 654 | columns: JSON.stringify($.map( |
632 | 655 | slickgrid.grid.getColumns(), function(col) {return col.field;})), |
633 | 656 | filename: filename |
... | ... |
dictionary/ajax_lexeme_slickgrid.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from hashlib import md5 |
3 | +import locale | |
3 | 4 | |
4 | 5 | from django.db.models import Count, Q |
5 | 6 | from django.core.cache import cache |
6 | 7 | from django.utils.encoding import force_unicode |
7 | 8 | |
8 | -from dictionary.models import Lexeme, LexemeAttribute, PartOfSpeech, LexemeList, \ | |
9 | - LexemeIndex | |
9 | +from dictionary.models import Lexeme, LexemeAttribute, PartOfSpeech, \ | |
10 | + LexemeList, LexemeIndex | |
10 | 11 | from dictionary.ajax_slickgrid import SlickGridQuery |
11 | 12 | from common.decorators import ajax |
12 | 13 | from common.util import bisect_left, reverse, json_encode |
14 | +from dictionary.util import check_query_params | |
13 | 15 | |
14 | -import locale | |
15 | 16 | locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8') |
16 | 17 | |
17 | 18 | ASPECT = LexemeAttribute.objects.get(name=u'aspekt') |
... | ... | @@ -43,8 +44,8 @@ class LexemeQuery(SlickGridQuery): |
43 | 44 | 'pos': lambda lexeme: lexeme.part_of_speech_id, |
44 | 45 | 'patterns': lambda lexeme: lexeme.lip_data()['patterns'], |
45 | 46 | 'genders': lambda lexeme: |
46 | - getattr(lexeme.attribute_value(ASPECT), 'value', '') | |
47 | - or lexeme.lip_data()['genders'], | |
47 | + getattr(lexeme.attribute_value(ASPECT), 'value', '') or | |
48 | + lexeme.lip_data()['genders'], | |
48 | 49 | 'vocabs': lambda lexeme: |
49 | 50 | '/'.join(lexeme.vocabularies.values_list('id', flat=True)), |
50 | 51 | 'owner': lambda lexeme: lexeme.owner_vocabulary_id, |
... | ... | @@ -73,9 +74,10 @@ class LexemeQuery(SlickGridQuery): |
73 | 74 | 'abbr_pos': 'part_of_speech__abbr_name', |
74 | 75 | } |
75 | 76 | |
76 | - def __init__(self, visible_vocabs, *args, **kwargs): | |
77 | - self.visible_vocabs = list(visible_vocabs) | |
77 | + def __init__(self, *args, **kwargs): | |
78 | 78 | super(LexemeQuery, self).__init__(*args, **kwargs) |
79 | + self.visible_vocabs = self.query_params['visible_vocabs'] | |
80 | + self.reader = self.query_params['reader'] | |
79 | 81 | self.lexeme_list = self.get_lexeme_list() |
80 | 82 | |
81 | 83 | def a_fronte(self): |
... | ... | @@ -144,9 +146,13 @@ class LexemeQuery(SlickGridQuery): |
144 | 146 | 'op': 'in', |
145 | 147 | 'data': tuple(matching_values), |
146 | 148 | } |
149 | + | |
147 | 150 | # optymalizacja warunków "różne od" |
148 | - ident = lambda x: x | |
149 | - int_list = lambda l: [int(i) for i in l] if l else [] | |
151 | + def ident(x): return x | |
152 | + | |
153 | + def int_list(l): | |
154 | + return [int(i) for i in l] if l else [] | |
155 | + | |
150 | 156 | indirect_fields = { |
151 | 157 | 'containing_vocabulary': ( |
152 | 158 | 'slownik', 'leksemy_w_slownikach', 'l_id', ident), |
... | ... | @@ -168,8 +174,8 @@ class LexemeQuery(SlickGridQuery): |
168 | 174 | int_list), |
169 | 175 | } |
170 | 176 | if lookup == '-in' and ( |
171 | - field in indirect_fields | |
172 | - or field.startswith('extra') and attr.closed): | |
177 | + field in indirect_fields or | |
178 | + field.startswith('extra') and attr.closed): | |
173 | 179 | key = 'extra' if field.startswith('extra') else field |
174 | 180 | field1, table, field2, f = indirect_fields[key] |
175 | 181 | for value in f(new_rule['data']): |
... | ... | @@ -200,6 +206,8 @@ class LexemeQuery(SlickGridQuery): |
200 | 206 | |
201 | 207 | def get_queryset(self): |
202 | 208 | lexemes = super(LexemeQuery, self).get_queryset() |
209 | + if self.reader: | |
210 | + lexemes = lexemes.exclude(status__in=Lexeme.HIDDEN_STATUSES) | |
203 | 211 | return lexemes.distinct().filter( |
204 | 212 | vocabularies__id__in=self.visible_vocabs) |
205 | 213 | |
... | ... | @@ -252,9 +260,7 @@ class LexemeQuery(SlickGridQuery): |
252 | 260 | return index |
253 | 261 | |
254 | 262 | def cache_key(self): |
255 | - key = json_encode( | |
256 | - (self.sort_rules, self.filter, self.visible_vocabs), | |
257 | - ensure_ascii=True) | |
263 | + key = json_encode(self.query_params, ensure_ascii=True) | |
258 | 264 | return md5(key.encode()).hexdigest() |
259 | 265 | |
260 | 266 | def get_cached_lexemes(self, refresh=True): |
... | ... | @@ -374,34 +380,33 @@ class LexemeQuery(SlickGridQuery): |
374 | 380 | fields = [ |
375 | 381 | column_translation.get(column, column) for column in columns] |
376 | 382 | for row in lexemes.values(*fields): |
377 | - print >>output_file, '\t'.join( | |
383 | + print >> output_file, '\t'.join( | |
378 | 384 | unicode(row[field]) for field in fields) |
379 | 385 | |
380 | 386 | |
381 | 387 | # Zapytanie o indeks wiersza o pewnym id przy danym sortowaniu |
382 | 388 | @ajax(login_required=False, method='get') |
383 | -def row_index(request, id, sort_rules, filter, visible_vocabs): | |
384 | - query = LexemeQuery( | |
385 | - filter=filter, sort_rules=sort_rules, visible_vocabs=visible_vocabs) | |
389 | +def row_index(request, id, query_params): | |
390 | + check_query_params(request, query_params) | |
391 | + query = LexemeQuery(query_params) | |
386 | 392 | return {'index': query.row_index(id)} |
387 | 393 | |
388 | 394 | |
389 | 395 | @ajax(login_required=False, method='get') |
390 | -def search_index(request, sort_rules, filter, visible_vocabs, search=''): | |
391 | - query = LexemeQuery( | |
392 | - filter=filter, sort_rules=sort_rules, visible_vocabs=visible_vocabs) | |
396 | +def search_index(request, query_params, search=''): | |
397 | + check_query_params(request, query_params) | |
398 | + query = LexemeQuery(query_params) | |
393 | 399 | return {'index': query.search_index(search)} |
394 | 400 | |
395 | 401 | |
396 | 402 | @ajax(login_required=False, method='get') |
397 | -def get_lexemes(request, from_page, to_page, rows, sort_rules, filter, | |
398 | - visible_vocabs, force_reload=False): | |
399 | - request.session['sort_rules'] = sort_rules | |
400 | - request.session['filter'] = filter | |
403 | +def get_lexemes(request, from_page, to_page, rows, query_params, | |
404 | + force_reload=False): | |
405 | + check_query_params(request, query_params) | |
406 | + request.session['sort_rules'] = query_params['sort_rules'] | |
407 | + request.session['filter'] = query_params['filter'] | |
401 | 408 | columns = request.session.get('columns') |
402 | - query = LexemeQuery( | |
403 | - filter=filter, sort_rules=sort_rules, visible_vocabs=visible_vocabs, | |
404 | - columns=columns) | |
409 | + query = LexemeQuery(query_params, columns=columns) | |
405 | 410 | start, response_rowcount = query.count_pages(from_page, to_page, rows) |
406 | 411 | if query.lexeme_list: |
407 | 412 | count = query.lexeme_list.lexemeindex_set.count() |
... | ... | @@ -412,7 +417,8 @@ def get_lexemes(request, from_page, to_page, rows, sort_rules, filter, |
412 | 417 | id_list = query.get_id_list(force_reload) |
413 | 418 | count = len(id_list) |
414 | 419 | sublist = id_list[start:start + response_rowcount] |
415 | - lexemes_qs = prefetch(Lexeme.all_objects.filter(id__in=sublist)) # brzydka łata | |
420 | + # brzydka łata | |
421 | + lexemes_qs = prefetch(Lexeme.all_objects.filter(id__in=sublist)) | |
416 | 422 | lexemes_dict = dict((l.id, l) for l in lexemes_qs) |
417 | 423 | lexemes = [lexemes_dict[lexeme_id] for lexeme_id in sublist] |
418 | 424 | return { |
... | ... | @@ -423,10 +429,9 @@ def get_lexemes(request, from_page, to_page, rows, sort_rules, filter, |
423 | 429 | |
424 | 430 | |
425 | 431 | @ajax(login_required=False, method='get') |
426 | -def search_by_form(request, sort_rules, filter, exponent, visible_vocabs): | |
427 | - query = LexemeQuery( | |
428 | - filter=filter, sort_rules=sort_rules, visible_vocabs=visible_vocabs, | |
429 | - columns=request.session.get('columns')) | |
432 | +def search_by_form(request, query_params, exponent): | |
433 | + check_query_params(request, query_params) | |
434 | + query = LexemeQuery(query_params, columns=request.session.get('columns')) | |
430 | 435 | lexemes = query.get_sorted_queryset().filter(lexemeform__form=exponent) |
431 | 436 | rows = [row for row in query.prepare_rows(lexemes)] |
432 | 437 | for row in rows: |
... | ... |
dictionary/ajax_lexeme_view.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | -from collections import defaultdict | |
3 | 2 | import datetime |
4 | 3 | |
5 | 4 | from django.core.cache import cache |
... | ... | @@ -261,10 +260,13 @@ def insert_new_lexeme(lexeme, request): |
261 | 260 | sort_rules = request.session.get('sort_rules') |
262 | 261 | if filter is None or sort_rules is None: |
263 | 262 | return |
264 | - query = LexemeQuery( | |
265 | - filter=filter, sort_rules=sort_rules, | |
266 | - visible_vocabs=visible_vocabularies(request.user).values_list( | |
267 | - 'id', flat=True)) | |
263 | + query = LexemeQuery({ | |
264 | + 'filter': filter, | |
265 | + 'sort_rules': sort_rules, | |
266 | + 'visible_vocabs': | |
267 | + visible_vocabularies(request.user).values_list('id', flat=True), | |
268 | + 'reader': False, | |
269 | + }) | |
268 | 270 | id_list = query.get_cached_lexemes() |
269 | 271 | if id_list is not None: |
270 | 272 | index = bisect_left(id_list, lexeme.entry, cmp=query.lexeme_cmp()) |
... | ... | @@ -333,8 +335,16 @@ def update_lexeme(request, form_data): |
333 | 335 | for prefix in form_dict['deleted']: |
334 | 336 | pk = int(prefix[3:]) |
335 | 337 | LexemeInflectionPattern.objects.get(pk=pk).delete() |
338 | + proposed_crs = {'delete': [], 'create': []} | |
336 | 339 | for cr_pk in form_dict['deleted_cr']: |
337 | - CrossReference.objects.get(pk=cr_pk).delete() | |
340 | + cr = CrossReference.objects.get(pk=cr_pk) | |
341 | + for rev_cr in cr.reversed(): | |
342 | + proposed_crs['delete'].append({ | |
343 | + 'cr_id': rev_cr.id, | |
344 | + 'entry': rev_cr.from_lexeme.entry, | |
345 | + 'type_desc': rev_cr.type.desc, | |
346 | + }) | |
347 | + cr.delete() | |
338 | 348 | submitted_lips = [] |
339 | 349 | submitted_crs = [] |
340 | 350 | for pair in form_data: |
... | ... | @@ -369,7 +379,17 @@ def update_lexeme(request, form_data): |
369 | 379 | submitted_crs.append(prefix) |
370 | 380 | cr_form = CrossReferenceForm(data=form_dict, prefix=prefix) |
371 | 381 | if cr_form.is_valid(): |
372 | - cr_form.save() | |
382 | + cr = cr_form.save() | |
383 | + if not cr.reversed(): | |
384 | + rev_type = cr.type.reversed() | |
385 | + if rev_type: | |
386 | + proposed_crs['create'].append({ | |
387 | + 'type_id': rev_type.id, | |
388 | + 'from_lexeme': cr.to_lexeme.id, | |
389 | + 'to_lexeme': cr.from_lexeme.id, | |
390 | + 'entry': cr.to_lexeme.entry, | |
391 | + 'type_desc': rev_type.desc, | |
392 | + }) | |
373 | 393 | else: |
374 | 394 | raise AjaxError(error_messages(cr_form)) |
375 | 395 | if len(submitted_lips) == 0 and l.is_public(): |
... | ... | @@ -431,7 +451,7 @@ def update_lexeme(request, form_data): |
431 | 451 | needed_derivatives = [ |
432 | 452 | d for d in computed_derivatives |
433 | 453 | if (d['entry'], d['cr_type']) not in cr_set] |
434 | - return {'derivatives': needed_derivatives} | |
454 | + return {'derivatives': needed_derivatives, 'proposed_crs': proposed_crs} | |
435 | 455 | |
436 | 456 | |
437 | 457 | @ajax(method='post') |
... | ... | @@ -649,10 +669,13 @@ def dynamic_action_fields(request, field_name): |
649 | 669 | |
650 | 670 | @ajax(method='post', permission_required='dictionary.change_lexeme') |
651 | 671 | def execute_group_actions(request, actions, filter): |
652 | - query = LexemeQuery( | |
653 | - filter=filter, sort_rules=[], | |
654 | - visible_vocabs=visible_vocabularies(request.user).values_list( | |
655 | - 'id', flat=True)) | |
672 | + query = LexemeQuery({ | |
673 | + 'filter': filter, | |
674 | + 'sort_rules': [], | |
675 | + 'visible_vocabs': | |
676 | + visible_vocabularies(request.user).values_list('id', flat=True), | |
677 | + 'reader': False | |
678 | + }) | |
656 | 679 | pk_list = query.get_id_list() |
657 | 680 | lexemes = Lexeme.objects.filter(pk__in=pk_list) |
658 | 681 | for l in lexemes: |
... | ... |
dictionary/ajax_slickgrid.py
... | ... | @@ -28,9 +28,10 @@ class SlickGridQuery(object): |
28 | 28 | '-isnull': '-isnull', |
29 | 29 | } |
30 | 30 | |
31 | - def __init__(self, filter, sort_rules, columns=None): | |
32 | - self.filter = filter | |
33 | - self.sort_rules = sort_rules | |
31 | + def __init__(self, query_params, columns=None): | |
32 | + self.query_params = query_params | |
33 | + self.filter = query_params['filter'] | |
34 | + self.sort_rules = query_params['sort_rules'] | |
34 | 35 | if columns: |
35 | 36 | self.columns = tuple(columns) |
36 | 37 | else: |
... | ... |
dictionary/auto_derivatives.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from django.db.models import Max |
3 | 3 | from dictionary.models import Ending, Lexeme, LexemeInflectionPattern, \ |
4 | - Pattern, Gender, LexemeAttributeValue, LexemeAttribute | |
4 | + Pattern, Gender, LexemeAttributeValue, LexemeAttribute, REVERSE_CR_TYPE | |
5 | 5 | |
6 | 6 | VOWELS = u'aeiouyąęó' |
7 | 7 | |
... | ... | @@ -26,20 +26,6 @@ NO_POPRZ = LexemeAttributeValue.objects.get( |
26 | 26 | NO_ZLOZ = LexemeAttributeValue.objects.get( |
27 | 27 | value=u'nieobecna', attribute__name=u'forma złoż.') |
28 | 28 | |
29 | -CR_TYPES = { | |
30 | - 'verpact': ('verpact', 'pactver'), | |
31 | - 'verppas': ('verppas', 'ppasver'), | |
32 | - # 'verappas': ('verppas', 'ppasver'), | |
33 | - 'verger': ('verger', 'gerver'), | |
34 | - 'adjosc': ('adjosc', 'oscadj'), | |
35 | - 'adjadv': ('adjadv', 'advadj'), | |
36 | - 'adjadvc': ('adjadvc', 'advcadj'), | |
37 | - 'adjcom': ('adjcom', 'comadj'), | |
38 | - 'adjnie': ('adjnie', 'nieadj'), | |
39 | - 'advnie': ('adjnie', 'nieadj'), | |
40 | - 'oscnie': ('adjnie', 'nieadj'), | |
41 | -} | |
42 | - | |
43 | 29 | |
44 | 30 | def ppas_data(lips, pos='ppas'): |
45 | 31 | for lip in lips: |
... | ... | @@ -229,13 +215,12 @@ def create_derivative(lexeme, part_of_speech, cr_type, entry, index, pl=None): |
229 | 215 | NO_ZLOZ.add_lexeme(der) |
230 | 216 | for q in lexeme.qualifiers.all(): |
231 | 217 | der.qualifiers.add(q) |
232 | - cr_to, cr_from = CR_TYPES[cr_type] | |
233 | - lexeme.add_cross_reference(der, cr_to) | |
234 | - der.add_cross_reference(lexeme, cr_from) | |
218 | + lexeme.add_cross_reference(der, cr_type) | |
219 | + der.add_cross_reference(lexeme, REVERSE_CR_TYPE[cr_type]) | |
235 | 220 | der.refresh_data() |
236 | 221 | new_lexemes = [der] |
237 | 222 | if cr_type in ('adjosc', 'adjadv'): |
238 | 223 | new_lexemes.extend(create_derivative( |
239 | - der, part_of_speech, part_of_speech + 'nie', make_negation(entry), | |
224 | + der, part_of_speech, 'adjnie', make_negation(entry), | |
240 | 225 | index)) |
241 | 226 | return new_lexemes |
... | ... |
dictionary/management/commands/prepare_lexeme_lists.py
... | ... | @@ -15,7 +15,6 @@ class Command(BaseCommand): |
15 | 15 | vocabularies = sorted( |
16 | 16 | visible_vocabularies(AnonymousUser()).values_list('id', flat=True)) |
17 | 17 | |
18 | - | |
19 | 18 | def handle(self, *args, **options): |
20 | 19 | transaction.enter_transaction_management() |
21 | 20 | for a_fronte in (True, False): |
... | ... | @@ -23,7 +22,12 @@ class Command(BaseCommand): |
23 | 22 | filter=json_encode(self.filter), a_fronte=a_fronte, |
24 | 23 | vocabularies=json_encode(self.vocabularies)) |
25 | 24 | sort_rules = ['a_fronte' if a_fronte else 'a_tergo'] |
26 | - query = LexemeQuery(self.vocabularies, self.filter, sort_rules) | |
25 | + query = LexemeQuery({ | |
26 | + 'filter': self.filter, | |
27 | + 'sort_rules': sort_rules, | |
28 | + 'visible_vocabs': self.vocabularies, | |
29 | + 'reader': True | |
30 | + }) | |
27 | 31 | query.reload_lexeme_list() |
28 | 32 | transaction.commit() |
29 | 33 | transaction.leave_transaction_management() |
30 | 34 | \ No newline at end of file |
... | ... |
dictionary/models.py
... | ... | @@ -1134,6 +1134,33 @@ class LexemeAssociation(Model): |
1134 | 1134 | unique_together = ['lexeme', 'vocabulary'] |
1135 | 1135 | |
1136 | 1136 | |
1137 | +# powinno być w tabeli, ale na razie nie chcemy zmieniać struktury | |
1138 | +REVERSE_CR_TYPE = { | |
1139 | + 'verpact': 'pactver', | |
1140 | + 'verppas': 'ppasver', | |
1141 | + 'verger': 'gerver', | |
1142 | + 'adjosc': 'oscadj', | |
1143 | + 'adjadv': 'advadj', | |
1144 | + 'adjadvc': 'advcadj', | |
1145 | + 'adjcom': 'comadj', | |
1146 | + 'adjnie': 'nieadj', | |
1147 | + | |
1148 | + 'advcom': 'comadv', | |
1149 | + 'masfem': 'femmas', | |
1150 | + 'veripp': 'ippver', | |
1151 | + 'warstd': 'warnstd', | |
1152 | + | |
1153 | + 'asp': 'asp', | |
1154 | + 'warleks': 'warleks', | |
1155 | + 'warpis': 'warpis', | |
1156 | + 'warrodz': 'warrodz', | |
1157 | + # zdrobod, zgrubod -- brak zwrotnych odsyłaczy | |
1158 | +} | |
1159 | + | |
1160 | +for cr_symbol, rev_symbol in list(REVERSE_CR_TYPE.iteritems()): | |
1161 | + REVERSE_CR_TYPE[rev_symbol] = cr_symbol | |
1162 | + | |
1163 | + | |
1137 | 1164 | class CrossReferenceType(Model): |
1138 | 1165 | symbol = CharField(max_length=10, db_column='typods') |
1139 | 1166 | desc = CharField(max_length=40, db_column='naglowek') |
... | ... | @@ -1147,6 +1174,13 @@ class CrossReferenceType(Model): |
1147 | 1174 | def __unicode__(self): |
1148 | 1175 | return self.symbol |
1149 | 1176 | |
1177 | + def reversed(self): | |
1178 | + if self.symbol not in REVERSE_CR_TYPE: | |
1179 | + return None | |
1180 | + rev_symbol = REVERSE_CR_TYPE[self.symbol] | |
1181 | + return CrossReferenceType.objects.get( | |
1182 | + symbol=rev_symbol, from_pos=self.to_pos, to_pos=self.from_pos) | |
1183 | + | |
1150 | 1184 | class Meta: |
1151 | 1185 | db_table = 'typyodsylaczy' |
1152 | 1186 | |
... | ... | @@ -1171,6 +1205,14 @@ class CrossReference(Model): |
1171 | 1205 | objects = CRManager() |
1172 | 1206 | all_objects = Manager() |
1173 | 1207 | |
1208 | + def reversed(self): | |
1209 | + rev_type = self.type.reversed() | |
1210 | + if rev_type: | |
1211 | + return self.to_lexeme.refs_to.filter( | |
1212 | + to_lexeme=self.from_lexeme, type=rev_type) | |
1213 | + else: | |
1214 | + return [] | |
1215 | + | |
1174 | 1216 | def __unicode__(self): |
1175 | 1217 | return '%s: %s -> %s' % ( |
1176 | 1218 | self.type.symbol, self.from_lexeme.entry, self.to_lexeme.entry) |
... | ... |
dictionary/static/js/lexeme-view.js
... | ... | @@ -128,8 +128,7 @@ $.each(column_data, function(key, data) { |
128 | 128 | |
129 | 129 | $.extend(slickgrid, { |
130 | 130 | loader: new Slick.Data.RemoteModel( |
131 | - $dj.ajax_get_page, $dj.ajax_search_index, | |
132 | - {visible_vocabs: visible_vocab_ids}), | |
131 | + $dj.ajax_get_page, $dj.ajax_search_index), | |
133 | 132 | grid_caption: gettext("Leksemy"), |
134 | 133 | counter: function(count) { |
135 | 134 | "use strict"; |
... | ... | @@ -281,30 +280,14 @@ $.extend(slickgrid, { |
281 | 280 | } |
282 | 281 | }, |
283 | 282 | |
284 | - row_index: function(id) { | |
283 | + query_params: function() { | |
285 | 284 | "use strict"; |
286 | - $.ajaxJSON({ | |
287 | - url: $dj.ajax_row_index, | |
288 | - method: 'get', | |
289 | - data: { | |
290 | - id: id, | |
291 | - sort_rules: slickgrid.loader.getSort(), | |
292 | - filter: slickgrid.loader.getFilter(), | |
293 | - visible_vocabs: visible_vocab_ids | |
294 | - }, | |
295 | - callback: function(data) { | |
296 | - var index = data.index; | |
297 | - if (index === null) { | |
298 | - slickgrid.load_content(id); | |
299 | - slickgrid.last_active_row = undefined; | |
300 | - slickgrid.grid.resetActiveCell(); | |
301 | - } else { | |
302 | - slickgrid.set_active_when_loaded = index; | |
303 | - slickgrid.grid.scrollRowToCenter(index); | |
304 | - slickgrid.ensure_data(); | |
305 | - } | |
306 | - } | |
307 | - }); | |
285 | + return { | |
286 | + sort_rules: slickgrid.loader.getSort(), | |
287 | + filter: slickgrid.loader.getFilter(), | |
288 | + visible_vocabs: visible_vocab_ids, | |
289 | + reader: $dj.reader | |
290 | + }; | |
308 | 291 | }, |
309 | 292 | |
310 | 293 | init_sort: function() { |
... | ... | @@ -358,10 +341,8 @@ $.extend(slickgrid, { |
358 | 341 | url: $dj.ajax_search_by_form, |
359 | 342 | method: 'get', |
360 | 343 | data: { |
361 | - filter: slickgrid.loader.getFilter(), | |
362 | - sort_rules: slickgrid.loader.getSort(), | |
363 | 344 | exponent: slickgrid.search_string(), |
364 | - visible_vocabs: visible_vocab_ids | |
345 | + query_params: slickgrid.query_params() | |
365 | 346 | }, |
366 | 347 | callback: function(data) { |
367 | 348 | var table = $('#by-form-container'); |
... | ... |
dictionary/static/js/remotemodel.js
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | (function ($) { |
4 | 4 | "use strict"; |
5 | - function RemoteModel(data_url, search_index_url, extra_data) { | |
5 | + function RemoteModel(data_url, search_index_url) { | |
6 | 6 | // private |
7 | 7 | var PAGESIZE = 50; |
8 | 8 | var data = {length: 0}; |
... | ... | @@ -93,11 +93,9 @@ |
93 | 93 | rows: PAGESIZE, |
94 | 94 | from_page: fromPage || 0, // nie wiem, skąd te nulle |
95 | 95 | to_page: toPage || 0, |
96 | - sort_rules: sort_rules, | |
97 | - filter: filter, | |
98 | - force_reload: force_reload | |
96 | + force_reload: force_reload, | |
97 | + query_params: slickgrid.query_params() | |
99 | 98 | }; |
100 | - $.extend(ajax_data, extra_data); | |
101 | 99 | force_reload = false; |
102 | 100 | |
103 | 101 | ajax_request = $.ajaxJSON({ |
... | ... | @@ -167,11 +165,9 @@ |
167 | 165 | var search_counter = slickgrid.search_counter; |
168 | 166 | var search_text = slickgrid.search_string(); |
169 | 167 | var data = { |
170 | - filter: filter, | |
171 | - sort_rules: sort_rules, | |
172 | - search: search_text | |
168 | + search: search_text, | |
169 | + query_params: slickgrid.query_params() | |
173 | 170 | }; |
174 | - $.extend(data, extra_data); | |
175 | 171 | $.ajaxJSON({ |
176 | 172 | url: search_index_url, |
177 | 173 | method: 'get', |
... | ... |
dictionary/util.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | +from common.decorators import AjaxError | |
2 | 3 | |
3 | 4 | from dictionary.models import BaseFormLabel |
4 | 5 | |
... | ... | @@ -51,3 +52,8 @@ def compare_patterns(patterns): |
51 | 52 | for bfl in differing_bfls]) |
52 | 53 | for pattern, root in patterns) |
53 | 54 | return diffs |
55 | + | |
56 | + | |
57 | +def check_query_params(request, query_params): | |
58 | + if not request.user.is_authenticated() and not query_params['reader']: | |
59 | + raise AjaxError('access denied') | |
... | ... |
dictionary/views.py
... | ... | @@ -14,6 +14,7 @@ from dictionary.models import visible_vocabularies, PartOfSpeech, Lexeme, \ |
14 | 14 | get_exclusion_classes, editable_vocabularies, \ |
15 | 15 | CrossReferenceType, PatternType, \ |
16 | 16 | LexemeAttribute, Gender, BorrowingSource |
17 | +from dictionary.util import check_query_params | |
17 | 18 | from dictionary.wsjp import make_data |
18 | 19 | |
19 | 20 | |
... | ... | @@ -124,6 +125,7 @@ def lexeme_view(request): |
124 | 125 | User.objects.order_by('username').values_list('id', 'username')) |
125 | 126 | js_vars = common_lexeme_js_vars(request, visible) |
126 | 127 | js_vars.update({ |
128 | + 'reader': False, | |
127 | 129 | 'ajax_history_table': reverse('history_table'), |
128 | 130 | 'ajax_odm_forms': reverse('odm_forms'), |
129 | 131 | 'ajax_edit_form': reverse('lexeme_edit_form'), |
... | ... | @@ -173,6 +175,7 @@ def reader_view(request): |
173 | 175 | ] |
174 | 176 | js_vars = common_lexeme_js_vars(request, visible) |
175 | 177 | js_vars.update({ |
178 | + 'reader': True, | |
176 | 179 | 'vocabs': {}, |
177 | 180 | 'user_options': [], |
178 | 181 | 'auto_search': True, |
... | ... | @@ -200,15 +203,12 @@ def reports(request): |
200 | 203 | |
201 | 204 | @permission_required('dictionary.view_lexeme') |
202 | 205 | def export_list(request): |
203 | - filter = json_decode(request.GET['filter']) | |
204 | - sort_rules = json_decode(request.GET['sort_rules']) | |
206 | + query_params = json_decode(request.GET['query_params']) | |
207 | + check_query_params(request, query_params) | |
205 | 208 | columns = json_decode(request.GET['columns']) |
206 | 209 | filename = request.GET.get('filename') or 'lista.txt' |
210 | + query = LexemeQuery(query_params) | |
207 | 211 | response = HttpResponse(content_type='text/plain') |
208 | - visible_vocabs = list(visible_vocabularies(request.user).values_list( | |
209 | - 'id', flat=True)) | |
210 | - query = LexemeQuery( | |
211 | - filter=filter, sort_rules=sort_rules, visible_vocabs=visible_vocabs) | |
212 | 212 | query.export_list(columns, response) |
213 | 213 | response['Content-Disposition'] = ('attachment; filename=%s' % filename) |
214 | 214 | return response |
... | ... |
patterns/ajax_pattern_view.py
... | ... | @@ -39,8 +39,8 @@ class PatternQuery(SlickGridQuery): |
39 | 39 | |
40 | 40 | # Zapytanie o indeks wiersza o pewnym id przy danym sortowaniu |
41 | 41 | @ajax(login_required=False, method='get') |
42 | -def row_index(request, id, sort_rules, filter): | |
43 | - query = PatternQuery(filter=filter, sort_rules=sort_rules) | |
42 | +def row_index(request, id, query_params): | |
43 | + query = PatternQuery(query_params) | |
44 | 44 | return {'index': query.row_index(id)} |
45 | 45 | |
46 | 46 | |
... | ... | @@ -48,17 +48,17 @@ def row_index(request, id, sort_rules, filter): |
48 | 48 | # pierwszego wiersza, którego hasło rozpoczyna się od search. |
49 | 49 | # 'selected_id' < 0, jeśli takiego nie ma |
50 | 50 | @ajax(login_required=False, method='get') |
51 | -def search_index(request, sort_rules, filter, search=''): | |
52 | - query = PatternQuery(filter=filter, sort_rules=sort_rules) | |
51 | +def search_index(request, query_params, search=''): | |
52 | + query = PatternQuery(query_params) | |
53 | 53 | return {'index': query.search_index(search)} |
54 | 54 | |
55 | 55 | |
56 | 56 | @ajax(login_required=False, method='get') |
57 | -def get_patterns(request, from_page, to_page, rows, sort_rules, filter): | |
58 | - request.session['pattern-sort_rules'] = sort_rules | |
59 | - request.session['pattern-filter'] = filter | |
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 | 60 | columns = request.session.get('pattern-columns') |
61 | - query = PatternQuery(filter=filter, sort_rules=sort_rules, columns=columns) | |
61 | + query = PatternQuery(query_params, columns=columns) | |
62 | 62 | rows, count = query.get_page(from_page, to_page, rows) |
63 | 63 | return { |
64 | 64 | 'rows': rows, |
... | ... |
patterns/static/js/pattern-view.js
... | ... | @@ -58,29 +58,12 @@ $.extend(slickgrid, { |
58 | 58 | }, |
59 | 59 | init_sort: function() {}, |
60 | 60 | init: function() {}, |
61 | - // copypasta | |
62 | - row_index: function(id) { | |
61 | + | |
62 | + query_params: function() { | |
63 | 63 | "use strict"; |
64 | - $.ajaxJSON({ | |
65 | - url: $dj.ajax_row_index, | |
66 | - method: 'get', | |
67 | - data: { | |
68 | - id: id, | |
69 | - sort_rules: slickgrid.loader.getSort(), | |
70 | - filter: slickgrid.loader.getFilter() | |
71 | - }, | |
72 | - callback: function(data) { | |
73 | - var index = data.index; | |
74 | - if (index === null) { | |
75 | - slickgrid.load_content(id); | |
76 | - slickgrid.last_active_row = undefined; | |
77 | - slickgrid.grid.resetActiveCell(); | |
78 | - } else { | |
79 | - slickgrid.set_active_when_loaded = index; | |
80 | - slickgrid.grid.scrollRowToCenter(index); | |
81 | - slickgrid.ensure_data(); | |
82 | - } | |
83 | - } | |
84 | - }); | |
64 | + return { | |
65 | + sort_rules: slickgrid.loader.getSort(), | |
66 | + filter: slickgrid.loader.getFilter() | |
67 | + }; | |
85 | 68 | } |
86 | 69 | }); |
87 | 70 | \ No newline at end of file |
... | ... |