mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-13 13:12:42 +00:00

This gets rid of the annoying requirement to specify things like "online, United States" for events that are online. This requires some SQL to run on existing installations: ALTER TABLE events_event ADD COLUMN isonline boolean NOT NULL DEFAULT 'f'; ALTER TABLE events_event ALTER COLUMN isonline DROP DEFAULT; ALTER TABLE events_event ALTER COLUMN country_id DROP NOT NULL; Fixes #166
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from django import forms
|
|
|
|
from pgweb.core.models import Organisation
|
|
from models import Event
|
|
|
|
class EventForm(forms.ModelForm):
|
|
toggle_fields = [{
|
|
'name': 'isonline',
|
|
'invert': True,
|
|
'fields': ['city', 'state', 'country',]
|
|
},
|
|
]
|
|
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
|
|
|
|
class Meta:
|
|
model = Event
|
|
exclude = ('submitter', 'approved', )
|