From 9c37f4352796dcb6db3d9d8c592686fe166d06ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Sun, 6 Nov 2016 21:20:10 +0100 Subject: [PATCH] =?UTF-8?q?F=C3=A1ze=20tvorby=20=C4=8D=C3=ADsla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/admin.py | 50 +++++++++++++++++++++++--- seminar/migrations/0042_cislo_faze.py | 19 ++++++++++ seminar/migrations/0043_uprava_faze.py | 19 ++++++++++ seminar/migrations/0044_uprava_faze.py | 19 ++++++++++ seminar/models.py | 20 +++++++++++ 5 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 seminar/migrations/0042_cislo_faze.py create mode 100644 seminar/migrations/0043_uprava_faze.py create mode 100644 seminar/migrations/0044_uprava_faze.py diff --git a/seminar/admin.py b/seminar/admin.py index 45cc5fb7..b1eb0f35 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -244,10 +244,28 @@ admin.site.register(Skola, SkolaAdmin) class CisloAdmin(VersionAdmin): fieldsets = [ - (None, {'fields': ['cislo', 'rocnik', 'verejne_db', 'verejna_vysledkovka', 'poznamka', 'pdf']}), - (u'Data', {'fields': ['datum_vydani', 'datum_deadline']}), + (None, { + 'fields': [ + 'cislo', + 'rocnik', + 'verejne_db', + 'verejna_vysledkovka', + 'faze', + 'poznamka', + 'pdf' + ] + }), + (u'Data', {'fields': ['datum_vydani', 'datum_deadline']}), ] - list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne', 'verejna_vysledkovka'] + list_display = [ + 'kod', + 'rocnik', + 'cislo', + 'datum_vydani', + 'datum_deadline', + 'verejne', + 'verejna_vysledkovka' + ] list_filter = ['rocnik'] view_on_site = Cislo.verejne_url actions = [ @@ -339,7 +357,20 @@ class PohadkaAdmin(VersionAdmin): return obj.uloha.cislo_zadani.rocnik.rocnik get_rocnik.short_description = u'Ročník' - list_display = ['__str__', 'get_rocnik', 'get_kod_ulohy', 'uloha', 'autor', 'timestamp'] + def get_readonly_fields(self, request, obj=None): + if not obj: + return [] + if obj.uloha.cislo_zadani.faze != 'admin': + return ['text'] + + list_display = [ + '__str__', + 'get_rocnik', + 'get_kod_ulohy', + 'uloha', + 'autor', + 'timestamp' + ] get_form = get_form_predvypln_autora @@ -375,12 +406,21 @@ class ProblemAdmin(VersionAdmin): (u'Vydání', {'fields': ['cislo_zadani', 'kod', 'cislo_reseni', 'opravovatel',]}), (None, {'fields': ['text_zadani', 'text_reseni', 'text_org',]}), ] - readonly_fields = ['timestamp', 'import_dakos_id'] list_select_related = True search_fields = ['nazev', 'text_zadani', 'text_reseni', 'text_org'] view_on_site = Problem.verejne_url ordering = ['-timestamp'] + def get_readonly_fields(self, request, obj=None): + readonly_fields = ['timestamp', 'import_dakos_id'] + if not obj: + return readonly_fields + if obj.cislo_zadani.faze != 'admin': + readonly_fields += ['nazev', 'text_zadani', 'body'] + if obj.cislo_reseni.faze != 'admin': + readonly_fields += ['text_reseni'] + return readonly_fields + def get_queryset(self, request): qs = super(ProblemAdmin, self).get_queryset(request) return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni') diff --git a/seminar/migrations/0042_cislo_faze.py b/seminar/migrations/0042_cislo_faze.py new file mode 100644 index 00000000..7d35ace5 --- /dev/null +++ b/seminar/migrations/0042_cislo_faze.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0041_konfery'), + ] + + operations = [ + migrations.AddField( + model_name='cislo', + name='faze', + field=models.CharField(default='admin', help_text='B\u011bhem f\xe1ze "admin" se obsah \u010d\xedsla vytv\xe1\u0159\xed (a p\u0159\xedpadn\u011b komentuje) ve webov\xe9m rozhran\xed. B\u011bhem f\xe1ze "tex" u\u017e obsah ve webov\xe9m rozhran\xed editovat nelze. N\xe1vrhy na \xfapravy se pak p\xed\u0161\xed do korekturov\xe1tka a zan\xe1\u0161ej\xed do gitu. Z n\u011bj se pak generuje verze pro web.', max_length=32, verbose_name='F\xe1ze vytv\xe1\u0159en\xed obsahu'), + ), + ] diff --git a/seminar/migrations/0043_uprava_faze.py b/seminar/migrations/0043_uprava_faze.py new file mode 100644 index 00000000..29e06e01 --- /dev/null +++ b/seminar/migrations/0043_uprava_faze.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0042_cislo_faze'), + ] + + operations = [ + migrations.AlterField( + model_name='cislo', + name='faze', + field=models.CharField(default='admin', help_text='B\u011bhem f\xe1ze "admin" se obsah \u010d\xedsla vytv\xe1\u0159\xed (a p\u0159\xedpadn\u011b komentuje) ve webov\xe9m rozhran\xed. B\u011bhem f\xe1ze "tex" u\u017e obsah ve webov\xe9m rozhran\xed editovat nelze. N\xe1vrhy na \xfapravy se pak p\xed\u0161\xed do korekturov\xe1tka a zan\xe1\u0161ej\xed do gitu. Z n\u011bj se pak generuje verze pro web.', max_length=32, verbose_name='F\xe1ze vytv\xe1\u0159en\xed obsahu', choices=[('admin', 'Zad\xe1v\xe1n\xed \xfaloh do webu'), ('tex', '\xdapravy \xfaloh v TeXov\xe9m repozit\xe1\u0159i')]), + ), + ] diff --git a/seminar/migrations/0044_uprava_faze.py b/seminar/migrations/0044_uprava_faze.py new file mode 100644 index 00000000..c0cfe0dd --- /dev/null +++ b/seminar/migrations/0044_uprava_faze.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0043_auto_20161106_1951'), + ] + + operations = [ + migrations.AlterField( + model_name='cislo', + name='faze', + field=models.CharField(default='admin', help_text='B\u011bhem f\xe1ze "\xdapravy na webu" se obsah \u010d\xedsla vytv\xe1\u0159\xed (a p\u0159\xedpadn\u011b komentuje) ve webov\xe9m rozhran\xed. B\u011bhem f\xe1ze "\xdapravy na webu" u\u017e obsah ve webov\xe9m rozhran\xed editovat nelze a n\xe1vrhy na \xfapravy se p\xed\u0161\xed do korekturov\xe1tka a zan\xe1\u0161ej\xed do gitu. Z n\u011bj se pak generuje verze pro web.', max_length=32, verbose_name='F\xe1ze vytv\xe1\u0159en\xed obsahu', choices=[('admin', '\xdapravy na webu'), ('tex', '\xdapravy v TeXu')]), + ), + ] diff --git a/seminar/models.py b/seminar/models.py index 4c8fc3f0..ef9478d6 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -349,6 +349,26 @@ class Cislo(SeminarModelBase): pdf = models.FileField(u'pdf', upload_to=cislo_pdf_filename, null=True, blank=True, help_text=u'Pdf čísla, které si mohou řešitelé stáhnout') + FAZE_ADMIN = u'admin' + FAZE_TEX = u'tex' + FAZE_CHOICES = [ + (FAZE_ADMIN, u'Úpravy na webu'), + (FAZE_TEX, u'Úpravy v TeXu'), + ] + faze = models.CharField( + u'Fáze vytváření obsahu', + max_length=32, + default=FAZE_ADMIN, + choices=FAZE_CHOICES, + help_text=( + u'Během fáze "{}" se obsah čísla vytváří (a případně ' + u'komentuje) ve webovém rozhraní. Během fáze "{}" už obsah ve ' + u'webovém rozhraní editovat nelze a návrhy na úpravy se píší ' + u'do korekturovátka a zanášejí do gitu. Z něj se pak generuje ' + u'verze pro web.' + ).format(FAZE_CHOICES[0][1], FAZE_CHOICES[0][1]) + ) + def kod(self): return u'%s.%s' % (self.rocnik.rocnik, self.cislo) kod.short_description = u'Kód čísla'