Files
postgres-web/pgweb/news/forms.py
Magnus Hagander 06a48b477c Implement automatic tweeting of news
Once a twitter account has been registered (using the twitter_register
management command), the twitter_post command wills start posting all
new news to twitter, once they are approved. It will only post news from
the past 7 days to avoid accidentally flooding with old news.
2017-12-09 16:46:38 +01:00

21 lines
741 B
Python

from django import forms
from django.forms import ValidationError
from pgweb.core.models import Organisation
from models import NewsArticle
class NewsArticleForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(NewsArticleForm, self).__init__(*args, **kwargs)
def filter_by_user(self, user):
self.fields['org'].queryset = Organisation.objects.filter(managers=user, approved=True)
def clean_date(self):
if self.instance.pk and self.instance.approved:
if self.cleaned_data['date'] != self.instance.date:
raise ValidationError("You cannot change the date on an article that has been approved")
return self.cleaned_data['date']
class Meta:
model = NewsArticle
exclude = ('submitter', 'approved', 'tweeted')