|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.views import generic
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.http import Http404
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
|
|
|
|
from .models import Oprava
|
|
|
|
from .forms import OpravaForm
|
|
|
|
|
|
|
|
from datetime import timedelta, date, datetime
|
|
|
|
from itertools import groupby
|
|
|
|
import tempfile
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
from django.conf import settings
|
|
|
|
import unicodedata
|
|
|
|
|
|
|
|
### Korektury
|
|
|
|
class KorekturyView(generic.TemplateView):
|
|
|
|
model = Oprava
|
|
|
|
template_name = 'korektury/opraf.html'
|
|
|
|
form_class = OpravaForm
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
q = request.POST
|
|
|
|
|
|
|
|
|
|
|
|
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 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))
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(KorekturyView,self).get_context_data(**kwargs)
|
|
|
|
context['img_name'] = "22_3_verze5"
|
|
|
|
context['img_indexes'] = range(27)
|
|
|
|
context['form_oprava'] = OpravaForm()
|
|
|
|
context['opravy'] = Oprava.objects.all()
|
|
|
|
return context
|
|
|
|
def form_valid(self,form):
|
|
|
|
return super(KorekturyView,self).form_valid(form)
|
|
|
|
|