1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django import forms
7 from django.core.exceptions import ValidationError
8 from django.utils.translation import ugettext_lazy as _
10 from catalogue.constants import STAGES
11 from librarian.document import Document
14 class DocumentTextSaveForm(forms.Form):
16 Form for saving document's text:
18 * parent_revision - revision which the modified text originated from.
19 * comment - user's verbose comment; will be used in commit.
20 * stage - change to this stage
24 parent_revision = forms.IntegerField(widget=forms.HiddenInput, required=False)
25 text = forms.CharField(widget=forms.HiddenInput)
27 author_name = forms.CharField(
30 help_text=_(u"Your name"),
33 author_email = forms.EmailField(
35 label=_(u"Author's email"),
36 help_text=_(u"Your email address, so we can show a gravatar :)"),
39 comment = forms.CharField(
41 widget=forms.Textarea,
42 label=_(u"Your comments"),
43 help_text=_(u"Describe changes you made."),
46 stage = forms.ChoiceField(
47 choices=[(s, s) for s in STAGES],
50 help_text=_(u"If completed a work stage, change to another one."),
53 def __init__(self, *args, **kwargs):
54 user = kwargs.pop('user')
55 super(DocumentTextSaveForm, self).__init__(*args, **kwargs)
56 if user and user.is_authenticated():
57 self.fields['author_name'].required = False
58 self.fields['author_email'].required = False
61 text = self.cleaned_data['text']
63 Document.from_string(text)
64 except ValueError as e:
65 raise ValidationError(e.message)
69 class DocumentTextRevertForm(forms.Form):
71 Form for reverting document's text:
73 * revision - revision to revert to.
74 * comment - user's verbose comment; will be used in commit.
78 revision = forms.IntegerField(widget=forms.HiddenInput)
80 author_name = forms.CharField(
83 help_text=_(u"Your name"),
86 author_email = forms.EmailField(
88 label=_(u"Author's email"),
89 help_text=_(u"Your email address, so we can show a gravatar :)"),
92 comment = forms.CharField(
94 widget=forms.Textarea,
95 label=_(u"Your comments"),
96 help_text=_(u"Describe the reason for reverting."),
100 class DocumentTextPublishForm(forms.Form):
101 revision = forms.IntegerField(widget=forms.HiddenInput)