X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/4b3016bf455bd8faca4209acf3c4b4fa361e4c85..a9f9e367a4aa563d907c5d2282ae732c9224f36a:/apps/catalogue/forms.py?ds=inline diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index 657a1b04..8cd00c2d 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -68,12 +68,18 @@ class ChunkForm(forms.ModelForm): user = forms.ModelChoiceField(queryset= User.objects.annotate(count=Count('chunk')). order_by('-count', 'last_name', 'first_name'), required=False, - label=_('Assigned to')) + label=_('Assigned to')) class Meta: model = Chunk + fields = ['title', 'slug', 'user', 'stage'] exclude = ['number'] + def __init__(self, *args, **kwargs): + super(ChunkForm, self).__init__(*args, **kwargs) + 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: @@ -114,13 +120,27 @@ class BookAppendForm(forms.Form): class BookForm(forms.ModelForm): - """ - Form used for editing a Book. - """ + """Form used for editing a Book.""" class Meta: model = Book + 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 + class ChooseMasterForm(forms.Form): """