Commit 02b8be12c1a953f8a8185ad60039976b6ab234b0

Authored by Marcel Kawski
1 parent 650fe8bf

Update other files

collector/loaders/korpushumanistyczny_tei.py
... ... @@ -114,10 +114,8 @@ def _create_document(pipeline, doc_path, doc_name, header_data):
114 114 lang='pl',
115 115 original_lang='pl',
116 116 pipeline=pipeline,
117   - publisher='',
118 117 publication_date=None,
119 118 publication_place='',
120   - number='',
121 119 meta_url='',
122 120 source_url='',
123 121 path=doc_path,
... ...
collector/storage/models.py
... ... @@ -132,8 +132,8 @@ class Document(models.Model):
132 132  
133 133 def check_details_filling(self):
134 134 if self.parent is None:
135   - if self.title == '' or self.publication_date is None or self.publication_place == '' or self.number == '' \
136   - or self.original_lang == '':
  135 + if self.title == '' or self.publication_date is None or self.publication_place == '' or \
  136 + self.original_lang == '':
137 137 return False
138 138 else:
139 139 if self.title == '' or self.original_lang == '':
... ... @@ -195,7 +195,6 @@ class Chapter(Document):
195 195 return 'rozdział'
196 196  
197 197  
198   -
199 198 class Chunk(models.Model):
200 199 document = models.ForeignKey(Document, related_name='chunks', on_delete=models.CASCADE)
201 200 sequence = models.PositiveIntegerField()
... ...
collector/storage/static/storage/css/document.css
... ... @@ -421,3 +421,7 @@ ul.legend {
421 421 .navbar-brand:hover, .nav-item:hover {
422 422 color: #0a79df;
423 423 }
  424 +
  425 +#change-doc-type-btn {
  426 + margin-left: 10px;
  427 +}
... ...
collector/storage/static/storage/js/document.js
... ... @@ -72,6 +72,10 @@ $(function () {
72 72 $(this).modalForm({formURL: $(this).data("id")});
73 73 });
74 74  
  75 + $(".change-doc-type").each(function () {
  76 + $(this).modalForm({formURL: $(this).data("id")});
  77 + });
  78 +
75 79 $(".add-keyword").each(function () {
76 80 $(this).modalForm({formURL: $(this).data("id")});
77 81 });
... ...
collector/storage/templates/storage/annotation.html
1 1 {% extends "storage/base.html" %}
2 2 {% load static %}
  3 +{% load filters %}
  4 +
3 5  
4 6 {% block title %}
5 7 {% if document %}
... ... @@ -96,6 +98,15 @@
96 98 {% endif %}
97 99 </div>
98 100 {% endif %}
  101 +
  102 + <div class="text-align-center">
  103 + <p>
  104 + Typ dokumentu: <strong>{{ doc_type }}</strong>
  105 + <button class="change-doc-type btn btn-primary" id="change-doc-type-btn" type="button"
  106 + data-id="{% url 'change_doc_type' document.id %}">Zmień
  107 + </button>
  108 + </p>
  109 + </div>
99 110  
100 111 {% if document.image or document.broken_source %}
101 112 <div class="info">
... ... @@ -113,7 +124,7 @@
113 124  
114 125 {% if subdocuments %}
115 126 <div class="info">
116   - <p>Poddokumenty:</p>
  127 + <p>Poddokumenty:</p>
117 128 </div>
118 129  
119 130 <table class="data-table doc-table" id="subdoc-list-table">
... ... @@ -162,7 +173,7 @@
162 173 <table class="data-table doc-table">
163 174 <thead>
164 175 <tr id="doc-details">
165   - <th class="col-title-subdoc">Tytuł</th>
  176 + <th class="col-title">Tytuł</th>
166 177 <th>Język oryginału</th>
167 178 <th class="actions col-actions">
168 179 {% if user.is_authenticated %}
... ... @@ -190,17 +201,29 @@
190 201 <thead>
191 202 <tr id="doc-details">
192 203 <th class="col-title">Tytuł</th>
193   - <th class="col-pub-date">Data publikacji</th>
194   - <th class="col-place">Miejsce publikacji</th>
195   - <th class="col-number">Numer</th>
196   - <th class="col-channel">Kanał</th>
197   - <th class="col-type">Typ</th>
  204 + <th>Data publikacji</th>
  205 + <th>Miejsce publikacji</th>
  206 + {% if document|isinst:"storage.models.Magazine" %}
  207 + <th>Numer</th>
  208 + {% elif document|isinst:"storage.models.BookWithMultipleAuthors" %}
  209 + <th>Wydawca</th>
  210 + {% endif %}
  211 + <th>Kanał</th>
  212 + <th>Typ</th>
198 213 <th class="col-text-origin">Pochodzenie</th>
199 214 <th>Język oryginału</th>
200 215 <th class="actions col-actions">
201 216 {% if user.is_authenticated %}
202   - <i class="edit-doc-details material-icons button edit" data-id="{% url 'edit_doc_details' document.pk %}"
203   - title="Edytuj">edit</i>
  217 + {% if document|isinst:"storage.models.Magazine" %}
  218 + <i class="edit-doc-details material-icons button edit" data-id="{% url 'edit_magazine_details' document.pk %}"
  219 + title="Edytuj">edit</i>
  220 + {% elif document|isinst:"storage.models.BookWithMultipleAuthors" %}
  221 + <i class="edit-doc-details material-icons button edit" data-id="{% url 'edit_bwma_details' document.pk %}"
  222 + title="Edytuj">edit</i>
  223 + {% elif document|isinst:"storage.models.Document" %}
  224 + <i class="edit-doc-details material-icons button edit" data-id="{% url 'edit_doc_details' document.pk %}"
  225 + title="Edytuj">edit</i>
  226 + {% endif %}
204 227 {% endif %}
205 228 </th>
206 229 </tr>
... ... @@ -211,15 +234,16 @@
211 234 <td>{{ document.title }}</td>
212 235 <td>{{ document.publication_date|default_if_none:'' }}</td>
213 236 <td>{{ document.publication_place }}</td>
214   - <td>{{ document.number }}</td>
  237 + {% if document|isinst:"storage.models.Magazine" %}
  238 + <td>{{ document.number|default_if_none:'' }}</td>
  239 + {% elif document|isinst:"storage.models.BookWithMultipleAuthors" %}
  240 + <td>{{ document.publisher|default_if_none:'' }}</td>
  241 + {% endif %}
215 242 <td>{{ document.channel }}</td>
216 243 <td>{{ document.type }}</td>
217 244 <td>{{ document.text_origin }}</td>
218 245 <td>{{ document.original_lang }}</td>
219 246 </tr>
220   - <tr>
221   - <td colspan="9"></td>
222   - </tr>
223 247 </tbody>
224 248 </table>
225 249  
... ...
collector/storage/templates/storage/edit.html
... ... @@ -32,6 +32,18 @@
32 32 </div>
33 33  
34 34 <div class="modal-body">
  35 +
  36 + {% for message in messages %}
  37 + {% if message.tags == "error" %}
  38 + <div class="alert alert-danger text-center" role="alert">
  39 + {{ message }}
  40 + </div>
  41 + {% else %}
  42 + <div class="alert alert-{{ message.tags }} text-center" role="alert">
  43 + {{ message }}
  44 + </div>
  45 + {% endif %}
  46 + {% endfor %}
35 47  
36 48 <div class="{% if form.non_field_errors %}invalid{% endif %} mb-2">
37 49 {% for error in form.non_field_errors %}
... ...
collector/storage/templates/storage/review.html
1 1 {% extends "storage/base.html" %}
2 2 {% load static %}
3   -{% load group_filter %}
  3 +{% load filters %}
4 4 {% block title %} Recenzowanie dokumentu {% endblock %}
5 5  
6 6 {% block content %}
... ... @@ -130,11 +130,15 @@
130 130 <thead>
131 131 <tr id="doc-details">
132 132 <th class="col-title">Tytuł</th>
133   - <th class="col-pub-date">Data publikacji</th>
134   - <th class="col-place">Miejsce publikacji</th>
135   - <th class="col-number">Numer</th>
136   - <th class="col-channel">Kanał</th>
137   - <th class="col-type">Typ</th>
  133 + <th>Data publikacji</th>
  134 + <th>Miejsce publikacji</th>
  135 + {% if document|isinst:Magazine %}
  136 + <th>Numer</th>
  137 + {% elif document|isinst:BookWithMultipleAuthors %}
  138 + <th>Wydawca</th>
  139 + {% endif %}
  140 + <th>Kanał</th>
  141 + <th>Typ</th>
138 142 <th class="col-text-origin">Pochodzenie</th>
139 143 <th>Język oryginału</th>
140 144 </tr>
... ... @@ -145,15 +149,16 @@
145 149 <td>{{ document.title }}</td>
146 150 <td>{{ document.publication_date|default_if_none:'' }}</td>
147 151 <td>{{ document.publication_place }}</td>
148   - <td>{{ document.number }}</td>
  152 + {% if document|isinst:Magazine %}
  153 + <td>{{ document.number }}</td>
  154 + {% elif document|isinst:BookWithMultipleAuthors %}
  155 + <td>{{ document.publisher }}</td>
  156 + {% endif %}
149 157 <td>{{ document.channel }}</td>
150 158 <td>{{ document.type }}</td>
151 159 <td>{{ document.text_origin }}</td>
152 160 <td>{{ document.original_lang }}</td>
153 161 </tr>
154   - <tr>
155   - <td colspan="8"></td>
156   - </tr>
157 162 </tbody>
158 163 </table>
159 164  
... ...
collector/storage/templatetags/group_filter.py renamed to collector/storage/templatetags/filters.py
1 1 from django import template
  2 +from importlib import import_module
  3 +
  4 +from storage.models import Document, Magazine, BookWithMultipleAuthors
2 5  
3 6 register = template.Library()
4 7  
... ... @@ -6,3 +9,9 @@ register = template.Library()
6 9 @register.filter
7 10 def belongs_to_group(user, group_name):
8 11 return user.groups.filter(name=group_name).exists()
  12 +
  13 +
  14 +@register.filter
  15 +def isinst(obj, class_name):
  16 + split = class_name.split('.')
  17 + return isinstance(obj, getattr(import_module('.'.join(split[:-1])), split[-1]))
... ...
collector/storage/urls.py
... ... @@ -10,6 +10,10 @@ urlpatterns = [
10 10 name='reprocess_document'),
11 11 path('document/<str:doc_id>', views.DocumentView.as_view(), name='document'),
12 12 path('document/edit-details/<int:pk>', login_required(views.DocDetailsEditView.as_view()), name='edit_doc_details'),
  13 + path('document/edit-magazine-details/<int:pk>', login_required(views.MagazineDetailsEditView.as_view()),
  14 + name='edit_magazine_details'),
  15 + path('document/edit-bwma-details/<int:pk>', login_required(views.BWMADetailsEditView.as_view()),
  16 + name='edit_bwma_details'),
13 17 path('document/edit-subdoc-details/<int:pk>', login_required(views.SubDocDetailsEditView.as_view()),
14 18 name='edit_subdoc_details'),
15 19 path('chunk/add/<str:doc_id>', login_required(views.ChunkAddBetweenView.as_view()), name='add_chunk_between'),
... ... @@ -43,6 +47,7 @@ urlpatterns = [
43 47 path('keyword/edit/<str:doc_id>/<int:pk>', login_required(views.edit_keyword), name='edit_keyword'),
44 48 path('keyword/delete/<str:doc_id>/<int:pk>', login_required(views.delete_keyword), name='delete_keyword'),
45 49 path('split-doc/<int:pk>', login_required(views.DocSplitView.as_view()), name='split_doc'),
  50 + path('change-doc-type/<int:pk>', login_required(views.DocTypeView.as_view()), name='change_doc_type'),
46 51 path('move-subdoc/<str:subdoc_id>/<str:direction>', login_required(views.move_subdoc), name='move_subdoc'),
47 52 path('revert-subdoc-division/<int:pk>/', login_required(views.RevertSubdocDivisionView.as_view()),
48 53 name='revert_subdoc_division'),
... ...
collector/storage/views.py
... ... @@ -18,12 +18,14 @@ from django.forms import modelformset_factory, formset_factory
18 18 from django.db import transaction, IntegrityError
19 19  
20 20 from keras import backend
21   -from sys import maxsize
  21 +from sys import maxsize, modules
22 22 from functools import partial, wraps
23 23  
24   -from .forms import ChunkForm, ParticipantForm, SubchunkForm, MetadataForm, DocDetailsForm, KeywordForm, DocSplitForm, \
25   - ChunkMoveForm, SubDocDetailsForm, AuthorForm, ChunkMergeForm, ChunkSplitForm
26   -from .models import Chunk, Document, Participant, Metadata, Keyword, Annotation, Magazine, Article
  24 +from .forms import ChunkForm, ParticipantForm, SubchunkForm, MetadataForm, KeywordForm, DocSplitForm, ChunkMoveForm, \
  25 + SubDocDetailsForm, AuthorForm, ChunkMergeForm, ChunkSplitForm, DocTypeForm, DocDetailsForm, MagazineDetailsForm, \
  26 + BWMADetailsForm
  27 +from .models import Chunk, Document, Participant, Metadata, Keyword, Annotation, Magazine, BookWithMultipleAuthors
  28 +from .utils import get_remaining_doc_types_tuple, get_remaining_subdoc_types_tuple, get_doc_with_type, SUBDOCUMENT_TYPES
27 29 from projects.ppc.models import Utterance
28 30 from pipeline.models import ProcessingStatus
29 31  
... ... @@ -417,9 +419,9 @@ class ChunkMergeView(UpdateView):
417 419 for index, ch in enumerate(all_target_chunks):
418 420 if ch.id == self.object.id:
419 421 if index > 0:
420   - poss_target_chunks |= Chunk.objects.filter(pk=all_target_chunks[index-1].pk)
421   - if index < len(all_target_chunks)-1:
422   - poss_target_chunks |= Chunk.objects.filter(pk=all_target_chunks[index+1].pk)
  422 + poss_target_chunks |= Chunk.objects.filter(pk=all_target_chunks[index - 1].pk)
  423 + if index < len(all_target_chunks) - 1:
  424 + poss_target_chunks |= Chunk.objects.filter(pk=all_target_chunks[index + 1].pk)
423 425 break
424 426 kwargs['poss_target_chunks'] = poss_target_chunks
425 427 return kwargs
... ... @@ -630,9 +632,11 @@ class AnnotationView(View):
630 632 if 'doc_id' in request.GET:
631 633 doc_id = request.GET.get('doc_id')
632 634  
633   - context = {'document': None}
634   - try:
635   - doc = Document.objects.get(id=doc_id)
  635 + doc = None
  636 + context = {'document': doc}
  637 + doc = get_doc_with_type(doc_id)
  638 + if doc is not None:
  639 + doc_type = doc.get_doc_type_display()
636 640 subdocuments = Document.objects.filter(parent=doc).order_by('sequence')
637 641 metadata = doc.metadata.order_by('sequence')
638 642 chunks = doc.chunks.order_by('sequence')
... ... @@ -643,9 +647,8 @@ class AnnotationView(View):
643 647 'metadata': metadata,
644 648 'chunks': chunks,
645 649 'keywords': keywords,
646   - 'authors': authors}
647   - except Document.DoesNotExist:
648   - pass
  650 + 'authors': authors,
  651 + 'doc_type': doc_type}
649 652  
650 653 return render(request, self.template_name, context)
651 654  
... ... @@ -763,6 +766,16 @@ class DocDetailsEditView(UpdateView):
763 766 return '%s#doc-details' % (reverse_lazy('annotation', kwargs={'doc_id': self.object.id}))
764 767  
765 768  
  769 +class MagazineDetailsEditView(DocDetailsEditView):
  770 + model = Magazine
  771 + form_class = MagazineDetailsForm
  772 +
  773 +
  774 +class BWMADetailsEditView(DocDetailsEditView):
  775 + model = BookWithMultipleAuthors
  776 + form_class = BWMADetailsForm
  777 +
  778 +
766 779 class SubDocDetailsEditView(DocDetailsEditView):
767 780 form_class = SubDocDetailsForm
768 781  
... ... @@ -865,7 +878,7 @@ class FinishAnnotationView(RedirectView):
865 878 return reverse('annotation')
866 879  
867 880 def get(self, request, *args, **kwargs):
868   - document = Document.objects.get(id=kwargs['doc_id'])
  881 + document = get_doc_with_type(kwargs['doc_id'])
869 882 subdocuments = Document.objects.filter(parent=document)
870 883 if document.missing_translator():
871 884 messages.warning(request, 'Ostrzeżenie: Dokument posiada język oryginału inny niż polski, ale nie ma '
... ... @@ -878,7 +891,7 @@ class FinishAnnotationView(RedirectView):
878 891 'submit_btn_text': 'Zakończ'})
879 892  
880 893 def post(self, request, *args, **kwargs):
881   - document = Document.objects.get(id=kwargs['doc_id'])
  894 + document = get_doc_with_type(kwargs['doc_id'])
882 895 subdocuments = Document.objects.filter(parent=document)
883 896 if not document.check_details_filling():
884 897 messages.error(request, 'Błąd: Nie wypełniono wszystkich szczegółów dokumentu.')
... ... @@ -935,18 +948,20 @@ class DocSplitView(UpdateView):
935 948 parent = self.object
936 949 else:
937 950 parent = self.object.parent
938   - new_document = Document.objects.create(name=parent.name,
939   - lang=parent.lang,
940   - original_lang=parent.original_lang,
941   - pipeline=parent.pipeline,
942   - publication_date=None,
943   - publisher='',
944   - path=parent.path,
945   - type='',
946   - status='',
947   - parent=parent,
948   - processing_status=parent.processing_status,
949   - sequence=sequence + 1)
  951 + self.object = get_doc_with_type(self.object.id)
  952 + subdocument_class = SUBDOCUMENT_TYPES[type(self.object)][0]
  953 + print('sd class: ', subdocument_class)
  954 + new_document = subdocument_class.objects.create(name=parent.name,
  955 + lang=parent.lang,
  956 + original_lang=parent.original_lang,
  957 + pipeline=parent.pipeline,
  958 + publication_date=None,
  959 + path=parent.path,
  960 + type='',
  961 + status='',
  962 + parent=parent,
  963 + processing_status=parent.processing_status,
  964 + sequence=sequence + 1)
950 965 new_document.chunks.set(chunks.filter(sequence__range=(chunk_beg, chunk_end)))
951 966 new_document.save()
952 967 self.object.chunks.set(chunks.filter(sequence__lt=chunk_beg) | chunks.filter(sequence__gt=chunk_end))
... ... @@ -1110,107 +1125,6 @@ class DraftListView(ListView):
1110 1125  
1111 1126 def get_context_data(self, **kwargs):
1112 1127 context = super(DraftListView, self).get_context_data(**kwargs)
1113   -
1114   - main_documents = Document.objects.filter(parent=None)
1115   - for doc in main_documents:
1116   - magazine = Magazine.objects.create(name=doc.name,
1117   - source_id=doc.source_id,
1118   - lang=doc.lang,
1119   - original_lang=doc.original_lang,
1120   - pipeline=doc.pipeline,
1121   - image=doc.image,
1122   - broken_source=doc.broken_source,
1123   - in_effect=doc.in_effect,
1124   - indexed=doc.indexed,
1125   - changed=doc.changed,
1126   - title=doc.title,
1127   - publication_date=doc.publication_date,
1128   - publication_place=doc.publication_place,
1129   - number2=doc.number,
1130   - creation_time=doc.creation_time,
1131   - meta_url=doc.meta_url,
1132   - source_url=doc.source_url,
1133   - file_url=doc.file_url,
1134   - path=doc.path,
1135   - channel=doc.channel,
1136   - type=doc.type,
1137   - text_origin=doc.text_origin,
1138   - status=doc.status,
1139   - processing_status=doc.processing_status,
1140   - new=doc.new,
1141   - unk_coverage=doc.unk_coverage,
1142   - sequence=1000000)
1143   -
1144   - magazine.keywords.add(*doc.keywords.all())
1145   - for ch in doc.chunks.all():
1146   - ch.document = magazine
1147   - ch.save()
1148   - for m in doc.metadata.all():
1149   - m.document = magazine
1150   - m.save()
1151   - for p in doc.participants.all():
1152   - p.document = magazine
1153   - p.save()
1154   - for a in doc.annotations.all():
1155   - a.document = magazine
1156   - a.save()
1157   -
1158   -
1159   - subdocs = Document.objects.filter(parent=doc)
1160   - for subdoc in subdocs:
1161   - submagazine = Article.objects.create(name=subdoc.name,
1162   - source_id=subdoc.source_id,
1163   - lang=subdoc.lang,
1164   - original_lang=subdoc.original_lang,
1165   - pipeline=subdoc.pipeline,
1166   - image=subdoc.image,
1167   - broken_source=subdoc.broken_source,
1168   - in_effect=subdoc.in_effect,
1169   - indexed=subdoc.indexed,
1170   - changed=subdoc.changed,
1171   - title=subdoc.title,
1172   - publication_date=subdoc.publication_date,
1173   - publication_place=subdoc.publication_place,
1174   - creation_time=subdoc.creation_time,
1175   - meta_url=subdoc.meta_url,
1176   - source_url=subdoc.source_url,
1177   - file_url=subdoc.file_url,
1178   - path=subdoc.path,
1179   - channel=subdoc.channel,
1180   - type=subdoc.type,
1181   - text_origin=subdoc.text_origin,
1182   - status=subdoc.status,
1183   - processing_status=subdoc.processing_status,
1184   - new=subdoc.new,
1185   - unk_coverage=subdoc.unk_coverage,
1186   - parent=magazine,
1187   - sequence=1000001)
1188   - submagazine.keywords.add(*subdoc.keywords.all())
1189   - for ch in subdoc.chunks.all():
1190   - ch.document = submagazine
1191   - ch.save()
1192   - for m in subdoc.metadata.all():
1193   - m.document = submagazine
1194   - m.save()
1195   - for p in subdoc.participants.all():
1196   - p.document = submagazine
1197   - p.save()
1198   - for a in subdoc.annotations.all():
1199   - a.document = submagazine
1200   - a.save()
1201   - seq = subdoc.sequence
1202   - subdoc.delete()
1203   - submagazine.sequence = seq
1204   - submagazine.save()
1205   -
1206   - seq = doc.sequence
1207   - doc.delete()
1208   - magazine.sequence = seq
1209   - magazine.save()
1210   -
1211   -
1212   -
1213   -
1214 1128 drafts = [ann.document for ann in
1215 1129 Annotation.objects.filter(user=self.request.user, finished=False).order_by('start_time')
1216 1130 ]
... ... @@ -1218,6 +1132,100 @@ class DraftListView(ListView):
1218 1132 return context
1219 1133  
1220 1134  
  1135 +def change_doc_type(doc, target_type):
  1136 + new_doc = target_type.objects.create(name=doc.name,
  1137 + source_id=doc.source_id,
  1138 + lang=doc.lang,
  1139 + original_lang=doc.original_lang,
  1140 + pipeline=doc.pipeline,
  1141 + image=doc.image,
  1142 + broken_source=doc.broken_source,
  1143 + in_effect=doc.in_effect,
  1144 + indexed=doc.indexed,
  1145 + changed=doc.changed,
  1146 + title=doc.title,
  1147 + publication_date=doc.publication_date,
  1148 + publication_place=doc.publication_place,
  1149 + creation_time=doc.creation_time,
  1150 + meta_url=doc.meta_url,
  1151 + source_url=doc.source_url,
  1152 + file_url=doc.file_url,
  1153 + path=doc.path,
  1154 + channel=doc.channel,
  1155 + type=doc.type,
  1156 + text_origin=doc.text_origin,
  1157 + status=doc.status,
  1158 + processing_status=doc.processing_status,
  1159 + new=doc.new,
  1160 + unk_coverage=doc.unk_coverage,
  1161 + sequence=1000000)
  1162 + seq = doc.sequence
  1163 + new_doc.keywords.add(*doc.keywords.all())
  1164 + subdocs = Document.objects.filter(parent=doc)
  1165 + for subdoc in subdocs:
  1166 + subdoc.parent = new_doc
  1167 + subdoc.save()
  1168 + for ch in doc.chunks.all():
  1169 + ch.document = new_doc
  1170 + ch.save()
  1171 + for m in doc.metadata.all():
  1172 + m.document = new_doc
  1173 + m.save()
  1174 + for p in doc.participants.all():
  1175 + p.document = new_doc
  1176 + p.save()
  1177 + for a in doc.annotations.all():
  1178 + a.document = new_doc
  1179 + a.save()
  1180 +
  1181 + doc.delete()
  1182 + new_doc.sequence = seq
  1183 + new_doc.save()
  1184 +
  1185 + return new_doc
  1186 +
  1187 +
  1188 +class DocTypeView(UpdateView):
  1189 + model = Document
  1190 + template_name = 'storage/edit.html'
  1191 + form_class = DocTypeForm
  1192 +
  1193 + def form_valid(self, form):
  1194 + if not self.request.is_ajax():
  1195 + doc_type = form.cleaned_data['doc_type']
  1196 + new_doc = change_doc_type(self.object, getattr(modules[__name__], doc_type))
  1197 + return HttpResponseRedirect(self.get_success_url(new_doc))
  1198 + return render(self.request, self.template_name, {'form': form})
  1199 +
  1200 + def get_context_data(self, **kwargs):
  1201 + context = super().get_context_data(**kwargs)
  1202 + context['title'] = 'Zmiana typu dokumentu'
  1203 + context['submit_btn_text'] = 'Zmień'
  1204 + if self.object.parent is None:
  1205 + messages.warning(self.request, 'Uwaga! Zmiana typu dokumentu głównego nie powoduje zmiany typów '
  1206 + 'poddokumentów. Można je zmienić nastomiast manualnie.')
  1207 + messages.warning(self.request, 'Uwaga! Zmiana typu dokumentu może spowodować usunięcie danych typowych dla '
  1208 + 'tego typu.')
  1209 + return context
  1210 +
  1211 + def get_form_kwargs(self):
  1212 + kwargs = super(DocTypeView, self).get_form_kwargs()
  1213 + self.object = get_doc_with_type(self.object.id)
  1214 + if self.object.parent is None:
  1215 + doc_types = get_remaining_doc_types_tuple(type(self.object))
  1216 + else:
  1217 + doc_types = get_remaining_subdoc_types_tuple(type(get_doc_with_type(self.object.parent.id)),
  1218 + type(self.object))
  1219 + if not doc_types:
  1220 + messages.error(self.request, 'Nie jest możliwa zmiana typu dokumentu. Dla tego typu dokumentu głównego nie '
  1221 + 'ma dostępnych innych typów dokumentów.')
  1222 + kwargs['doc_types'] = doc_types
  1223 + return kwargs
  1224 +
  1225 + def get_success_url(self, new_doc):
  1226 + return reverse_lazy('annotation', kwargs={'doc_id': new_doc.id})
  1227 +
  1228 +
1221 1229 # ****************************** autocomplete ******************************
1222 1230  
1223 1231  
... ...