Source code for news.forms
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django import forms
from .models import NewsLetter, NewsItem, NewsLetterNewsItemsTable
[docs]class NewsItemForm(forms.ModelForm):
[docs] class Meta:
model = NewsItem
fields = [
"date",
"headline",
"blurb_short",
"blurb",
"image",
"css_class",
"followup_link",
"followup_link_text",
"published",
"on_homepage",
]
[docs]class NewsLetterNewsItemsTableFormSet(forms.BaseModelFormSet):
[docs] def save(self, *args, **kwargs):
objects = super().save(*args, **kwargs)
for form in self.ordered_forms:
form.instance.order = form.cleaned_data["ORDER"]
form.instance.save()
return objects
NewsLetterNewsItemsOrderingFormSet = forms.modelformset_factory(
NewsLetterNewsItemsTable,
fields=(),
can_order=True,
extra=0,
formset=NewsLetterNewsItemsTableFormSet,
)