Browse Source

Pridano ruseni vsech komentaru, zasluhy a pamet autora.

Vetsina formularu si pamatuje posledniho autora.
Nefunguje editace, ale aspon se zobrazi okno.
remotes/origin/opraf
parent
commit
0915838f26
  1. 28
      korektury/templates/korektury/opraf.html
  2. 40
      korektury/views.py

28
korektury/templates/korektury/opraf.html

@ -17,9 +17,9 @@
<div id="commform-div"> <div id="commform-div">
<form action='' onsubmit='save_scroll(this)' id="commform" method="POST"> <form action='' onsubmit='save_scroll(this)' id="commform" method="POST">
{% csrf_token %} {% csrf_token %}
<input size="8" name="au" value="anonym"/> <input size="8" name="au" value="{{autor}}"/>
<input type=submit value="Oprav!"/> <input type=submit value="Oprav!"/>
<button type="button" onclick="close_commform()">Zavøít</button> <button type="button" onclick="close_commform()">Zavřít</button>
<br/> <br/>
<textarea onkeypress="textarea_onkey(event);" id="commform-text" cols=40 rows=10 name="txt"></textarea> <textarea onkeypress="textarea_onkey(event);" id="commform-text" cols=40 rows=10 name="txt"></textarea>
<br/> <br/>
@ -38,16 +38,15 @@
{% endfor %} {% endfor %}
<form method="post"> <form method="post">
{% csrf_token %}
<input type='hidden' name='action' value='delall'/> <input type='hidden' name='action' value='delall'/>
<input type='submit' value='Smazat v¹echny komentáøe'/> <input type='submit' value='Smazat všechny komentáře'/>
<input type='hidden' name='pdf' value='{{pdf.id}}'/> <input type='hidden' name='pdf' value='{{pdf.id}}'/>
<input type='checkbox' name='yes'/> Souhlasím se smazáním v¹ech kometáøù <input type='checkbox' name='yes'/> Souhlasím se smazáním všech kometářů
</form> </form>
<hr/> <hr/>
Dìkujeme opravovatelùm: Marble(4), zuzka(4), Matìj(2), O(N)dra(2), Va¹ek(1), Kristý(1), Tonda(1), Jethro(1), Pe»a(1), ML(1), Lucka(1) <hr> Děkujeme opravovatelům: {% for autor,pocet in zasluhy.items %} {{autor}}({{pocet}}) {% endfor %}<hr>
@ -64,7 +63,8 @@
<div class='author'>{{o.autor}}</div> <div class='author'>{{o.autor}}</div>
<div class='float-right'> <div class='float-right'>
<form action='' onsubmit='save_scroll(this)' method='POST'> <form action='' onsubmit='save_scroll(this)' method='POST'>
{% csrf_token %} {% csrf_token %}
<input type='hidden' name="au" value="{{autor}}"/>
<input type='hidden' name='pdf' value='{{pdf.id}}'> <input type='hidden' name='pdf' value='{{pdf.id}}'>
<input type='hidden' name='id' value='{{o.id}}'> <input type='hidden' name='id' value='{{o.id}}'>
<input type='hidden' name='scroll'> <input type='hidden' name='scroll'>
@ -106,7 +106,7 @@
<img src="/static/korektury/imgs/link.png"/> <img src="/static/korektury/imgs/link.png"/>
</button></a> </button></a>
<button><a href='#op579'> <button><a href='#op579'>
<img title='Dal¹í oprava' src="/static/korektury/imgs/next.png"/> <img title='Další oprava' src="/static/korektury/imgs/next.png"/>
</a></button> </a></button>
</form> </form>
@ -133,7 +133,7 @@
<img src="/static/korektury/imgs/edit.png"/></button> <img src="/static/korektury/imgs/edit.png"/></button>
</div> </div>
</div> </div>
<div id='kt{{k.id}}'>{{k.text}}</div> <div id='kt{{k.id}}'>{{k.text}}</div>
</div> </div>
{% endfor %} {% endfor %}
@ -155,6 +155,12 @@
{{ form_oprava.as_p }} {{ form_oprava.as_p }}
<input type='submit' value='Odeslat'/> <input type='submit' value='Odeslat'/>
</form> </form>
{% if scroll %}
<script>
window.scrollTo(0,{{scroll}});
</script>
{% endif %}
</body> </html> </body>
</html>

40
korektury/views.py

@ -35,16 +35,20 @@ class KorekturyView(generic.TemplateView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = self.form_class(request.POST) form = self.form_class(request.POST)
q = request.POST q = request.POST
scroll = q.get('scroll')
autor = q.get('au')
if not autor:
autor = 'anonym'
if not scroll:
scroll = 0
action = q.get('action') action = q.get('action')
if (action == u''): # Přidej if (action == u''): # Přidej
x = int(q.get('x')) x = int(q.get('x'))
y = int(q.get('y')) y = int(q.get('y'))
autor = q.get('au')
text = q.get('txt') text = q.get('txt')
strana = int(q.get('img-id')[4:]) strana = int(q.get('img-id')[4:])
scroll = q.get('scroll')
pdf = KorekturovanePDF.objects.filter(id=q.get('pdf')).first() pdf = KorekturovanePDF.objects.filter(id=q.get('pdf')).first()
op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf) op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf)
@ -82,14 +86,26 @@ class KorekturyView(generic.TemplateView):
id = int(q.get('id')) id = int(q.get('id'))
kom = Komentar.objects.filter(id=id).first() kom = Komentar.objects.filter(id=id).first()
kom.delete() kom.delete()
elif (action == u'delall'):
pdf = KorekturovanePDF.objects.filter(id=q.get('pdf'))
checked = q.get('yes')
if checked:
opravy = Oprava.objects.filter(pdf=pdf)
komentare = Komentar.objects.filter(oprava=opravy)
opravy.delete()
komentare.delete()
# return HttpResponse(u'Keys: %s '%(q.iteitems())) # return HttpResponse(u'Keys: %s '%(q.iteitems()))
return HttpResponse(u'Oprav: %d, akce: %s'%( # return HttpResponse(u'Oprav: %d, akce: %s'%(
len(Oprava.objects.all()),action)) # 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()) context = self.get_context_data()
context['scroll'] = scroll
context['autor'] = autor
return render(request, 'korektury/opraf.html',context)
# return HttpResponse(u'Oprav: %d,x: %d y: %d, autor: %s, text: %s, strana: %d'%( # return HttpResponse(u'Oprav: %d,x: %d y: %d, autor: %s, text: %s, strana: %d'%(
# len(Oprava.objects.all()),x,y,autor,text,strana)) # len(Oprava.objects.all()),x,y,autor,text,strana))
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -98,12 +114,24 @@ class KorekturyView(generic.TemplateView):
context['pdf'] = pdf context['pdf'] = pdf
context['img_name'] = os.path.split(pdf.pdf.path)[1].split('.')[0] context['img_name'] = os.path.split(pdf.pdf.path)[1].split('.')[0]
context['img_path'] = settings.KOREKTURY_IMG_DIR context['img_path'] = settings.KOREKTURY_IMG_DIR
context['img_indexes'] = range(27) context['img_indexes'] = range(pdf.stran)
context['form_oprava'] = OpravaForm() context['form_oprava'] = OpravaForm()
opravy = Oprava.objects.filter(pdf=self.kwargs['pdf']) opravy = Oprava.objects.filter(pdf=self.kwargs['pdf'])
zasluhy = {}
for o in opravy: for o in opravy:
if o.autor in zasluhy:
zasluhy[o.autor]+=1
else:
zasluhy[o.autor]=1
o.komentare = o.komentar_set.all() o.komentare = o.komentar_set.all()
for k in o.komentare:
if o.autor in zasluhy:
zasluhy[k.autor]+=1
else:
zasluhy[k.autor]=1
context['opravy'] = opravy context['opravy'] = opravy
context['zasluhy'] = zasluhy
return context return context
def form_valid(self,form): def form_valid(self,form):
return super(KorekturyView,self).form_valid(form) return super(KorekturyView,self).form_valid(form)

Loading…
Cancel
Save