forked from gergely/calendar-social
Add the Event.visibility field
This shows if the event is visible to anyone or just people who are invited. The calendar view already respects this flag.
This commit is contained in:
@@ -26,6 +26,8 @@ from wtforms.ext.dateutil.fields import DateTimeField
|
||||
from wtforms.validators import DataRequired, Email, StopValidation, ValidationError
|
||||
from wtforms.widgets import TextArea
|
||||
|
||||
from calsocial.models import EventVisibility, EVENT_VISIBILITY_TRANSLATIONS
|
||||
|
||||
|
||||
class UsernameAvailable(object): # pylint: disable=too-few-public-methods
|
||||
"""Checks if a username is available
|
||||
@@ -169,6 +171,36 @@ class TimezoneField(SelectField):
|
||||
yield (value, label, value == self.data)
|
||||
|
||||
|
||||
class EnumField(SelectField):
|
||||
def __init__(self, enum_type, translations, *args, **kwargs):
|
||||
kwargs.update({'choices': [(value, None) for value in enum_type]})
|
||||
self.data = None
|
||||
self.enum_type = enum_type
|
||||
self.translations = translations
|
||||
SelectField.__init__(self, *args, **kwargs)
|
||||
|
||||
def process_formdata(self, valuelist):
|
||||
if not valuelist:
|
||||
self.data = None
|
||||
|
||||
return
|
||||
|
||||
try:
|
||||
self.data = self.enum_type[valuelist[0]]
|
||||
except KeyError:
|
||||
raise ValueError('Unknown value')
|
||||
|
||||
def iter_choices(self):
|
||||
for value in self.enum_type:
|
||||
label = self.translations[value] if self.translations else value.name
|
||||
|
||||
yield (
|
||||
value.name,
|
||||
self.gettext(self.translations[value]),
|
||||
value == self.data
|
||||
)
|
||||
|
||||
|
||||
class EventForm(FlaskForm):
|
||||
"""Form for event creation/editing
|
||||
"""
|
||||
@@ -179,6 +211,7 @@ class EventForm(FlaskForm):
|
||||
end_time = DateTimeField(_('End time'), validators=[DataRequired()])
|
||||
all_day = BooleanField(_('All day'))
|
||||
description = StringField(_('Description'), widget=TextArea())
|
||||
visibility = EnumField(EventVisibility, EVENT_VISIBILITY_TRANSLATIONS, label=_('Visibility'))
|
||||
|
||||
def populate_obj(self, obj):
|
||||
"""Populate ``obj`` with event data
|
||||
|
Reference in New Issue
Block a user