Pridano administracni rozhrani.
Korekturovana PDF se uz daji pridavat pres admina. Pridan jednoduchy vypis korekturovanych veci.
This commit is contained in:
		
							parent
							
								
									2a163fe6a4
								
							
						
					
					
						commit
						b0f9714329
					
				
					 12 changed files with 205 additions and 27 deletions
				
			
		|  | @ -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) | ||||
|  |  | |||
							
								
								
									
										27
									
								
								korektury/migrations/0003_auto_20151204_1855.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								korektury/migrations/0003_auto_20151204_1855.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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, | ||||
|         ), | ||||
|     ] | ||||
							
								
								
									
										26
									
								
								korektury/migrations/0004_auto_20151204_2240.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								korektury/migrations/0004_auto_20151204_2240.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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, | ||||
|         ), | ||||
|     ] | ||||
							
								
								
									
										32
									
								
								korektury/migrations/0005_auto_20151204_2244.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								korektury/migrations/0005_auto_20151204_2244.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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, | ||||
|         ), | ||||
|     ] | ||||
							
								
								
									
										20
									
								
								korektury/migrations/0006_oprava_pdf.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								korektury/migrations/0006_oprava_pdf.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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, | ||||
|         ), | ||||
|     ] | ||||
|  | @ -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') | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,15 +1,14 @@ | |||
| <html> | ||||
| 	<head> | ||||
|         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||||
| <head> | ||||
| 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||||
| 	<link rel="stylesheet" type="text/css" media="screen, projection" href="/static/korektury/opraf.css" /> | ||||
| 	<script src="/static/korektury/opraf.js"></script> | ||||
| 	<title>Korektury 22_3_verze5.pdf</title> | ||||
| 	</head> | ||||
| 	<body>  | ||||
| 
 | ||||
| 	<h1>Korektury 22_3_verze5.pdf</h1> | ||||
| 	<i>Klikni na chybu, napi¹ komentáø</i>  | | ||||
| 	<a href="?action=ls">ls</a> | | ||||
| 	<title>Korektury {{pdf.nazev}}</title> | ||||
| </head> | ||||
| <body>  | ||||
| 	<h1>Korektury {{pdf.nazev}}</h1> | ||||
| 	<i>Klikni na chybu, napiš komentář</i>  | | ||||
| 	<a href="/korektury">ls</a> | | ||||
| 	<a href="?action=doc">help</a> |          | | ||||
| 	<a href="https://mam.mff.cuni.cz/">hlavní stránka</a> | | ||||
| 	<a href="https://mam.mff.cuni.cz/wiki">wiki</a> | | ||||
|  | @ -24,7 +23,7 @@ | |||
| 	  <br/> | ||||
| 	  <textarea onkeypress="textarea_onkey(event);" id="commform-text" cols=40 rows=10 name="txt"></textarea> | ||||
| 	  <br/> | ||||
| 	  <input type="hidden" size="3" name="pdf" value='22_3_verze5.pdf'/> | ||||
| 	  <input type="hidden" size="3" name="pdf" value='{{pdf.id}}'/> | ||||
| 	  <input type="hidden" size="3" id="commform-x" name="x"/> | ||||
| 	  <input type="hidden" size="3" id="commform-y" name="y"/> | ||||
| 	  <input type="hidden" size="3" id="commform-img-id" name="img-id"/> | ||||
|  | @ -35,13 +34,13 @@ | |||
| 	</div> | ||||
| 
 | ||||
| 	{% for i in img_indexes %} | ||||
| 	<div class='imgdiv'><img width='1021' height='1448' onclick='img_click(this,event)' id='img-{{i}}' src='/static/korektury/png/{{img_name}}-{{i}}.png'/></div><hr/> | ||||
| 	<div class='imgdiv'><img width='1021' height='1448' onclick='img_click(this,event)' id='img-{{i}}' src='/media/korektury/img/{{img_name}}-{{i}}.png'/></div><hr/> | ||||
| 	{% endfor %} | ||||
| 
 | ||||
| 	<form method="post"> | ||||
| 	  <input type='hidden' name='action' value='delall'/> | ||||
| 	  <input type='submit' value='Smazat v¹echny komentáøe'/> | ||||
| 	  <input type='hidden' name='pdf' value='22_3_verze5.pdf'/> | ||||
| 	  <input type='hidden' name='pdf' value='{{pdf.id}}'/> | ||||
| 	  <input type='checkbox' name='yes'/> Souhlasím se smazáním v¹ech kometáøù | ||||
| 	</form> | ||||
| 	<hr/> | ||||
|  | @ -66,7 +65,7 @@ | |||
| 	 <div class='float-right'> | ||||
| 	  <form  action='' onsubmit='save_scroll(this)' method='POST'> | ||||
| 		{% csrf_token %} | ||||
| 	   <input type='hidden' name='pdf' value='22_3_verze5.pdf'> | ||||
| 	   <input type='hidden' name='pdf' value='{{pdf.id}}'> | ||||
| 	   <input type='hidden' name='id' value='{{o.id}}'> | ||||
| 	   <input type='hidden' name='scroll'> | ||||
| 	   {% if o.komentare %} | ||||
|  | @ -122,7 +121,7 @@ | |||
|             	<div class="float-right"> | ||||
|                     <form  action='' onsubmit='save_scroll(this)' method='POST'> | ||||
| 					  {% csrf_token %} | ||||
|                       <input type='hidden' name='pdf' value='22_3_verze1.pdf'> | ||||
|                       <input type='hidden' name='pdf' value='{{pdf.id}}'> | ||||
| 					  <input type='hidden' name='id' value='{{k.id}}'> | ||||
|                       <input type='hidden' name='scroll'> | ||||
|                       <button type='submit' name='action' value='del-comment' title='Smaž komentář' | ||||
|  |  | |||
							
								
								
									
										13
									
								
								korektury/templates/korektury/seznam.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								korektury/templates/korektury/seznam.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| <html> | ||||
| 	<head> | ||||
|         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||||
| 	<title>Seznam korektur</title> | ||||
| 	</head> | ||||
| 	<body>  | ||||
| 	<ul> | ||||
| {% for pdf in object_list  %} | ||||
| 	<li> <b>{{ pdf.nazev }}</b> <i>{{pdf.komentar}}</i> <a href="/korektury/{{pdf.id}}">{{pdf.pdf.url}}</a> </li> | ||||
| {% endfor %} | ||||
| 	</ul> | ||||
| 	</body> | ||||
| <html> | ||||
|  | @ -3,5 +3,6 @@ from django.conf.urls import patterns, url | |||
| from . import views | ||||
| 
 | ||||
| urlpatterns = patterns('', | ||||
|     url(r'^korektury$',views.KorekturyView.as_view(),name='korektury'), | ||||
|     url(r'^korektury$',views.KorekturyListView.as_view(),name='korektury-list'), | ||||
|     url(r'^korektury/(?P<pdf>\d+)$', views.KorekturyView.as_view(), name='korektury'), | ||||
| ) | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ from django.utils.translation import ugettext as _ | |||
| from django.http import Http404 | ||||
| from django.http import HttpResponseRedirect | ||||
| 
 | ||||
| from .models import Oprava,Komentar | ||||
| from .models import Oprava,Komentar,KorekturovanePDF | ||||
| from .forms import OpravaForm | ||||
| 
 | ||||
| from datetime import timedelta, date, datetime | ||||
|  | @ -21,6 +21,11 @@ import os | |||
| from django.conf import settings | ||||
| import unicodedata | ||||
| 
 | ||||
| 
 | ||||
| class KorekturyListView(generic.ListView): | ||||
|     model = KorekturovanePDF | ||||
|     template_name = 'korektury/seznam.html' | ||||
| 
 | ||||
| ### Korektury | ||||
| class KorekturyView(generic.TemplateView): | ||||
|     model = Oprava | ||||
|  | @ -40,8 +45,9 @@ class KorekturyView(generic.TemplateView): | |||
|             text = q.get('txt') | ||||
|             strana = int(q.get('img-id')[4:]) | ||||
|             scroll = q.get('scroll') | ||||
|             pdf = KorekturovanePDF.objects.filter(id=q.get('pdf')).first() | ||||
| 
 | ||||
|             op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana) | ||||
|             op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf) | ||||
|             op.save() | ||||
|         elif (action == u'del'): | ||||
|             id = int(q.get('id')) | ||||
|  | @ -88,10 +94,13 @@ class KorekturyView(generic.TemplateView): | |||
| #            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" | ||||
|         pdf = KorekturovanePDF.objects.filter(id=self.kwargs['pdf']).first() | ||||
|         context['pdf'] = pdf | ||||
|         context['img_name'] = os.path.split(pdf.pdf.path)[1].split('.')[0] | ||||
|         context['img_path'] = settings.KOREKTURY_IMG_DIR | ||||
|         context['img_indexes'] = range(27)  | ||||
|         context['form_oprava'] = OpravaForm() | ||||
|         opravy = Oprava.objects.all() | ||||
|         opravy = Oprava.objects.filter(pdf=self.kwargs['pdf']) | ||||
|         for o in opravy: | ||||
|             o.komentare = o.komentar_set.all() | ||||
|         context['opravy'] = opravy | ||||
|  |  | |||
|  | @ -236,6 +236,8 @@ LOGGING = { | |||
| # MaM specific | ||||
| 
 | ||||
| SEMINAR_RESENI_DIR = os.path.join(BASE_DIR, 'media', 'reseni') | ||||
| KOREKTURY_PDF_DIR = os.path.join(BASE_DIR, 'media', 'korektury','pdf') | ||||
| KOREKTURY_IMG_DIR = os.path.join(BASE_DIR, 'media', 'korektury','img') | ||||
| 
 | ||||
| 
 | ||||
| CKEDITOR_CONFIGS = { | ||||
|  |  | |||
|  | @ -35,6 +35,13 @@ DATABASES = { | |||
|         'NAME': os.path.join(BASE_DIR, 'db-local.sqlite3'), | ||||
|     } | ||||
| } | ||||
| #DATABASES = { | ||||
| #    'default': { | ||||
| #        'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||||
| #        'NAME': 'mam_local', | ||||
| #        'USER': 'mam', | ||||
| #    }, | ||||
| #} | ||||
| 
 | ||||
| # LOGGING | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue