Skip to content
Snippets Groups Projects
Commit 394270bb authored by dcz's avatar dcz
Browse files

Notes bugfix

parent ed49ae60
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ from .phrase_descriptions.descriptions import position_prop_description ...@@ -47,6 +47,7 @@ from .phrase_descriptions.descriptions import position_prop_description
MAX_LAST_VISITED = 10 MAX_LAST_VISITED = 10
@login_required @login_required
def entries(request): def entries(request):
# TODO make this automatic by subclassing/configuring session object # TODO make this automatic by subclassing/configuring session object
...@@ -56,6 +57,7 @@ def entries(request): ...@@ -56,6 +57,7 @@ def entries(request):
request.session['show_reals_desc'] = True request.session['show_reals_desc'] = True
if 'show_linked_entries' not in request.session: if 'show_linked_entries' not in request.session:
request.session['show_linked_entries'] = True request.session['show_linked_entries'] = True
user = request.user
# TODO retrieve the form from the request session – keep forms between page refreshes, # TODO retrieve the form from the request session – keep forms between page refreshes,
# keep search history, allow saving searches? # keep search history, allow saving searches?
# if so, don’t delete local forms on main form submit in send_form # if so, don’t delete local forms on main form submit in send_form
...@@ -68,6 +70,7 @@ def entries(request): ...@@ -68,6 +70,7 @@ def entries(request):
'frames_form' : FrameFormFactory.get_form(as_subform=False), 'frames_form' : FrameFormFactory.get_form(as_subform=False),
'schemata_form' : SchemaFormFactory.get_form(as_subform=False), 'schemata_form' : SchemaFormFactory.get_form(as_subform=False),
'unified_frames_form': UnifiedFrameFormFactory.get_form(as_subform=False), 'unified_frames_form': UnifiedFrameFormFactory.get_form(as_subform=False),
'is_superlexicograf': user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists()
}) })
......
...@@ -5,9 +5,11 @@ from django.contrib.auth.decorators import login_required ...@@ -5,9 +5,11 @@ from django.contrib.auth.decorators import login_required
from django.db import transaction from django.db import transaction
from django.http import JsonResponse, HttpResponse from django.http import JsonResponse, HttpResponse
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.test import override_settings
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from common.decorators import ajax_required, ajax from common.decorators import ajax_required, ajax
from connections.models import SchemaHook, ExampleConnection
from entries.polish_strings import EXAMPLE_SOURCE, EXAMPLE_OPINION from entries.polish_strings import EXAMPLE_SOURCE, EXAMPLE_OPINION
from entries.views import get_scroller_params, get_alternations, get_prefs_list, schema2dict, \ from entries.views import get_scroller_params, get_alternations, get_prefs_list, schema2dict, \
frame2dict, collect_forms, get_filtered_objects, get_local_schema_filter_form, get_local_frame_filter_form frame2dict, collect_forms, get_filtered_objects, get_local_schema_filter_form, get_local_frame_filter_form
...@@ -16,7 +18,7 @@ from importer.unification.UnificationPreprocessXML import UnificationPreprocessH ...@@ -16,7 +18,7 @@ from importer.unification.UnificationPreprocessXML import UnificationPreprocessH
from meanings.models import LexicalUnit from meanings.models import LexicalUnit
from semantics.choices import FrameStatus from semantics.choices import FrameStatus
from semantics.models import Frame, ArgumentRole, SemanticRole, RoleAttribute, RoleType, RoleSubAttribute, \ from semantics.models import Frame, ArgumentRole, SemanticRole, RoleAttribute, RoleType, RoleSubAttribute, \
PredefinedSelectionalPreference PredefinedSelectionalPreference, Argument
from syntax.models import Schema from syntax.models import Schema
from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference, UnifiedFrame, \ from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference, UnifiedFrame, \
UnifiedFrame2SlowalFrameMapping, UnifiedFrameArgumentSlowalFrameMapping, HierarchyModel UnifiedFrame2SlowalFrameMapping, UnifiedFrameArgumentSlowalFrameMapping, HierarchyModel
...@@ -25,7 +27,7 @@ from . import choices ...@@ -25,7 +27,7 @@ from . import choices
from xml.etree.ElementTree import Element, SubElement, tostring from xml.etree.ElementTree import Element, SubElement, tostring
import io import io
from xml.sax import handler, make_parser from xml.sax import handler, make_parser
from django.db.models import Q from django.db.models import Q, Prefetch
from django.conf import settings from django.conf import settings
import logging import logging
...@@ -350,9 +352,16 @@ def to_lemma(lexical_units): ...@@ -350,9 +352,16 @@ def to_lemma(lexical_units):
return ", ".join(map(lambda l: l['str'], lexical_units)) return ", ".join(map(lambda l: l['str'], lexical_units))
# @override_settings(DEBUG=True)
def get_unified_frame_json(unified_frame, request): def get_unified_frame_json(unified_frame, request):
local_schema_filter_form = None local_schema_filter_form = None
local_frame_filter_form = None local_frame_filter_form = None
import datetime
now = datetime.datetime.now()
print("1 Current date and time : ")
print(now.strftime("%Y-%m-%d %H:%M:%S"))
if 'no_filters' in request.POST: if 'no_filters' in request.POST:
apply_filters = not simplejson.loads(request.POST['no_filters']) apply_filters = not simplejson.loads(request.POST['no_filters'])
local_schema_filter_form = get_local_schema_filter_form(apply_filters, request) local_schema_filter_form = get_local_schema_filter_form(apply_filters, request)
...@@ -364,22 +373,75 @@ def get_unified_frame_json(unified_frame, request): ...@@ -364,22 +373,75 @@ def get_unified_frame_json(unified_frame, request):
if local_frame_filter_form: if local_frame_filter_form:
slowal_frames_db = get_filtered_objects(local_frame_filter_form, slowal_frames_db) slowal_frames_db = get_filtered_objects(local_frame_filter_form, slowal_frames_db)
slowal_frames_db = slowal_frames_db.select_related("opinion")
# slowal_frames_db = slowal_frames_db.prefetch_related(
# Prefetch(
# 'lexical_units',
# queryset=LexicalUnit.objects
# ),
# Prefetch(
# 'arguments',
# queryset=Argument.objects.select_related("role", "role__role", "role__attribute", "role__sub_attribute").prefetch_related(
# Prefetch(
# 'example_connections',
# queryset=ExampleConnection.objects.select_related('example', 'lexical_unit').prefetch_related(
# Prefetch(
# 'arguments',
# queryset=Argument.objects
# ),
# Prefetch(
# 'schema_connections',
# queryset=SchemaHook.objects
# )
# )
# )
# )
# )
# )
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__role__role")
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__role__attribute")
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__role__sub_attribute")
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__example_connections__example")
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__example_connections__example__example_connections__arguments")
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__example_connections__example__example_connections__lexical_unit")
slowal_frames_db = slowal_frames_db.prefetch_related("arguments__example_connections__example__example_connections__schema_connections")
slowal_frames = slowal_frames_db.all() slowal_frames = slowal_frames_db.all()
slowal_frames_dict = []
for slowal_frame in slowal_frames:
dict = frame2dict(slowal_frame, slowal_frame.lexical_units.all())
slowal_frames_dict.append(dict)
all_schema_objects = Schema.objects.filter( all_schema_objects = Schema.objects.filter(
schema_hooks__argument_connections__argument__frame__in=slowal_frames).distinct() schema_hooks__argument_connections__argument__frame__in=slowal_frames).distinct()
if local_schema_filter_form: if local_schema_filter_form:
all_schema_objects = get_filtered_objects(local_schema_filter_form, all_schema_objects) all_schema_objects = get_filtered_objects(local_schema_filter_form, all_schema_objects)
slowal_frames_dict = [] all_schema_objects = all_schema_objects.select_related("opinion")
for slowal_frame in slowal_frames: all_schema_objects = all_schema_objects.prefetch_related("positions")
dict = frame2dict(slowal_frame, slowal_frame.lexical_units.all()) all_schema_objects = all_schema_objects.prefetch_related("schema_hooks")
slowal_frames_dict.append(dict) all_schema_objects = all_schema_objects.prefetch_related("schema_hooks__argument_connections")
all_schema_objects = all_schema_objects.prefetch_related("positions__function")
all_schema_objects = all_schema_objects.prefetch_related("positions__control")
all_schema_objects = all_schema_objects.prefetch_related("positions__pred_control")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types__main_type")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types__attributes")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types__lexicalized_phrase")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types__lemma_operator")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types__lemma_cooccur")
all_schema_objects = all_schema_objects.prefetch_related("positions__phrase_types__lemmata")
slowal_frames_dict = sorted(slowal_frames_dict, key=lambda x: to_lemma(x['lexical_units'])) slowal_frames_dict = sorted(slowal_frames_dict, key=lambda x: to_lemma(x['lexical_units']))
alternations, realisation_phrases, realisation_descriptions = get_alternations(all_schema_objects, slowal_frames) alternations, realisation_phrases, realisation_descriptions = get_alternations(all_schema_objects, slowal_frames)
examples = get_examples(slowal_frames) examples = get_examples(slowal_frames)
all_schema_objects_dict = [schema2dict(schema, schema.subentries.all()[0].negativity, request.LANGUAGE_CODE) for all_schema_objects_dict = [schema2dict(schema, schema.subentries.all()[0].negativity, request.LANGUAGE_CODE) for
......
...@@ -85,7 +85,7 @@ def add_note(request, model, pk, type=None): ...@@ -85,7 +85,7 @@ def add_note(request, model, pk, type=None):
subject = get_object_or_404(model, pk=pk) subject = get_object_or_404(model, pk=pk)
user = request.user user = request.user
if request.POST.get('super', 'off') == 'on' \ if request.POST.get('super', 'off') == 'on' \
and user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists(): and user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists() and hasattr(subject, 'assignments'):
user = subject.assignments.first().user user = subject.assignments.first().user
note = Note(author=user, subject=subject) note = Note(author=user, subject=subject)
if type: if type:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment