Commit 902704d20310f6fd9caee77948e60f12bd9a4cc8

Authored by janek37
1 parent d4668dfb

ostrzeganie przed usunięciem klasyfikacji, poprawki z powodu zmienionych tabel

.idea/sqldialects.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3 3 <component name="SqlDialectMappings">
4   - <file url="file://$PROJECT_DIR$/sql/history.sql" dialect="PostgreSQL" />
  4 + <file url="file://$PROJECT_DIR$/sql" dialect="PostgreSQL" />
5 5 </component>
6 6 </project>
7 7  
... ...
dictionary/ajax_lexeme_view.py
... ... @@ -145,6 +145,14 @@ def lexeme_edit_form(request, id):
145 145 to_return['cross_references'] = crs
146 146 return to_return
147 147  
  148 +@ajax(method='get')
  149 +def check_classifications(request, owner_id, pos):
  150 + part_of_speech = PartOfSpeech.objects.get(symbol=pos)
  151 + owner = Vocabulary.objects.get(pk=owner_id)
  152 + classifications = owner.classifications.filter(
  153 + parts_of_speech=part_of_speech)
  154 + return {'classifications': list(classifications.values_list('pk', flat=True))}
  155 +
148 156 def make_classification_forms(lexeme, vocabulary=None, part_of_speech=None,
149 157 editable=True):
150 158 if not vocabulary:
... ...
dictionary/export.py
... ... @@ -89,10 +89,10 @@ def export_lexemes(data=None, output_file=None):
89 89 cursor = connection.cursor()
90 90 query = """
91 91 select distinct haslo, prefiks||rdzen||zak||sufiks, l.pos, ch.charfl, tag,
92   - l.id as leksem_id, refl.lexemeattributevalue_id %(clas_field)s
  92 + l.id as leksem_id, refl.attribute_value_id %(clas_field)s
93 93 from leksemy l
94 94 join leksemy_w_slownikach ls on (ls.l_id = l.id)
95   - left outer join dictionary_lexemeattributevalue_lexemes refl
  95 + left outer join dictionary_lexemeav refl
96 96 on (l.id = refl.lexeme_id and %(refl)s)
97 97 join odmieniasie o on (o.l_id = l.id)
98 98 join charfle ch on ch.id = o.charfl
... ... @@ -111,13 +111,13 @@ def export_lexemes(data=None, output_file=None):
111 111 union all
112 112 -- wymagające gniazdowania przy hasłowaniu: adjcom, advcom, derywaty:
113 113 select distinct g.haslo as haslo, prefiks||rdzen||zak||sufiks, l.pos,
114   - ch.charfl, tag, l.id as leksem_id, refl.lexemeattributevalue_id
  114 + ch.charfl, tag, l.id as leksem_id, refl.attribute_value_id
115 115 %(clas_field)s
116 116 from leksemy l
117 117 join leksemy_w_slownikach ls on (ls.l_id = l.id)
118 118 join odsylacze on l.id=l_id_od
119 119 join leksemy g on (l_id_do=g.id and g.usuniety = false)
120   - left outer join dictionary_lexemeattributevalue_lexemes refl
  120 + left outer join dictionary_lexemeav refl
121 121 on (g.id = refl.lexeme_id and %(refl)s)
122 122 join odmieniasie o on l.id=o.l_id
123 123 join charfle ch on ch.id = o.charfl
... ... @@ -138,13 +138,13 @@ def export_lexemes(data=None, output_file=None):
138 138 'x_qual': qualifier_clauses,
139 139 'magic': magic_qualifier_clauses,
140 140 'crtype_ids': ', '.join(str(pk) for pk in crtype_ids), # brzydko, oj tam
141   - 'clas_field': ', classificationvalue_id' if data['commonness'] else '',
  141 + 'clas_field': ', classification_value_id' if data['commonness'] else '',
142 142 'clas_join':
143   - 'left outer join wartosci_klasyfikacji_lexemes wkl '
144   - 'on (wkl.lexeme_id=l.id and wkl.classificationvalue_id in (%s))'
  143 + 'left outer join dictionary_lexemecv wkl '
  144 + 'on (wkl.lexeme_id=l.id and wkl.classification_value_id in (%s))'
145 145 % ', '.join(str(pk) for pk in cv_ids) if data['commonness'] else '',
146 146 'refl':
147   - 'refl.lexemeattributevalue_id in (%s)'
  147 + 'refl.attribute_value_id in (%s)'
148 148 % ', '.join(str(pk) for pk in refls),
149 149 }
150 150 params_part = (list(data['vocabs']) + list(data['antivocabs']) +
... ...
dictionary/history.py
... ... @@ -106,10 +106,10 @@ def prepare_value(table, column, value):
106 106 prepared = InflectionCharacteristic.objects.get(pk=int(value)).symbol
107 107 elif column == 'w_id':
108 108 prepared = Pattern.objects.get(pk=int(value)).name
109   - elif column == 'classificationvalue_id':
  109 + elif column in ('classification_value_id', 'classificationvalue_id'):
110 110 cv = ClassificationValue.all_objects.get(pk=int(value))
111 111 prepared = (cv.label, cv.classification.name)
112   - elif column == 'lexemeattributevalue_id':
  112 + elif column == 'attribute_value_id':
113 113 av = LexemeAttributeValue.objects.get(pk=int(value))
114 114 prepared = (av.value, av.attribute.name)
115 115 else:
... ... @@ -152,9 +152,9 @@ def transaction_table(transaction_data):
152 152 if item1.row_id not in lips:
153 153 lips[item1.row_id] = {}
154 154 lips[item1.row_id][attr] = before_after
155   - if column == 'lexemeattributevalue_id':
  155 + if column == 'attribute_value_id':
156 156 extra_attributes.append(before_after)
157   - if column == 'classificationvalue_id':
  157 + if column in ('classification_value_id', 'classificationvalue_id'):
158 158 classifications.append(before_after)
159 159 if table == 'kwalifikatory_leksemow' and column == 'qualifier_id':
160 160 qualifiers.append(before_after)
... ...
dictionary/views.py
... ... @@ -65,6 +65,7 @@ def lexeme_view(request):
65 65 'ajax_prompter_list': reverse('prompter_list'),
66 66 'ajax_check_pos': reverse('check_pos'),
67 67 'ajax_check_pattern': reverse('check_pattern'),
  68 + 'ajax_check_classifications': reverse('check_classifications'),
68 69 'ajax_get_ics': reverse('get_ics'),
69 70 'ajax_save_default_owner': reverse('save_default_owner'),
70 71 'ajax_create_lexeme': reverse('create_lexeme'),
... ...
dictionary/wsjp.py
... ... @@ -20,8 +20,8 @@ def make_data(entries):
20 20 as rodzaj, podparad, row, col, rowspan, colspan, kskl
21 21 from
22 22 leksemy l
23   - left outer join dictionary_lexemeattributevalue_lexemes refl
24   - on (l.id = refl.lexeme_id and refl.lexemeattributevalue_id in (%(refl)s))
  23 + left outer join dictionary_lexemeav refl
  24 + on (l.id = refl.lexeme_id and refl.attribute_value_id in (%(refl)s))
25 25 join odmieniasie o on (l.id = o.l_id)
26 26 join charfle ch on (o.charfl = ch.id)
27 27 join wzory on (o.w_id = wzory.id)
... ... @@ -40,8 +40,8 @@ def make_data(entries):
40 40 join odsylacze ods on l.id = l_id_od
41 41 join typyodsylaczy tods on ods.typods_id = tods.id
42 42 join leksemy g on l_id_do = g.id
43   - left outer join dictionary_lexemeattributevalue_lexemes refl
44   - on (g.id = refl.lexeme_id and refl.lexemeattributevalue_id in (%(refl)s))
  43 + left outer join dictionary_lexemeav refl
  44 + on (g.id = refl.lexeme_id and refl.attribute_value_id in (%(refl)s))
45 45 join odmieniasie o on l.id = o.l_id
46 46 join charfle ch on (o.charfl = ch.id)
47 47 join wzory on (o.w_id = wzory.id)
... ... @@ -57,7 +57,7 @@ def make_data(entries):
57 57 'haslo': 'haslo',
58 58 'entry_placeholders': entry_placeholders,
59 59 'leks_clause': '''l.pos not in ('skrl','skrw') and
60   - (l.pos != 'v' or refl.lexemeattributevalue_id in (%s))'''
  60 + (l.pos != 'v' or refl.attribute_value_id in (%s))'''
61 61 % nonrefl_ids,
62 62 'refl': refl_ids,
63 63 },
... ... @@ -69,7 +69,7 @@ def make_data(entries):
69 69 'haslo_tab': u"haslo||' się'",
70 70 'haslo': 'haslo',
71 71 'entry_placeholders': entry_placeholders,
72   - 'leks_clause': '''(l.pos='v' and refl.lexemeattributevalue_id <> %s)''',
  72 + 'leks_clause': '''(l.pos='v' and refl.attribute_value_id <> %s)''',
73 73 'refl': refl_ids,
74 74 },
75 75 entries + [empty_refl, 's']
... ... @@ -80,7 +80,7 @@ def make_data(entries):
80 80 'haslo_tab': "'nie '||haslo",
81 81 'haslo': "'nie '||haslo",
82 82 'entry_placeholders': entry_placeholders,
83   - 'leks_clause': '''l.pos='v' and refl.lexemeattributevalue_id in (%s)'''
  83 + 'leks_clause': '''l.pos='v' and refl.attribute_value_id in (%s)'''
84 84 % nonrefl_ids,
85 85 'refl': refl_ids,
86 86 },
... ... @@ -92,7 +92,7 @@ def make_data(entries):
92 92 'haslo_tab': u"'nie '||haslo||' się'",
93 93 'haslo': "'nie '||haslo",
94 94 'entry_placeholders': entry_placeholders,
95   - 'leks_clause': '''(l.pos='v' and refl.lexemeattributevalue_id <> %s)''',
  95 + 'leks_clause': '''(l.pos='v' and refl.attribute_value_id <> %s)''',
96 96 'refl': refl_ids,
97 97 },
98 98 entries + [empty_refl, 'ns']
... ... @@ -104,7 +104,7 @@ def make_data(entries):
104 104 'entry_placeholders': entry_placeholders,
105 105 'main_clause': '''typods in ('comadj','comadv','ppasver') and
106 106 l.pos in ('adjcom','advcom','ppas') and
107   - (l.pos != 'ppas' or refl.lexemeattributevalue_id in (%s))'''
  107 + (l.pos != 'ppas' or refl.attribute_value_id in (%s))'''
108 108 % nonrefl_ids,
109 109 'refl': refl_ids,
110 110 },
... ... @@ -116,7 +116,7 @@ def make_data(entries):
116 116 'haslo': u"g.haslo||' się'",
117 117 'entry_placeholders': entry_placeholders,
118 118 'main_clause': '''(typods ='ppasver' and l.pos ='ppas' and
119   - refl.lexemeattributevalue_id <> %s)''',
  119 + refl.attribute_value_id <> %s)''',
120 120 'refl': refl_ids,
121 121 },
122 122 entries + [empty_refl]
... ...
media/js/lexeme-view.js
1 1 var prompter_ctrl, created;
2 2  
  3 +function init_selection(jq) {
  4 + "use strict";
  5 + jq.find('option:selected').addClass('last-selected');
  6 +}
  7 +
  8 +function revert_selection(jq) {
  9 + "use strict";
  10 + jq.find('option.last-selected').prop('selected', true);
  11 +}
  12 +
  13 +function confirm_selection(jq) {
  14 + "use strict";
  15 + jq.find('option.last-selected').removeClass('last-selected');
  16 + jq.find('option:selected').addClass('last-selected');
  17 +}
  18 +
3 19 function selected_qualifiers_text(num, total, checked) {
4 20 "use strict";
5 21 if (num >= 4)
... ... @@ -227,6 +243,11 @@ function get_entry() {
227 243 return $('#id_entry').val();
228 244 }
229 245  
  246 +function get_owner() {
  247 + "use strict";
  248 + return $('#id_new_owner').val();
  249 +}
  250 +
230 251 function join_attrs(attrs) {
231 252 "use strict";
232 253 return $.map(attrs, function(attr) {
... ... @@ -234,6 +255,13 @@ function join_attrs(attrs) {
234 255 }).join(', ');
235 256 }
236 257  
  258 +function join_classifications(clas_ids) {
  259 + "use strict";
  260 + return $.map(clas_ids, function(c_id) {
  261 + return $("[for='id_cl" + c_id + "-values']").text().replace(':', '');
  262 + }).join(', ');
  263 +}
  264 +
237 265 function init_form_widgets() {
238 266 "use strict";
239 267 $(document).on('click', '.lip-row span.remove', function() {
... ... @@ -259,8 +287,7 @@ function init_form_widgets() {
259 287 $(document).on('click', '#add-row', function() {
260 288 var id = lexeme_id();
261 289 var new_row = $(get_new_row_html(id));
262   - new_row.find('.inflection-characteristic option:selected')
263   - .addClass('last-selected');
  290 + init_selection(new_row.find('.inflection-characteristic'));
264 291 var pattern_list = $('#pattern-list');
265 292 pattern_list.append(new_row);
266 293 var elem = pattern_list.find('.lip-qualifiers').last();
... ... @@ -381,7 +408,21 @@ function init_form_widgets() {
381 408 $('#move-lexeme').toggleClass('move-hidden');
382 409 });
383 410 $(document).on('change', '#id_part_of_speech', check_pos);
384   - $(document).on('change', '#id_new_owner', reload_classifications);
  411 + $(document).on('change', '#id_new_owner', function() {
  412 + var stale_classifications = check_classifications(), confirmed;
  413 + if (stale_classifications.length > 0) {
  414 + confirmed = window.confirm(
  415 + 'Zostaną usunięte klasyfikacje: ' +
  416 + join_classifications(stale_classifications) + 'Kontynuować?');
  417 + if (!confirmed) {
  418 + revert_selection($(this));
  419 + }
  420 + }
  421 + if (confirmed || stale_classifications.length === 0) {
  422 + confirm_selection($(this));
  423 + reload_classifications();
  424 + }
  425 + });
385 426 $(document).on('change', '.inflection-characteristic', function() {
386 427 var new_ics = get_ic_symbols();
387 428 var stale_attrs = check_attrs(new_ics);
... ... @@ -390,12 +431,11 @@ function init_form_widgets() {
390 431 confirmed = window.confirm("Atrybuty: " + join_attrs(stale_attrs) +
391 432 ' zostaną usunięte. Kontynouwać?');
392 433 if (!confirmed) {
393   - $(this).find('option.last-selected').prop('selected', true);
  434 + revert_selection($(this));
394 435 }
395 436 }
396 437 if (confirmed || stale_attrs.length === 0) {
397   - $(this).find('option.last-selected').removeClass('last-selected');
398   - $(this).find('option:selected').addClass('last-selected');
  438 + confirm_selection($(this));
399 439 reload_attributes();
400 440 }
401 441 });
... ... @@ -413,7 +453,7 @@ function reload_classifications() {
413 453 "use strict";
414 454 var data = {
415 455 lexeme_id: lexeme_id(),
416   - vocab_id: $('#id_new_owner').val(),
  456 + vocab_id: get_owner(),
417 457 pos: get_pos()
418 458 };
419 459 $.ajaxJSON({
... ... @@ -527,8 +567,9 @@ function edit_form_init() {
527 567 deleted = [];
528 568 deleted_cr = [];
529 569 created = false;
530   - $('#id_part_of_speech').find('option:selected').addClass('last-selected');
531   - $('.inflection-characteristic option:selected').addClass('last-selected');
  570 + init_selection($('#id_part_of_speech'));
  571 + init_selection($('.inflection-characteristic'));
  572 + init_selection(new_owner_elem);
532 573 jqgrid.hide_changed();
533 574 if (jqgrid.ctrl)
534 575 jqgrid.ctrl.remove();
... ... @@ -902,6 +943,26 @@ function input_prompter_pattern() {
902 943 }
903 944 }
904 945  
  946 +function check_classifications() {
  947 + "use strict";
  948 + var new_classifications = $.ajaxJSON({
  949 + method: 'get',
  950 + url: $dj.ajax_check_classifications,
  951 + data: {lexeme_id: lexeme_id(), pos: get_pos(), owner_id: get_owner()},
  952 + async: false
  953 + }).classifications;
  954 + var old_classifications = $('#classifications').find('.classification-values')
  955 + .map(function(i, el) {
  956 + return parseInt(el.id.replace('id_cl', '').replace('-values', ''), 10);
  957 + });
  958 + var stale_classifications = [];
  959 + old_classifications.each(function(i, c_id) {
  960 + if (new_classifications.indexOf(c_id) === -1)
  961 + stale_classifications.push(c_id);
  962 + });
  963 + return stale_classifications;
  964 +}
  965 +
905 966 function check_attrs(ics) {
906 967 "use strict";
907 968 var new_attrs = $.ajaxJSON({
... ... @@ -914,7 +975,7 @@ function check_attrs(ics) {
914 975 return parseInt(el.id.split('-')[0].substring('id_attr'.length), 10);
915 976 });
916 977 var stale_attrs = [];
917   - $.each(old_attrs, function(i, attr) {
  978 + old_attrs.each(function(i, attr) {
918 979 if (new_attrs.indexOf(attr) === -1)
919 980 stale_attrs.push(attr);
920 981 });
... ... @@ -943,7 +1004,9 @@ var check_pos = function() {
943 1004 good_ics.push(ic_symbol);
944 1005 });
945 1006 var stale_attrs = check_attrs(good_ics);
946   - if (bad_lips.length > 0 || cr_row_elems.length > 0 || stale_attrs.length > 0) {
  1007 + var stale_classifications = check_classifications();
  1008 + if (bad_lips.length > 0 || cr_row_elems.length > 0 ||
  1009 + stale_attrs.length > 0 || stale_classifications.length > 0) {
947 1010 var lips_text = '', cr_text = '', lips = [];
948 1011 if (bad_lips.length > 0) {
949 1012 $.each(bad_lips, function(i, t) {
... ... @@ -956,21 +1019,25 @@ var check_pos = function() {
956 1019 if (cr_row_elems.length > 0) {
957 1020 cr_text += "wszystkie odsyłacze\n";
958 1021 }
959   - // TODO ostrzegać przed znikaniem klasyfikacji [kiedyś] (?)
960 1022 var attr_text = '';
961 1023 if (stale_attrs.length > 0) {
962 1024 attr_text = "atrybuty: " + join_attrs(stale_attrs) + '\n';
963 1025 }
  1026 + var clas_text = '';
  1027 + if (stale_classifications.length > 0) {
  1028 + clas_text = "klasyfikacje: " +
  1029 + join_classifications(stale_classifications) + '\n';
  1030 + }
964 1031 confirmed = window.confirm(
965   - 'Zostaną usunięte:\n' + lips_text + cr_text + attr_text + 'Kontynuować?');
  1032 + 'Zostaną usunięte:\n' + lips_text + cr_text + attr_text + clas_text +
  1033 + 'Kontynuować?');
966 1034 if (!confirmed) {
967   - $(this).find('option.last-selected').prop('selected', true);
  1035 + revert_selection($(this));
968 1036 }
969 1037 }
970 1038 if (confirmed || !(bad_lips.length > 0 || cr_row_elems.length > 0 ||
971   - stale_attrs.length > 0)) {
972   - $(this).find('option.last-selected').removeClass('last-selected');
973   - $(this).find('option:selected').addClass('last-selected');
  1039 + stale_attrs.length > 0 || stale_classifications.length > 0)) {
  1040 + confirm_selection($(this));
974 1041 var result = $.ajax({ // znowu brzydko...
975 1042 type: 'get',
976 1043 url: $dj.ajax_get_ics,
... ...
sql/drop.sql
  1 +-- bardzo nieaktualne!
1 2 drop table "auth_group_permissions" cascade;
2 3 drop table "auth_group" cascade;
3 4 drop table "auth_user_user_permissions" cascade;
... ... @@ -11,7 +12,7 @@
11 12 drop table "klasygramatyczne" cascade;
12 13 drop table "kwalifikatory_leksemow" cascade;
13 14 drop table "kwalifikatory_odmieniasiow" cascade;
14   - drop table "wartosci_klasyfikacji_lexemes" cascade;
  15 + drop table "dictionary_lexemecv" cascade;
15 16 drop table "odmieniasie" cascade;
16 17 drop table "zakonczenia" cascade;
17 18 drop table "kwalifikatory_zakonczen" cascade;
... ...
sql/history.sql
... ... @@ -40,7 +40,7 @@ BEGIN
40 40 lexemeId := temp.id;
41 41 ELSIF (TG_TABLE_NAME IN ('odmieniasie', 'leksemy_w_slownikach')) THEN
42 42 lexemeId := temp.l_id;
43   - ELSIF (TG_TABLE_NAME IN ('kwalifikatory_leksemow', 'wartosci_klasyfikacji_lexemes', 'dictionary_lexemeattributevalue_lexemes')) THEN
  43 + ELSIF (TG_TABLE_NAME IN ('kwalifikatory_leksemow', 'dictionary_lexemeav', 'dictionary_lexemecv')) THEN
44 44 lexemeId := temp.lexeme_id;
45 45 ELSIF (TG_TABLE_NAME = 'odsylacze') THEN
46 46 lexemeId := temp.l_id_od;
... ... @@ -116,16 +116,16 @@ CREATE TRIGGER leksemy_w_slownikach_trigger_history_
116 116 AFTER INSERT OR UPDATE OR DELETE ON leksemy_w_slownikach
117 117 FOR EACH ROW EXECUTE PROCEDURE make_history_();
118 118  
119   -CREATE TRIGGER wartosci_klasyfikacji_lexemes_trigger_history_
120   -AFTER INSERT OR UPDATE OR DELETE ON wartosci_klasyfikacji_lexemes -- ta tabela zmieni nazwę
  119 +CREATE TRIGGER dictionary_lexemecv_trigger_history_
  120 +AFTER INSERT OR UPDATE OR DELETE ON dictionary_lexemecv
121 121 FOR EACH ROW EXECUTE PROCEDURE make_history_();
122 122  
123 123 CREATE TRIGGER odsylacze_trigger_history_
124 124 AFTER INSERT OR UPDATE OR DELETE ON odsylacze
125 125 FOR EACH ROW EXECUTE PROCEDURE make_history_();
126 126  
127   -CREATE TRIGGER lexemeattributevalue_lexemes_trigger_history_
128   -AFTER INSERT OR UPDATE OR DELETE ON dictionary_lexemeattributevalue_lexemes
  127 +CREATE TRIGGER dictionary_lexemeav_trigger_history_
  128 +AFTER INSERT OR UPDATE OR DELETE ON dictionary_lexemeav
129 129 FOR EACH ROW EXECUTE PROCEDURE make_history_();
130 130  
131 131 -- wzory
... ...
... ... @@ -5,8 +5,8 @@ from django.conf import settings
5 5 from common.util import url
6 6  
7 7 # Uncomment the next two lines to enable the admin:
8   -from django.contrib import admin
9   -admin.autodiscover()
  8 +#from django.contrib import admin
  9 +#admin.autodiscover()
10 10  
11 11 urlpatterns = patterns('',
12 12 # Example:
... ... @@ -39,6 +39,7 @@ urlpatterns += patterns(&#39;dictionary.ajax_lexeme_view&#39;,
39 39 url(r'^ajax/delete_lexeme/$', 'delete_lexeme'),
40 40 url(r'^ajax/check-pos/$', 'check_pos'),
41 41 url(r'^ajax/check-pattern/$', 'check_pattern'),
  42 + url(r'^ajax/check-classifications/$', 'check_classifications'),
42 43 url(r'^ajax/get-ics/$', 'get_ics'),
43 44 url(r'^ajax/create-lexeme/$', 'create_lexeme'),
44 45 url(r'^ajax/classification-forms/$', 'classification_forms'),
... ...