diff --git a/korektury/migrations/0010_Pridani_odkazu_na_organizatora.py b/korektury/migrations/0010_Pridani_odkazu_na_organizatora.py new file mode 100644 index 00000000..e76d5058 --- /dev/null +++ b/korektury/migrations/0010_Pridani_odkazu_na_organizatora.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0041_konfery'), + ('korektury', '0009_trizeni_korektur_v_seznamu'), + ] + + operations = [ + migrations.AddField( + model_name='komentar', + name='autor_org', + field=models.ForeignKey(blank=True, to='seminar.Organizator', help_text='Autor koment\xe1\u0159e', null=True), + ), + migrations.AddField( + model_name='oprava', + name='autor_org', + field=models.ForeignKey(blank=True, to='seminar.Organizator', help_text=b'Autor opravy', null=True), + ), + ] diff --git a/korektury/migrations/0011_prevod_autora_z_charField_na_Organizator.py b/korektury/migrations/0011_prevod_autora_z_charField_na_Organizator.py new file mode 100644 index 00000000..dddb07be --- /dev/null +++ b/korektury/migrations/0011_prevod_autora_z_charField_na_Organizator.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + +def transform_autor(apps, schema_editor): + print + Organizator = apps.get_model('seminar', 'Organizator') + + # preorgovani oprav + Oprava = apps.get_model('korektury', 'Oprava') + for oprava in Oprava.objects.all(): + jmeno = oprava.autor.split() + if len(jmeno) == 2: + try: + org = Organizator.objects.get(user__first_name=jmeno[0], + user__last_name=jmeno[1]) + oprava.autor_org = org + oprava.save() + except: + print "Org nenalezen -- mažu korekturu" +# oprava.delete() + else: + print "Org nenalezen -- mažu korekturu" + oprava.delete() + + # preorgovani komentaru + Komentar = apps.get_model('korektury', 'Komentar') + for komentar in Komentar.objects.all(): + jmeno = komentar.autor.split() + if len(jmeno) == 2: + try: + org = Organizator.objects.get(user__first_name=jmeno[0], + user__last_name=jmeno[1]) + komentar.autor_org = org + komentar.save() + except: + print "Org nenalezen -- mažu korekturu" +# oprava.delete() + else: + print "Org nenalezen -- mažu korekturu" + komentar.delete() + +def back(apps, schema_editor): + pass + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0010_Pridani_odkazu_na_organizatora'), + ] + + operations = [ + migrations.RunPython(transform_autor, back), + ] diff --git a/korektury/migrations/0012_delete_autor.py b/korektury/migrations/0012_delete_autor.py new file mode 100644 index 00000000..4f41a955 --- /dev/null +++ b/korektury/migrations/0012_delete_autor.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0011_prevod_autora_z_charField_na_Organizator'), + ] + + operations = [ + migrations.RemoveField( + model_name='komentar', + name='autor', + ), + migrations.RemoveField( + model_name='oprava', + name='autor', + ), + ] diff --git a/korektury/migrations/0013_rename_autor_org.py b/korektury/migrations/0013_rename_autor_org.py new file mode 100644 index 00000000..db0d3151 --- /dev/null +++ b/korektury/migrations/0013_rename_autor_org.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0012_delete_autor'), + ] + + operations = [ + migrations.RenameField( + model_name='komentar', + old_name='autor_org', + new_name='autor', + ), + migrations.RenameField( + model_name='oprava', + old_name='autor_org', + new_name='autor', + ), + ] diff --git a/korektury/models.py b/korektury/models.py index a0c52ec0..a07c6945 100644 --- a/korektury/models.py +++ b/korektury/models.py @@ -8,6 +8,8 @@ from django.utils.encoding import force_unicode from django.core.exceptions import ObjectDoesNotExist from django.utils.text import get_valid_filename +from seminar.models import Organizator + import subprocess from reversion import revisions as reversion @@ -122,9 +124,9 @@ class Oprava(models.Model): 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') + autor = models.ForeignKey(Organizator, blank = True, + help_text='Autor opravy', + null = True) text = models.TextField(u'text opravy',blank = True, help_text='Text opravy') @@ -152,8 +154,9 @@ class Komentar(models.Model): 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') + autor = models.ForeignKey(Organizator, blank = True, + help_text = u'Autor komentáře', + null = True) 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 83c997ab..04cfc2de 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -82,7 +82,10 @@
- Děkujeme opravovatelům: {% for autor,pocet in zasluhy.items %} {{autor}}({{pocet}}) {% endfor %}
+ Děkujeme opravovatelům: + {% for autor,pocet in zasluhy.items %} + {{autor}} ({{pocet}}){% if not forloop.last %},{% endif %} + {% endfor %}