diff --git a/korektury/admin.py b/korektury/admin.py index 8c38f3f3..564e2cd0 100644 --- a/korektury/admin.py +++ b/korektury/admin.py @@ -1,3 +1,16 @@ from django.contrib import admin +from reversion.admin import VersionAdmin +from korektury.models import KorekturovanePDF # Register your models here. +class KorekturovanePDFAdmin(VersionAdmin): + readonly_fields = ['cas', 'stran'] + fieldsets = [ + (None, {'fields': ['pdf', 'cas', 'stran', 'nazev', 'komentar']}), +# (u'PDF', {'fields': ['pdf']}), + ] + list_display = ['pdf', 'cas', 'stran'] + list_filter = [] + search_fields = [] + +admin.site.register(KorekturovanePDF, KorekturovanePDFAdmin) diff --git a/korektury/migrations/0003_auto_20151204_1855.py b/korektury/migrations/0003_auto_20151204_1855.py new file mode 100644 index 00000000..8f8cb70b --- /dev/null +++ b/korektury/migrations/0003_auto_20151204_1855.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0002_auto_20151202_2351'), + ] + + operations = [ + migrations.AddField( + model_name='korekturovanepdf', + name='cas', + field=models.DateTimeField(default=django.utils.timezone.now, help_text=b'\xc4\x8cas vlo\xc5\xbeen\xc3\xad PDF', verbose_name='\u010das vlo\u017een\xed PDF'), + preserve_default=True, + ), + migrations.AddField( + model_name='korekturovanepdf', + name='stran', + field=models.IntegerField(default=0, help_text=b'Po\xc4\x8det stran PDF', verbose_name='po\u010det stran'), + preserve_default=True, + ), + ] diff --git a/korektury/migrations/0004_auto_20151204_2240.py b/korektury/migrations/0004_auto_20151204_2240.py new file mode 100644 index 00000000..ed47ccaf --- /dev/null +++ b/korektury/migrations/0004_auto_20151204_2240.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0003_auto_20151204_1855'), + ] + + operations = [ + migrations.AddField( + model_name='korekturovanepdf', + name='komentar', + field=models.TextField(help_text=b'Koment\xc3\xa1\xc5\x99 ke korekturovan\xc3\xa9mu PDF (nap\xc5\x99. na co se zam\xc4\x9b\xc5\x99it)', verbose_name='koment\xe1\u0159 k PDF', blank=True), + preserve_default=True, + ), + migrations.AddField( + model_name='korekturovanepdf', + name='nazev', + field=models.TextField(help_text=b'N\xc3\xa1zev (nap\xc5\x99. 22.1 verze 4) korekturovan\xc3\xa9ho PDF', verbose_name='n\xe1zev PDF', blank=True), + preserve_default=True, + ), + ] diff --git a/korektury/migrations/0005_auto_20151204_2244.py b/korektury/migrations/0005_auto_20151204_2244.py new file mode 100644 index 00000000..52ebdfb6 --- /dev/null +++ b/korektury/migrations/0005_auto_20151204_2244.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0004_auto_20151204_2240'), + ] + + operations = [ + migrations.AlterField( + model_name='komentar', + name='autor', + field=models.CharField(help_text=b'Autor koment\xc3\xa1\xc5\x99e', max_length=20, verbose_name='autor koment\xe1\u0159e', blank=True), + preserve_default=True, + ), + migrations.AlterField( + model_name='korekturovanepdf', + name='nazev', + field=models.CharField(help_text=b'N\xc3\xa1zev (nap\xc5\x99. 22.1 verze 4) korekturovan\xc3\xa9ho PDF', max_length=50, verbose_name='n\xe1zev PDF', blank=True), + preserve_default=True, + ), + migrations.AlterField( + model_name='oprava', + name='autor', + field=models.CharField(help_text=b'Autor opravy', max_length=20, verbose_name='autor opravy', blank=True), + preserve_default=True, + ), + ] diff --git a/korektury/migrations/0006_oprava_pdf.py b/korektury/migrations/0006_oprava_pdf.py new file mode 100644 index 00000000..2adf04e7 --- /dev/null +++ b/korektury/migrations/0006_oprava_pdf.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0005_auto_20151204_2244'), + ] + + operations = [ + migrations.AddField( + model_name='oprava', + name='pdf', + field=models.ForeignKey(default=-1, to='korektury.KorekturovanePDF'), + preserve_default=True, + ), + ] diff --git a/korektury/models.py b/korektury/models.py index 80655739..75593af3 100644 --- a/korektury/models.py +++ b/korektury/models.py @@ -13,8 +13,8 @@ from django.core.cache import cache from imagekit.models import ImageSpecField, ProcessedImageField from imagekit.processors import ResizeToFit, Transpose -from PIL import Image import os +import subprocess from cStringIO import StringIO from django.core.files.base import ContentFile @@ -26,12 +26,11 @@ import reversion # PrilohaReseni method def generate_filename(self, filename): - clean = filename.replace('/','-').replace('\0', '') - datedir = timezone.now().strftime('%Y-%m') + clean = filename.replace('/','-').replace('\0', '').replace(":","_") fname = "%s_%s" % ( - timezone.now().strftime('%Y-%m-%d-%H:%M'), + timezone.now().strftime('%Y-%m-%d-%H_%M'), clean) - return os.path.join(settings.SEMINAR_RESENI_DIR, datedir, fname) + return os.path.join(settings.KOREKTURY_PDF_DIR, fname) #@reversion.register(ignore_duplicate_revision=True) @@ -45,10 +44,40 @@ class KorekturovanePDF(models.Model): #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) + #TODO Nepovinný foreign key k číslu + def save(self): + 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) @@ -63,7 +92,7 @@ class Oprava(models.Model): #Interní ID id = models.AutoField(primary_key = True) - #pdf = models.ForeignKey(KorekturovanePDF) + pdf = models.ForeignKey(KorekturovanePDF, default=-1) strana = models.IntegerField(u'strana s opravou', help_text='Strana s opravou (od 0)') @@ -83,7 +112,7 @@ class Oprava(models.Model): # TODO: Změnit na cizí klíč do orgů - autor = models.TextField(u'autor opravy',blank = True, help_text='Autor opravy') + 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') @@ -112,7 +141,7 @@ class Komentar(models.Model): oprava = models.ForeignKey(Oprava) # TODO: Změnit na cizí klíč do orgů - autor = models.TextField(u'autor komentáře',blank = True, help_text='Autor komentáře') + 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') diff --git a/korektury/templates/korektury/opraf.html b/korektury/templates/korektury/opraf.html index 63069f63..7beb1435 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -1,15 +1,14 @@ -
- + + -