-class ChunkForm(forms.ModelForm):
- """
- Form used for editing a chunk.
- """
- user = forms.ModelChoiceField(queryset=
- User.objects.annotate(count=Count('chunk')).
- order_by('-count', 'last_name', 'first_name'), required=False,
- label=_('Assigned to'))
-
- class Meta:
- model = Chunk
- fields = ['title', 'slug', 'gallery_start', 'user', 'stage']
- exclude = ['number']
-
- def __init__(self, *args, **kwargs):
- super(ChunkForm, self).__init__(*args, **kwargs)
- self.fields['gallery_start'].widget.attrs={'class': 'number-input'}
- self.fields['slug'].widget.attrs={'class': 'autoslug'}
- self.fields['title'].widget.attrs={'class': 'autoslug-source'}
-
- def clean_slug(self):
- slug = self.cleaned_data['slug']
- try:
- chunk = Chunk.objects.get(book=self.instance.book, slug=slug)
- except Chunk.DoesNotExist:
- return slug
- if chunk == self.instance:
- return slug
- raise forms.ValidationError(_('Chunk with this slug already exists'))
-
-
-class ChunkAddForm(ChunkForm):
- """
- 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 BookAppendForm(forms.Form):