-class DocumentForm(forms.ModelForm):
- """
- Form used for editing a chunk.
- """
- user = forms.ModelChoiceField(queryset=
- User.objects.order_by('last_name', 'first_name'), required=False,
- label=_('Assigned to'))
-
- class Meta:
- model = Document
- fields = ['user', 'stage']
-
-
-class DocumentAddForm(DocumentForm):
- """
- Form used for adding a chunk to a document.
- """
-
- def clean_slug(self):
- slug = self.cleaned_data['slug']
- try:
- user = Chunk.objects.get(book=self.instance.book, slug=slug)
- except Chunk.DoesNotExist:
- return slug
- raise forms.ValidationError(_('Chunk with this slug already exists'))
-
-
-class BookForm(forms.ModelForm):
- """Form used for editing a Book."""
-
- class Meta:
- model = Document
- exclude = ['project']
-
- def __init__(self, *args, **kwargs):
- ret = super(BookForm, self).__init__(*args, **kwargs)
- self.fields['slug'].widget.attrs.update({"class": "autoslug"})
- self.fields['title'].widget.attrs.update({"class": "autoslug-source"})
- return ret
-
-
-class ReadonlyBookForm(BookForm):
- """Form used for not editing a Book."""
-
- def __init__(self, *args, **kwargs):
- ret = super(ReadonlyBookForm, self).__init__(*args, **kwargs)
- for field in self.fields.values():
- field.widget.attrs.update({"readonly": True})
- return ret
-
-