From 4f1e04af998a341a60876cd73b43b3d334fb27da Mon Sep 17 00:00:00 2001 From: Tomas 'Jethro' Pokorny Date: Wed, 2 Dec 2015 01:01:24 +0100 Subject: [PATCH] Funguje mazani, upravy a done/undone. Lehce rozbite je zvyraznovani car, chce to prozkoumat JS. --- korektury/templates/korektury/opraf.html | 17 +++++--- korektury/views.py | 49 +++++++++++++++++++----- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/korektury/templates/korektury/opraf.html b/korektury/templates/korektury/opraf.html index 75d80b7f..9013ce53 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -54,23 +54,28 @@ {% for o in opravy %} -
-
+
+
+
{{o.autor}}
+ {% csrf_token %} - + - + {% if o.status = 'opraveno' %} + {% else %} + + {% endif %} - +
@@ -94,4 +99,6 @@ {{ form_oprava.as_p }} + + diff --git a/korektury/views.py b/korektury/views.py index 673d94d8..14f95b57 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -30,17 +30,46 @@ class KorekturyView(generic.TemplateView): def post(self, request, *args, **kwargs): form = self.form_class(request.POST) q = request.POST - x = int(q.get('x')) - y = int(q.get('y')) - autor = q.get('au') - text = q.get('txt') - strana = int(q.get('img-id')[4:]) - scroll = q.get('scroll') - - oprava = Oprava(x=x,y=y, autor=autor, text=text, strana=strana) - oprava.save() + + + action = q.get('action') + if (action == u''): # Přidej + x = int(q.get('x')) + y = int(q.get('y')) + autor = q.get('au') + text = q.get('txt') + strana = int(q.get('img-id')[4:]) + scroll = q.get('scroll') + + op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana) + op.save() + elif (action == u'del'): + id = int(q.get('id')) + op = Oprava.objects.filter(id=id).first() + op.delete() + elif (action == u'update'): + id = int(q.get('id')) + op = Oprava.objects.filter(id=id).first() + autor = q.get('au') + text = q.get('txt') + op.autor = autor + op.text = text + op.save() + elif (action == u'undone'): + id = int(q.get('id')) + op = Oprava.objects.filter(id=id).first() + op.status = op.STATUS_K_OPRAVE + op.save() + elif (action == u'done'): + id = int(q.get('id')) + op = Oprava.objects.filter(id=id).first() + op.status = op.STATUS_OPRAVENO + op.save() + + return HttpResponse(u'Oprav: %d, akce: %s'%( + len(Oprava.objects.all()),action)) - return HttpResponseRedirect(reverse('korektury')+"?scroll=%s"%(scroll)) +# return HttpResponseRedirect(reverse('korektury')+"?scroll=%s"%(scroll)) # return render(request, 'seminar/opraf.html',self.get_context_data()) # return HttpResponse(u'Oprav: %d,x: %d y: %d, autor: %s, text: %s, strana: %d'%( # len(Oprava.objects.all()),x,y,autor,text,strana))