Files
postgres-web/pgweb/events/forms.py
Jonathan S. Katz e7014d7ecc Enable events to be badged.
Adds the "badged" flag to the Event model in order to distinguish
community badged events from other PostgreSQL oriented events.
Seven total events will be displayed on the homepage, with up to
four community events displayed. If there are no upcoming
community events then, then the header "Events" is shown.

The event submission interface allows a user to opt-in to
listing an event as a "community" event and provide an
explanation for moderators as to why the event should be
considered a community event.

Expands the list of News and Planet PostgreSQL blog entries to 10.
2017-12-06 12:06:37 +09:00

55 lines
1.9 KiB
Python

from django import forms
from django.forms import ValidationError
from pgweb.core.models import Organisation
from models import Event
class EventForm(forms.ModelForm):
toggle_fields = [
{
'name': 'isonline',
'invert': True,
'fields': ['city', 'state', 'country',]
},
{
'name': 'badged',
'invert': False,
'fields': ['description_for_badged',]
},
]
def __init__(self, *args, **kwargs):
super(EventForm, self).__init__(*args, **kwargs)
def filter_by_user(self, user):
self.fields['org'].queryset = Organisation.objects.filter(managers=user, approved=True)
def clean(self):
cleaned_data = super(EventForm, self).clean()
if not cleaned_data.get('isonline'):
# Non online events require city and country
# (we don't require state, since many countries have no such thing)
if not cleaned_data.get('city'):
self._errors['city'] = self.error_class(['City must be specified for non-online events'])
del cleaned_data['city']
if not cleaned_data.get('country'):
self._errors['country'] = self.error_class(['Country must be specified for non-online events'])
del cleaned_data['country']
return cleaned_data
def clean_startdate(self):
if self.instance.pk and self.instance.approved:
if self.cleaned_data['startdate'] != self.instance.startdate:
raise ValidationError("You cannot change the dates on events that have been approved")
return self.cleaned_data['startdate']
def clean_enddate(self):
if self.instance.pk and self.instance.approved:
if self.cleaned_data['enddate'] != self.instance.enddate:
raise ValidationError("You cannot change the dates on events that have been approved")
if self.cleaned_data.has_key('startdate') and self.cleaned_data['enddate'] < self.cleaned_data['startdate']:
raise ValidationError("End date cannot be before start date!")
return self.cleaned_data['enddate']
class Meta:
model = Event
exclude = ('submitter', 'approved', )