class ParticipantsDisplayForm(IndicoForm): """Form to customize the display of the participant list.""" json = JSONField() def validate_json(self, field): schema = { 'type': 'object', 'properties': { 'merge_forms': { 'type': 'boolean' }, 'participant_list_forms': { 'type': 'array', 'items': { 'type': 'integer' } }, 'participant_list_columns': { 'type': 'array', 'items': { 'type': 'string' } } } } try: jsonschema.validate(field.data, schema) except jsonschema.ValidationError as exc: raise ValidationError(str(exc))
class EventCreationFormBase(IndicoForm): listing = IndicoButtonsBooleanField(_('Listing'), default=True, true_caption=(_('List in a category'), 'eye'), false_caption=(_('Keep unlisted'), 'eye-blocked')) category = CategoryField(_('Category'), [ UsedIf(lambda form, _: (form.listing.data or not can_create_unlisted_events(session.user))), DataRequired() ], require_event_creation_rights=True) title = StringField(_('Event title'), [DataRequired()]) timezone = IndicoTimezoneSelectField(_('Timezone'), [DataRequired()]) location_data = IndicoLocationField(_('Location'), allow_location_inheritance=False, edit_address=False) protection_mode = IndicoEnumRadioField(_('Protection mode'), enum=ProtectionMode) create_booking = JSONField() def validate_category(self, field): if ((self.listing.data or not can_create_unlisted_events(session.user)) and not field.data.can_create_events(session.user)): raise ValidationError( _('You are not allowed to create events in this category.'))
class PaperUploadForm(IndicoForm): """Form to upload a new paper version.""" paper_file = JSONField(_("Paper file"), widget=DropzoneWidget(max_files=10, submit_form=False, add_remove_links=True, handle_flashes=True))
class LogoForm(IndicoForm): logo = JSONField( "Logo", widget=DropzoneWidget( accepted_file_types='image/jpeg,image/jpg,image/png,image/gif', max_files=1, submit_form=False, submit_if_empty=False, add_remove_links=False, handle_flashes=True), description=_("Logo to be displayed next to the event's title"))
class EventCreationFormBase(IndicoForm): category = CategoryField(_('Category'), [DataRequired()], allow_subcats=False, require_event_creation_rights=True) title = StringField(_('Event title'), [DataRequired()]) timezone = IndicoTimezoneSelectField(_('Timezone'), [DataRequired()]) location_data = IndicoLocationField(_('Location'), allow_location_inheritance=False, edit_address=False) protection_mode = IndicoEnumRadioField(_('Protection mode'), enum=ProtectionMode) create_booking = JSONField() def validate_category(self, field): if not field.data.can_create_events(session.user): raise ValidationError(_('You are not allowed to create events in this category.'))
class CategoryLogoForm(IndicoForm): logo = JSONField( "Logo", widget=DropzoneWidget( accepted_file_types='image/jpeg,image/jpg,image/png,image/gif', max_files=1, submit_form=False, submit_if_empty=False, add_remove_links=False, handle_flashes=True), description=_( "Logo that will show up next to the category description. Will be " "automatically resized to at most 200x200 pixels."))
class CategoryIconForm(IndicoForm): icon = JSONField( "Icon", widget=DropzoneWidget( accepted_file_types='image/jpeg,image/jpg,image/png,image/gif', max_files=1, submit_form=False, submit_if_empty=False, add_remove_links=False, handle_flashes=True), description= _("Small icon that will show up next to category names in overview pages. Will be " "automatically resized to 16x16 pixels. This may involve loss of image quality, " "so try to upload images as close as possible to those dimensions."))
class ParticipantsDisplayFormColumnsForm(IndicoForm): """Form to customize the columns for a particular registration form on the participant list.""" json = JSONField() def validate_json(self, field): schema = { 'type': 'object', 'properties': { 'columns': { 'type': 'array', 'items': {'type': 'integer'} } } } try: jsonschema.validate(field.data, schema) except jsonschema.ValidationError as exc: raise ValidationError(exc.message)
class BlockingForm(IndicoForm): reason = TextAreaField(_(u'Reason'), [DataRequired()]) principals = PrincipalField(groups=True, serializable=False, allow_external=True) blocked_rooms = JSONField(default=[]) def validate_blocked_rooms(self, field): try: field.data = map(int, field.data) except Exception as e: # In case someone sent crappy data raise ValidationError(str(e)) # Make sure all room ids are valid if len(field.data) != Room.find(Room.id.in_(field.data)).count(): raise ValidationError('Invalid rooms') if hasattr(self, '_blocking'): start_date = self._blocking.start_date end_date = self._blocking.end_date blocking_id = self._blocking.id else: start_date = self.start_date.data end_date = self.end_date.data blocking_id = None overlap = BlockedRoom.find_first( BlockedRoom.room_id.in_(field.data), BlockedRoom.state != BlockedRoom.State.rejected, Blocking.start_date <= end_date, Blocking.end_date >= start_date, Blocking.id != blocking_id, _join=Blocking) if overlap: msg = 'Your blocking for {} is overlapping with another blocking.'.format( overlap.room.full_name) raise ValidationError(msg)
class AddImagesForm(IndicoForm): image = JSONField( "Image", widget=DropzoneWidget( accepted_file_types='image/jpeg,image/jpg,image/png,image/gif', submit_if_empty=False))