From 0d653acd2e274df0a3881be42a244ba45e9cc733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Wed, 19 Feb 2025 17:05:04 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Maz=C3=A1n=C3=AD=20korektur=20a=20koment?= =?UTF-8?q?=C3=A1=C5=99=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/api/urls.py | 2 ++ korektury/api/views.py | 22 ++++++++++++++++++- .../korektury/korekturovatko/__komentar.html | 10 ++++++++- .../korektury/korekturovatko/__oprava.html | 10 ++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/korektury/api/urls.py b/korektury/api/urls.py index eb74d90f..5c1e1bc3 100644 --- a/korektury/api/urls.py +++ b/korektury/api/urls.py @@ -6,4 +6,6 @@ urlpatterns = [ path('/stav', org_required(views.korektury_stav_view), name='korektury_api_pdf_stav'), path('oprava/stav', org_required(views.oprava_stav_view), name='korektury_api_oprava_stav'), path('/opravy_a_komentare', org_required(views.opravy_a_komentare_view), name='korektury_api_opravy_a_komentare'), + path('oprava/smaz', org_required(views.oprava_smaz_view), name='korektury_api_oprava_smaz'), + path('komentar/smaz', org_required(views.komentar_smaz_view), name='korektury_api_komentar_smaz'), ] diff --git a/korektury/api/views.py b/korektury/api/views.py index 560abfad..dff32f19 100644 --- a/korektury/api/views.py +++ b/korektury/api/views.py @@ -1,4 +1,6 @@ -from django.http import HttpResponseForbidden, JsonResponse +from http import HTTPStatus + +from django.http import HttpResponseForbidden, JsonResponse, HttpResponse from django.shortcuts import get_object_or_404 from django.utils.html import linebreaks from django.views.decorators.csrf import csrf_exempt @@ -34,6 +36,24 @@ def oprava_stav_view(request, **kwargs): op.save() return JsonResponse({'status': op.status}) +def oprava_smaz_view(request, **kwargs): + q = request.POST + op_id_str = q.get('oprava_id') + assert op_id_str is not None + op_id = int(op_id_str) + oprava = get_object_or_404(Oprava, id=op_id) + oprava.delete() + return HttpResponse(status=HTTPStatus.NO_CONTENT) + +def komentar_smaz_view(request, **kwargs): + q = request.POST + kom_id_str = q.get('komentar_id') + assert kom_id_str is not None + kom_id = int(kom_id_str) + komentar = get_object_or_404(Komentar, id=kom_id) + komentar.delete() + return HttpResponse(status=HTTPStatus.NO_CONTENT) + class KomentarSerializer(serializers.ModelSerializer): class Meta: model = Komentar diff --git a/korektury/templates/korektury/korekturovatko/__komentar.html b/korektury/templates/korektury/korekturovatko/__komentar.html index e9aed2d2..5f6309bc 100644 --- a/korektury/templates/korektury/korekturovatko/__komentar.html +++ b/korektury/templates/korektury/korekturovatko/__komentar.html @@ -84,7 +84,15 @@ #delete_comment() { if (confirm('Opravdu smazat komentář?')) { - throw {name : 'NotImplementedError', message: '(Webaři jsou) too lazy to implement'}; + const data = new FormData(CSRF_FORM); + data.append('komentar_id', this.id); + fetch('{% url "korektury_api_komentar_smaz" %}', {method: 'POST', body: data}) + .then(response => { + if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);} + this.htmlElement.remove(); + place_comments(); + }) + .catch(error => {alert('Něco se nepovedlo:' + error);}); } } } diff --git a/korektury/templates/korektury/korekturovatko/__oprava.html b/korektury/templates/korektury/korekturovatko/__oprava.html index 85b17262..0304f524 100644 --- a/korektury/templates/korektury/korekturovatko/__oprava.html +++ b/korektury/templates/korektury/korekturovatko/__oprava.html @@ -161,7 +161,15 @@ #delete() { if (confirm('Opravdu smazat korekturu?')) { - throw {name : 'NotImplementedError', message: '(Webaři jsou) too lazy to implement'}; + const data = new FormData(CSRF_FORM); + data.append('oprava_id', this.id); + fetch('{% url "korektury_api_oprava_smaz" %}', {method: 'POST', body: data}) + .then(response => { + if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);} + comments[this.img_id].splice(comments[this.img_id].indexOf(this), 1); + place_comments(); + }) + .catch(error => {alert('Něco se nepovedlo:' + error);}); } } } From cb8f0aab18172280c37b122cfb177c6b657f888c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Wed, 19 Feb 2025 17:06:07 +0100 Subject: [PATCH 2/2] =?UTF-8?q?
=20uvnit=C5=99=20divu=20koment=C3=A1?= =?UTF-8?q?=C5=99e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/korektury/korekturovatko/__komentar.html | 2 ++ korektury/templates/korektury/korekturovatko/__oprava.html | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/korektury/templates/korektury/korekturovatko/__komentar.html b/korektury/templates/korektury/korekturovatko/__komentar.html index 5f6309bc..eaeb1171 100644 --- a/korektury/templates/korektury/korekturovatko/__komentar.html +++ b/korektury/templates/korektury/korekturovatko/__komentar.html @@ -17,6 +17,8 @@
{# {{k.text|linebreaks}} #}
+ +
diff --git a/korektury/templates/korektury/korekturovatko/__oprava.html b/korektury/templates/korektury/korekturovatko/__oprava.html index 0304f524..78f3a829 100644 --- a/korektury/templates/korektury/korekturovatko/__oprava.html +++ b/korektury/templates/korektury/korekturovatko/__oprava.html @@ -16,7 +16,7 @@
- {# {% for k in o.komentare %} {% include "korektury/korekturovatko/__komentar.html" %}
{% endfor %} #} + {# {% for k in o.komentare %} {% include "korektury/korekturovatko/__komentar.html" %} {% endfor %} #}
@@ -125,10 +125,7 @@ this.pointer.dataset.opravastatus=status; }; - add_komentar_htmlElement(htmlElement) { - this.#komentare.appendChild(htmlElement); - this.#komentare.appendChild(document.createElement('hr')); - } + add_komentar_htmlElement(htmlElement) { this.#komentare.appendChild(htmlElement); }