diff --git a/LICENSE b/LICENSE index 68035cc..6baacb7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012, Bartłomiej Nitoń +Copyright (c) 2015, Bartłomiej Nitoń All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/accounts/admin.py b/accounts/admin.py index a148c51..ff6f8f4 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -39,7 +39,8 @@ class RealizedPhraseologyAdmin(admin.ModelAdmin): readonly_fields = ('date',) search_fields = ('lemma__entry',) -class RealizedSemanticsAdmin(admin.ModelAdmin): +class RealizedSemanticsAdmin(admin.ModelAdmin): + exclude = ('entry',) list_filter = ('status', 'bonus',) search_fields = ('entry__name',) diff --git a/dictionary/ajax_lemma_view.py b/dictionary/ajax_lemma_view.py index 65aa6ab..1d10f9d 100644 --- a/dictionary/ajax_lemma_view.py +++ b/dictionary/ajax_lemma_view.py @@ -3193,3 +3193,21 @@ def delete_user(request, user_id): def deselect_preview_tab(request): request.session['lemma_preview'] = False return {} + +@ajax(method='get') +def get_schemata(request, lemma_id): + lemma = Lemma.objects.get(id=lemma_id) + schemata = lemma.frames.order_by('text_rep') + serialized_schemata = [frameObjToSerializableDict(lemma, schema, True) for schema in schemata] + json_schemata = json_encode(serialized_schemata) + return {'schemata': json_schemata, + 'can_modify': user_can_modify(lemma, request.user)} + +@ajax(method='get') +def get_examples(request, lemma_id): + lemma = Lemma.objects.get(id=lemma_id) + examples = lemma.nkjp_examples.all() + examples_js = nkjpExamplesObjToJs(examples, request.user, lemma) + json_examples = json_encode(examples_js) + return {'examples': json_examples, + 'can_modify': user_can_modify(lemma, request.user)} diff --git a/dictionary/saving.py b/dictionary/saving.py index a1c6782..f0bf09c 100644 --- a/dictionary/saving.py +++ b/dictionary/saving.py @@ -23,21 +23,22 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema, operations = [] used_poss_ids = [] for js_position in js_schema['positions']: - position = get_position(schema, js_position, used_poss_ids) - for js_phrase_type in js_position['arguments']: - phrase_type = Argument.objects.get(text_rep=js_phrase_type['text_rep']) - new_connection_target = {'schema': schema, - 'position': position, - 'phrase_type': phrase_type} - for conn in js_phrase_type['connections']: - operations.extend(reconnect_operations(frames, conn, new_connection_target)) - conn_dict = next((conn_dict - for conn_dict in connections if conn_dict['compl'] == conn['compl']), None) - if conn_dict: - conn_dict['realizations'].extend(conn['realizations']) - else: - connections.append({'compl': conn['compl'], - 'realizations': conn['realizations']}) + if len(js_position['arguments']) > 0: + position = get_position(schema, js_position, used_poss_ids) + for js_phrase_type in js_position['arguments']: + phrase_type = Argument.objects.get(text_rep=js_phrase_type['text_rep']) + new_connection_target = {'schema': schema, + 'position': position, + 'phrase_type': phrase_type} + for conn in js_phrase_type['connections']: + operations.extend(reconnect_operations(frames, conn, new_connection_target)) + conn_dict = next((conn_dict + for conn_dict in connections if conn_dict['compl'] == conn['compl']), None) + if conn_dict: + conn_dict['realizations'].extend(conn['realizations']) + else: + connections.append({'compl': conn['compl'], + 'realizations': conn['realizations']}) return operations def get_position(schema, js_position, used_poss_ids): diff --git a/dictionary/static/js/lemma-view.js b/dictionary/static/js/lemma-view.js index 1ad464f..a75776c 100644 --- a/dictionary/static/js/lemma-view.js +++ b/dictionary/static/js/lemma-view.js @@ -75,6 +75,15 @@ var nkjp_source_tab = ax_nkjp_source_vals; function alertUserNotAuthenticated() { error_alert('Przed wykonaniem działania odśwież okno przeglądarki, a następnie zaloguj się ponownie do narzędzia.'); } + +function resetLemmaVersions() { + window.frames_modif = new Array(); + window.frames_modif_idx = 0; + var lemma_version = new Lemma_Version(window.schemas, + window.nkjp_examples, + window.nkjp_lemma_examples); + frames_modif.push(lemma_version); +} function initiateFrameFilters() { @@ -437,7 +446,7 @@ function load_content(id) { window.notesNotSaved = false; window.lemmaExNotSaved = false; - $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ + $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ window.lemma_id = id; createSplitter('framesSplit','new-frame-tables', 'tabs'); if(window.can_modify) diff --git a/dictionary/static/js/semantics_coupling.js b/dictionary/static/js/semantics_coupling.js index c84b329..bbe6c17 100644 --- a/dictionary/static/js/semantics_coupling.js +++ b/dictionary/static/js/semantics_coupling.js @@ -1,5 +1,4 @@ -function schemaGotAssignedSemantics(element_id) -{ +function schemaGotAssignedSemantics(element_id) { var semanticsAssigned = true; var id_map = parseId(element_id); var schema_id = id_map['frame_id']; @@ -93,3 +92,63 @@ function clearPositionConnections(position) { function clearPhraseTypeConnections(phraseType) { phraseType.connections = []; } + +function updateSchemataConnections() { + $('#new-frame-tables').empty(); + $("#show_nkjp_table").empty(); + $.ajaxJSON({ + method: 'get', + url: ajax_get_schemata, + data: { + lemma_id: window.lemma_id + }, + + callback: function(result) { + window.schemas = serializedObjToObj(result['schemata']); + resetLemmaVersions(); + var frame_class = 'InactiveFrameTable'; + if(result['can_modify']) { + frame_class = 'ActiveFrameTable'; + } + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', + 'frame_filter', window.nkjp_examples, frame_class, + window.lemma_entry, window.lemma_entry); + }, + error_callback: function(xhr, status, error) { + error_alert(status + ': ' + error); + }, + bad_data_callback: function(result) { + return true; + }, + }); +} + +function updateExamplesConnections() { + $('#new-frame-tables').empty(); + $("#show_nkjp_table").empty(); + $.ajaxJSON({ + method: 'get', + url: ajax_get_examples, + data: { + lemma_id: window.lemma_id + }, + + callback: function(result) { + window.nkjp_examples = serializedNkjpToObj(result['examples']); + resetLemmaVersions(); + var frame_class = 'InactiveFrameTable'; + if(result['can_modify']) { + frame_class = 'ActiveFrameTable'; + } + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', + 'frame_filter', window.nkjp_examples, frame_class, + window.lemma_entry, window.lemma_entry); + }, + error_callback: function(xhr, status, error) { + error_alert(status + ': ' + error); + }, + bad_data_callback: function(result) { + return true; + }, + }); +} diff --git a/dictionary/views.py b/dictionary/views.py index 1cb0a07..853131b 100644 --- a/dictionary/views.py +++ b/dictionary/views.py @@ -191,6 +191,8 @@ def lemma_view(request): 'ajax_get_compatible_schema_chars' : reverse('get_compatible_schema_chars'), 'ajax_deselect_preview_tab': reverse('deselect_preview_tab'), + 'ajax_get_schemata': reverse('get_schemata'), + 'ajax_get_examples': reverse('get_examples'), # powiazywanie hasel (nieczasownikowe) 'ajax_relate_entries' : reverse('relate_entries'), diff --git a/semantics/static/js/semantics_frames.js b/semantics/static/js/semantics_frames.js index e634747..87183cd 100644 --- a/semantics/static/js/semantics_frames.js +++ b/semantics/static/js/semantics_frames.js @@ -463,8 +463,8 @@ function saveFrames() { memorizeConnections(data.connections.connected, data.connections.connected_reverse); $("#semantic-frames-count").empty(); $("#semantic-frames-count").append(data.frames_count); + updateSchemataConnections(); }); frames_operations = []; } } - diff --git a/semantics/static/js/semantics_lexical_units.js b/semantics/static/js/semantics_lexical_units.js index 6dac2cd..266e504 100644 --- a/semantics/static/js/semantics_lexical_units.js +++ b/semantics/static/js/semantics_lexical_units.js @@ -97,6 +97,7 @@ function saveMeanings() { success: function(data){ memorizeLexicalUnits(data.lexical_units); basicLexicalUnitsData(data.informations); + updateExamplesConnections(); }, async: false }); diff --git a/urls.py b/urls.py index 1b9858f..329e9a2 100644 --- a/urls.py +++ b/urls.py @@ -121,6 +121,8 @@ urlpatterns += patterns('dictionary.ajax_lemma_view', url(r'^ajax/user_is_authenticated/$', 'user_is_authenticated'), url(r'^ajax/deselect_preview_tab/$', 'deselect_preview_tab'), + url(r'^ajax/get_schemata/$', 'get_schemata'), + url(r'^ajax/get_examples/$', 'get_examples'), # powiazywanie hasel (nieczasownikowe) url(r'^ajax/relate_entries/$', 'relate_entries'),