diff --git a/seminar/admin.py b/seminar/admin.py index 3a61d461..89901c6b 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -245,10 +245,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 = [ @@ -340,7 +358,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 @@ -376,12 +407,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 5a478feb..ad9667bf 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'