|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.conf import settings
|
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
from django.utils.encoding import force_unicode
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import reversion
|
|
|
|
|
|
|
|
# PrilohaReseni method
|
|
|
|
def generate_filename(self, filename):
|
|
|
|
clean = filename.replace('/','-').replace('\0', '').replace(":","_")
|
|
|
|
fname = "%s_%s" % (
|
|
|
|
timezone.now().strftime('%Y-%m-%d-%H_%M'),
|
|
|
|
clean)
|
|
|
|
return os.path.join(settings.KOREKTURY_PDF_DIR, fname)
|
|
|
|
|
|
|
|
|
|
|
|
#@reversion.register(ignore_duplicate_revision=True)
|
|
|
|
#@python_2_unicode_compatible
|
|
|
|
class KorekturovanePDF(models.Model):
|
|
|
|
class Meta:
|
|
|
|
db_table = 'korekturovane_cislo'
|
|
|
|
verbose_name = u'PDF k opravám'
|
|
|
|
verbose_name_plural = u'PDF k opravám'
|
|
|
|
|
|
|
|
#Interní ID
|
|
|
|
id = models.AutoField(primary_key = True)
|
|
|
|
|
|
|
|
cas = models.DateTimeField(u'čas vložení PDF',default=timezone.now,help_text = 'Čas vložení PDF')
|
|
|
|
|
|
|
|
nazev = models.CharField(u'název PDF',blank = True,max_length=50, help_text='Název (např. 22.1 verze 4) korekturovaného PDF')
|
|
|
|
|
|
|
|
komentar = models.TextField(u'komentář k PDF',blank = True, help_text='Komentář ke korekturovanému PDF (např. na co se zaměřit)')
|
|
|
|
|
|
|
|
pdf = models.FileField(u'PDF', upload_to = generate_filename)
|
|
|
|
|
|
|
|
stran = models.IntegerField(u'počet stran', help_text = 'Počet stran PDF', default = 0)
|
|
|
|
STATUS_PRIDAVANI = 'pridavani'
|
|
|
|
STATUS_ZANASENI = 'zanaseni'
|
|
|
|
STATUS_ZASTARALE = 'zastarale'
|
|
|
|
STATUS_CHOICES = (
|
|
|
|
(STATUS_PRIDAVANI, u'Přidávání korektur'),
|
|
|
|
(STATUS_ZANASENI, u'Korektury jsou zanášeny'),
|
|
|
|
(STATUS_ZASTARALE, u'Stará verze, nekorigovat'),
|
|
|
|
)
|
|
|
|
status = models.CharField(u'stav PDF',max_length=16, choices=STATUS_CHOICES, blank=False,
|
|
|
|
default = STATUS_PRIDAVANI)
|
|
|
|
|
|
|
|
|
|
|
|
#TODO Nepovinný foreign key k číslu
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
# Pokud se nezmenilo PDF, tak nepregenerovavej nahledy
|
|
|
|
try:
|
|
|
|
original = KorekturovanePDF.objects.get(pk=self.pk)
|
|
|
|
if original.pdf == self.pdf:
|
|
|
|
super(KorekturovanePDF, self).save()
|
|
|
|
return
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
pass
|
|
|
|
super(KorekturovanePDF, self).save()
|
|
|
|
print("\nSaving")
|
|
|
|
print(self.pdf.path)
|
|
|
|
print(self.pdf.url)
|
|
|
|
filename = os.path.split(self.pdf.file.name)[1].split(".")[0]
|
|
|
|
try:
|
|
|
|
os.listdir(settings.KOREKTURY_IMG_DIR)
|
|
|
|
except OSError:
|
|
|
|
os.mkdir(settings.KOREKTURY_IMG_DIR)
|
|
|
|
while True:
|
|
|
|
res = subprocess.call([
|
|
|
|
"convert",
|
|
|
|
"-density","180x180",
|
|
|
|
"-geometry"," 1024x1448",
|
|
|
|
self.pdf.path+"[%d]"%self.stran,
|
|
|
|
os.path.join(settings.KOREKTURY_IMG_DIR, "%s-%d.png"%(filename,self.stran))])
|
|
|
|
if res==1:
|
|
|
|
break
|
|
|
|
self.stran +=1
|
|
|
|
super(KorekturovanePDF, self).save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@reversion.register(ignore_duplicate_revision=True)
|
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Oprava(models.Model):
|
|
|
|
class Meta:
|
|
|
|
db_table = 'opravy'
|
|
|
|
verbose_name = u'Oprava'
|
|
|
|
verbose_name_plural = u'Opravy'
|
|
|
|
ordering = ['y','x']
|
|
|
|
|
|
|
|
#Interní ID
|
|
|
|
id = models.AutoField(primary_key = True)
|
|
|
|
|
|
|
|
pdf = models.ForeignKey(KorekturovanePDF, default=-1)
|
|
|
|
|
|
|
|
strana = models.IntegerField(u'strana s opravou', help_text='Strana s opravou (od 0)')
|
|
|
|
|
|
|
|
x = models.IntegerField(u'x-ová souřadnice bugu')
|
|
|
|
y = models.IntegerField(u'y-ová souřadnice bugu')
|
|
|
|
|
|
|
|
STATUS_K_OPRAVE = 'k_oprave'
|
|
|
|
STATUS_OPRAVENO = 'opraveno'
|
|
|
|
STATUS_NENI_CHYBA = 'neni_chyba'
|
|
|
|
STATUS_K_REAKCI = 'k_reakci'
|
|
|
|
STATUS_CHOICES = (
|
|
|
|
(STATUS_K_OPRAVE, u'K opravě'),
|
|
|
|
(STATUS_OPRAVENO, u'Opraveno'),
|
|
|
|
(STATUS_NENI_CHYBA, u'Není chyba'),
|
|
|
|
(STATUS_K_REAKCI, u'K reakci autora textu'),
|
|
|
|
)
|
|
|
|
status = models.CharField(u'stav opravy',max_length=16, choices=STATUS_CHOICES, blank=False,
|
|
|
|
default = STATUS_K_OPRAVE)
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: Změnit na cizí klíč do orgů
|
|
|
|
autor = models.CharField(u'autor opravy',blank = True,max_length=20, help_text='Autor opravy')
|
|
|
|
|
|
|
|
text = models.TextField(u'text opravy',blank = True, help_text='Text opravy')
|
|
|
|
|
|
|
|
# def __init__(self,dictionary):
|
|
|
|
# for k,v in dictionary.items():
|
|
|
|
# setattr(self,k,v)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return force_unicode(u'%s od %s: %s'%(self.status,self.autor,self.text))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@reversion.register(ignore_duplicate_revision=True)
|
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Komentar(models.Model):
|
|
|
|
class Meta:
|
|
|
|
db_table = 'komentare'
|
|
|
|
verbose_name = u'Komentář k opravě'
|
|
|
|
verbose_name_plural = u'Komentáře k opravě'
|
|
|
|
ordering = ['cas']
|
|
|
|
|
|
|
|
#Interní ID
|
|
|
|
id = models.AutoField(primary_key = True)
|
|
|
|
|
|
|
|
cas = models.DateTimeField(u'čas komentáře',default=timezone.now,help_text = 'Čas zadání komentáře')
|
|
|
|
|
|
|
|
oprava = models.ForeignKey(Oprava)
|
|
|
|
# TODO: Změnit na cizí klíč do orgů
|
|
|
|
autor = models.CharField(u'autor komentáře',blank = True,max_length=20, help_text='Autor komentáře')
|
|
|
|
|
|
|
|
text = models.TextField(u'text komentáře',blank = True, help_text='Text komentáře')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return force_unicode(u'%s od %s: %s'%(self.cas,self.autor,self.text))
|
|
|
|
|
|
|
|
|
|
|
|
|