Commit 2fd3e43df9a1e5fbe222babcea21a0ec3ad0c42c
1 parent
db7bc5dd
Add splitting chunks
Showing
6 changed files
with
64 additions
and
3 deletions
collector/storage/forms.py
... | ... | @@ -336,6 +336,20 @@ class DocSplitForm(ModelForm): |
336 | 336 | fields = ['chunk_beg', 'chunk_end'] |
337 | 337 | |
338 | 338 | |
339 | +class ChunkSplitForm(ModelForm): | |
340 | + new_chunk_text = CharField(widget=Textarea(attrs={'rows': 10}), label='Tekst nowej sekcji') | |
341 | + | |
342 | + def __init__(self, *args, **kwargs): | |
343 | + super(ChunkSplitForm, self).__init__(*args, **kwargs) | |
344 | + | |
345 | + class Meta: | |
346 | + model = Chunk | |
347 | + fields = ['text', 'new_chunk_text'] | |
348 | + labels = { | |
349 | + 'text': 'Tekst', | |
350 | + } | |
351 | + | |
352 | + | |
339 | 353 | class ChunkMoveForm(ModelForm): |
340 | 354 | |
341 | 355 | def __init__(self, *args, **kwargs): |
... | ... |
collector/storage/static/storage/css/document.css
collector/storage/static/storage/js/document.js
... | ... | @@ -28,6 +28,10 @@ $(function () { |
28 | 28 | $(this).modalForm({formURL: $(this).data("id")}); |
29 | 29 | }); |
30 | 30 | |
31 | + $(".split-chunk").each( function () { | |
32 | + $(this).modalForm({formURL: $(this).data("id")}); | |
33 | + }); | |
34 | + | |
31 | 35 | $(".add-subchunk").each( function () { |
32 | 36 | $(this).modalForm({formURL: $(this).data("id")}); |
33 | 37 | }); |
... | ... |
collector/storage/templates/storage/annotation.html
... | ... | @@ -351,8 +351,11 @@ |
351 | 351 | <th class="actions"> |
352 | 352 | {% if user.is_authenticated %} |
353 | 353 | <i class="merge-chunk material-icons button merge" |
354 | - data-id="{% url 'merge_chunk' chunk.pk chunk.document.id %}" | |
354 | + data-id="{% url 'merge_chunk' chunk.pk %}" | |
355 | 355 | title="Połącz z inną sekcją">merge_type</i> |
356 | + <i class="split-chunk material-icons button split" | |
357 | + data-id="{% url 'split_chunk' chunk.pk %}" | |
358 | + title="Podziel sekcję">call_split</i> | |
356 | 359 | <i class="move-chunk material-icons button redo" data-id="{% url 'move_chunk' chunk.pk %}" |
357 | 360 | title="Przenieś do innego dokumentu">redo</i> |
358 | 361 | {% if not chunk.utterances.exists %} |
... | ... |
collector/storage/urls.py
... | ... | @@ -18,7 +18,8 @@ urlpatterns = [ |
18 | 18 | path('chunk/edit/<int:pk>', login_required(views.ChunkEditView.as_view()), name='edit_chunk'), |
19 | 19 | path('chunk/delete/<int:pk>', login_required(views.ChunkDeleteView.as_view()), name='delete_chunk'), |
20 | 20 | path('chunk/move/<int:pk>', login_required(views.ChunkMoveView.as_view()), name='move_chunk'), |
21 | - path('chunk/merge/<int:pk>/<str:doc_id>', login_required(views.ChunkMergeView.as_view()), name='merge_chunk'), | |
21 | + path('chunk/split/<int:pk>', login_required(views.ChunkSplitView.as_view()), name='split_chunk'), | |
22 | + path('chunk/merge/<int:pk>', login_required(views.ChunkMergeView.as_view()), name='merge_chunk'), | |
22 | 23 | path('subchunk/add/<int:chunk_pk>', login_required(views.SubchunkAddView.as_view()), name='add_subchunk'), |
23 | 24 | path('subchunk/edit/<int:pk>', login_required(views.SubchunkEditView.as_view()), name='edit_subchunk'), |
24 | 25 | path('subchunk/delete/<int:pk>', login_required(views.SubchunkDeleteView.as_view()), name='delete_subchunk'), |
... | ... |
collector/storage/views.py
... | ... | @@ -19,7 +19,7 @@ from keras import backend |
19 | 19 | from sys import maxsize |
20 | 20 | |
21 | 21 | from .forms import ChunkForm, ParticipantForm, SubchunkForm, MetadataForm, DocDetailsForm, KeywordForm, DocSplitForm, \ |
22 | - ChunkMoveForm, SubDocDetailsForm, AuthorForm, ChunkMergeForm | |
22 | + ChunkMoveForm, SubDocDetailsForm, AuthorForm, ChunkMergeForm, ChunkSplitForm | |
23 | 23 | from .models import Chunk, Document, Participant, Metadata, Keyword, Annotation |
24 | 24 | from projects.ppc.models import Utterance |
25 | 25 | from pipeline.models import ProcessingStatus |
... | ... | @@ -345,6 +345,37 @@ class ChunkMoveView(UpdateView): |
345 | 345 | return '%s#chunk-%d' % (reverse_lazy('annotation', kwargs={'doc_id': self.object.document.id}), self.object.pk) |
346 | 346 | |
347 | 347 | |
348 | +class ChunkSplitView(UpdateView): | |
349 | + model = Chunk | |
350 | + template_name = 'storage/edit.html' | |
351 | + form_class = ChunkSplitForm | |
352 | + | |
353 | + def form_valid(self, form): | |
354 | + if not self.request.is_ajax(): | |
355 | + self.object.text = form.cleaned_data['text'] | |
356 | + self.object.save() | |
357 | + next_chunks = Chunk.objects.filter(document=self.object.document, | |
358 | + sequence__gt=self.object.sequence).order_by('sequence') | |
359 | + if next_chunks.first().sequence == self.object.sequence + 1: | |
360 | + for chunk in next_chunks: | |
361 | + chunk.sequence += 1 | |
362 | + chunk.save() | |
363 | + Chunk.objects.create(document=self.object.document, | |
364 | + text=form.cleaned_data['new_chunk_text'], | |
365 | + sequence=self.object.sequence + 1) | |
366 | + return HttpResponseRedirect(self.get_success_url()) | |
367 | + return render(self.request, self.template_name, {'form': form}) | |
368 | + | |
369 | + def get_context_data(self, **kwargs): | |
370 | + context = super().get_context_data(**kwargs) | |
371 | + context['title'] = 'Podział sekcji' | |
372 | + context['submit_btn_text'] = 'Podziel' | |
373 | + return context | |
374 | + | |
375 | + def get_success_url(self): | |
376 | + return reverse_lazy('annotation', kwargs={'doc_id': self.object.document.id}) | |
377 | + | |
378 | + | |
348 | 379 | class ChunkMergeView(UpdateView): |
349 | 380 | model = Chunk |
350 | 381 | template_name = 'storage/edit.html' |
... | ... | @@ -1028,6 +1059,9 @@ class RetakeDocForAnnotationView(UserPassesTestMixin, RedirectView): |
1028 | 1059 | return HttpResponse('Wymagana jest rola redaktora, aby uzyskać dostęp do tej strony.') |
1029 | 1060 | |
1030 | 1061 | |
1062 | +# ****************************** autocomplete ****************************** | |
1063 | + | |
1064 | + | |
1031 | 1065 | def md_name_autocomplete(request): |
1032 | 1066 | mds = Metadata.objects.filter(name__istartswith=request.GET.get('term')) |
1033 | 1067 | names = list(set([md.name for md in mds])) |
... | ... |