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

Additional fitlers for unified frames

parent 2a2e5ee1
Branches
Tags
No related merge requests found
......@@ -628,6 +628,13 @@ class UnifiedFrameFormFactory(FormFactory):
lookup='arguments_count',
), None
),
(
'num_frames',
lambda: RangeFilter(
label=_('Liczba ram semantycznych'),
lookup='slowal_frames_count',
), None
),
(
'name',
lambda: RegexFilter(
......@@ -636,6 +643,14 @@ class UnifiedFrameFormFactory(FormFactory):
lookup='title',
), None,
),
(
'lemmas',
lambda: RegexFilter(
label=_('Lematy jednostek leksykalnych'),
max_length=200,
lookup='unified_frame_2_slowal_frame__slowal_frame__lexical_units__base',
), None,
),
(
None, None,
lambda n, cls: and_or_form_creator(_('UnifiedFrameArgument'), 'add-argument-{}'.format(n), data_add='argument'),
......
......@@ -86,5 +86,9 @@ class UnifiedFrameImport:
if subnode._name == 'slowal_frame':
UnifiedFrameImport.storeSlowalFrame(subnode, unifiedFrame, argumentIdsMapping)
unifiedFrame.arguments_count = len(argumentIdsMapping)
unifiedFrame.update_sloval_frame_count()
unifiedFrame.save()
return unifiedFrame.pk
......@@ -27,6 +27,10 @@ class UnifiedFrame(models.Model):
assignments = GenericRelation("users.Assignment", content_type_field="subject_ct", object_id_field="subject_id")
arguments_count = models.PositiveIntegerField(null=False, default=0)
slowal_frames_count = models.PositiveIntegerField(null=False, default=0)
objects = models.Manager.from_queryset(UnifiedFrameQueryset)()
def sorted_arguments(self): # TODO: zaimplementowac wlasciwe sortowanie
......@@ -42,6 +46,7 @@ class UnifiedFrame(models.Model):
new_unified_frame_arguments = None
if not new_frame:
new_frame = UnifiedFrame.objects.create()
new_frame.arguments_count = self.arguments_count
new_frame.save()
unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=self)
old_2_new_argument_mapping = {}
......@@ -71,6 +76,10 @@ class UnifiedFrame(models.Model):
argument_mapping.unified_agrument_id = new_unified_frame_arguments[i]
argument_mapping.save()
self.update_sloval_frame_count()
new_frame.update_sloval_frame_count()
# curr_mapping = UnifiedFrame2SlowalFrameMapping.objects.filter(unified_frame=self).all()
# if len(curr_mapping) == 0:
# unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=self).all()
......@@ -79,11 +88,20 @@ class UnifiedFrame(models.Model):
return new_frame
@transaction.atomic
def update_sloval_frame_count(
self, new_frame_title: Optional = None
) -> "UnifiedFrame":
self.slowal_frames_count = self.unified_frame_2_slowal_frame.count()
self.save()
@transaction.atomic
def duplicate(
self, new_frame_title: Optional = None
) -> "UnifiedFrame":
new_frame = UnifiedFrame.objects.create(title=new_frame_title)
new_frame.arguments_count = self.arguments_count
new_frame.slowal_frames_count = self.slowal_frames_count
new_frame.save()
unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=self)
for unified_frame_argument in unified_frame_arguments:
......
......@@ -375,6 +375,8 @@ def add_argument(request):
unifiedFrame = UnifiedFrame.objects.get(pk=unified_frame_id)
newUnifiedFrameArgument = UnifiedFrameArgument.objects.create(unified_frame=unifiedFrame)
newUnifiedFrameArgument.save()
unifiedFrame.arguments_count = unifiedFrame.arguments_count + 1
unifiedFrame.save()
return JsonResponse({})
@ajax_required
......@@ -386,6 +388,9 @@ def remove_argument(request):
newUnifiedFrameArgument = UnifiedFrameArgument.objects.get(id=complement_id)
newUnifiedFrameArgument.delete()
unifiedFrame = UnifiedFrame.objects.get(pk=unified_frame_id)
unifiedFrame.arguments_count = unifiedFrame.arguments_count - 1
unifiedFrame.save()
return JsonResponse({})
@ajax_required
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment