Пример #1
0
class CategorySettingsForm(IndicoForm):
    BASIC_FIELDS = ('title', 'description', 'timezone', 'lecture_theme', 'meeting_theme', 'visibility',
                    'suggestions_disabled', 'event_creation_notification_emails', 'notify_managers')
    EVENT_HEADER_FIELDS = ('event_message_mode', 'event_message')

    title = StringField(_("Title"), [DataRequired()])
    description = IndicoMarkdownField(_("Description"))
    timezone = IndicoTimezoneSelectField(_("Timezone"), [DataRequired()],
                                         description=_("Default timezone event lists will show up in. It will also be "
                                                       "used as a default for new events."))
    lecture_theme = IndicoThemeSelectField(_("Theme for Lectures"), [DataRequired()], event_type=EventType.lecture,
                                           description=_("Default timetable theme used for lecture events"))
    meeting_theme = IndicoThemeSelectField(_("Theme for Meetings"), [DataRequired()], event_type=EventType.meeting,
                                           description=_("Default timetable theme used for meeting events"))
    suggestions_disabled = BooleanField(_('Disable Suggestions'), widget=SwitchWidget(),
                                        description=_("Enable this if you don't want Indico to suggest this category as"
                                                      " a possible addition to a user's favourites."))
    event_message_mode = IndicoEnumSelectField(_("Message Type"), enum=EventMessageMode,
                                               default=EventMessageMode.disabled,
                                               description=_("This message will show up at the top of every event page "
                                                             "in this category"))
    event_message = IndicoMarkdownField(_("Content"))
    notify_managers = BooleanField(_("Notify managers"), widget=SwitchWidget(),
                                   description=_("Whether to send email notifications to all managers of this category "
                                                 "when an event is created inside it or in any of its subcategories."))
    event_creation_notification_emails = EmailListField(_("Notification E-mails"),
                                                        description=_("List of emails that will receive a notification "
                                                                      "every time a new event is created inside the "
                                                                      "category or one of its subcategories. "
                                                                      "One email address per line."))
Пример #2
0
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.'))
Пример #3
0
class CategorySettingsForm(IndicoForm):
    BASIC_FIELDS = ('title', 'description', 'timezone', 'lecture_theme',
                    'meeting_theme', 'visibility', 'suggestions_disabled',
                    'is_flat_view_enabled',
                    'event_creation_notification_emails', 'notify_managers')
    EVENT_HEADER_FIELDS = ('event_message_mode', 'event_message')

    title = StringField(_('Title'), [DataRequired()])
    description = IndicoMarkdownField(_('Description'))
    timezone = IndicoTimezoneSelectField(
        _('Timezone'), [DataRequired()],
        description=_(
            'Default timezone event lists will show up in. It will also be '
            'used as a default for new events.'))
    lecture_theme = IndicoThemeSelectField(
        _('Theme for Lectures'), [DataRequired()],
        event_type=EventType.lecture,
        description=_('Default timetable theme used for lecture events'))
    meeting_theme = IndicoThemeSelectField(
        _('Theme for Meetings'), [DataRequired()],
        event_type=EventType.meeting,
        description=_('Default timetable theme used for meeting events'))
    suggestions_disabled = BooleanField(
        _('Disable Suggestions'),
        widget=SwitchWidget(),
        description=_(
            "Enable this if you don't want Indico to suggest this category as"
            " a possible addition to a user's favorites."))
    is_flat_view_enabled = BooleanField(
        _('Allow flat view'),
        widget=SwitchWidget(),
        description=_(
            'Allow users to view all the events descending from this '
            'category in one single page. This is not recommended on large '
            'categories with thousands of events.'))
    event_message_mode = IndicoEnumSelectField(
        _('Message Type'),
        enum=EventMessageMode,
        default=EventMessageMode.disabled,
        description=_(
            'This message will show up at the top of every event page '
            'in this category'))
    event_message = IndicoMarkdownField(_('Content'))
    notify_managers = BooleanField(
        _('Notify managers'),
        widget=SwitchWidget(),
        description=
        _('Whether to send email notifications to all managers of this category '
          'when an event is created inside it or in any of its subcategories.'
          ))
    event_creation_notification_emails = EmailListField(
        _('Notification E-mails'),
        description=_('List of emails that will receive a notification '
                      'every time a new event is created inside the '
                      'category or one of its subcategories. '
                      'One email address per line.'))
Пример #4
0
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)
    protection_mode = IndicoEnumRadioField(_('Protection mode'), enum=ProtectionMode)

    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.'))
Пример #5
0
class CategorySettingsForm(IndicoForm):
    BASIC_FIELDS = ('title', 'description', 'timezone', 'lecture_theme',
                    'meeting_theme', 'visibility', 'suggestions_disabled',
                    'event_creation_notification_emails', 'notify_managers')
    EVENT_HEADER_FIELDS = ('event_message_mode', 'event_message')

    title = StringField(_("Title"), [DataRequired()])
    description = IndicoMarkdownField(_("Description"))
    timezone = IndicoTimezoneSelectField(
        _("Timezone"), [DataRequired()],
        description=_(
            "Default timezone event lists will show up in. It will also be "
            "used as a default for new events."))
    lecture_theme = IndicoThemeSelectField(
        _("Theme for Lectures"), [DataRequired()],
        event_type=EventType.lecture,
        description=_("Default timetable theme used for lecture events"))
    meeting_theme = IndicoThemeSelectField(
        _("Theme for Meetings"), [DataRequired()],
        event_type=EventType.meeting,
        description=_("Default timetable theme used for meeting events"))
    visibility = SelectField(
        _("Event visibility"), [Optional()],
        coerce=lambda x: None if x == '' else int(x),
        description=
        _("""From which point in the category tree contents will be visible from """
          """(number of categories upwards). Applies to "Today's events" and """
          """Calendar. If the category is moved, this number will be preserved."""
          ))
    suggestions_disabled = BooleanField(
        _('Disable Suggestions'),
        widget=SwitchWidget(),
        description=_(
            "Enable this if you don't want Indico to suggest this category as"
            " a possible addition to a user's favourites."))
    event_message_mode = IndicoEnumSelectField(
        _("Message Type"),
        enum=EventMessageMode,
        default=EventMessageMode.disabled,
        description=_(
            "This message will show up at the top of every event page "
            "in this category"))
    event_message = IndicoMarkdownField(_("Content"))
    notify_managers = BooleanField(
        _("Notify managers"),
        widget=SwitchWidget(),
        description=
        _("Whether to send email notifications to all managers of this category "
          "when an event is created inside it or in any of its subcategories."
          ))
    event_creation_notification_emails = EmailListField(
        _("Notification E-mails"),
        description=_("List of emails that will receive a notification "
                      "every time a new event is created inside the "
                      "category or one of its subcategories. "
                      "One email address per line."))

    def __init__(self, *args, **kwargs):
        super(CategorySettingsForm, self).__init__(*args, **kwargs)
        category = kwargs.pop('category')
        self.visibility.choices = get_visibility_options(category,
                                                         allow_invisible=False)

        # Check if category visibility would be affected by any of the parents
        real_horizon = category.real_visibility_horizon
        own_horizon = category.own_visibility_horizon
        if real_horizon and real_horizon.is_descendant_of(own_horizon):
            self.visibility.warning = _(
                "This category's visibility is currently limited by that of '{}'."
            ).format(real_horizon.title)
Пример #6
0
class EventDatesForm(IndicoForm):
    _main_fields = ('start_dt', 'end_dt', 'timezone', 'update_timetable')
    _override_date_fields = ('start_dt_override', 'end_dt_override')

    timezone = IndicoTimezoneSelectField(_('Timezone'), [DataRequired()])
    start_dt = IndicoDateTimeField(_("Start"), [InputRequired()],
                                   allow_clear=False)
    end_dt = IndicoDateTimeField(
        _("End"),
        [InputRequired(),
         LinkedDateTime('start_dt', not_equal=True)],
        allow_clear=False)
    update_timetable = BooleanField(
        _('Update timetable'),
        widget=SwitchWidget(),
        description=_(
            "Move sessions/contributions/breaks in the timetable according "
            "to the new event start time."))
    start_dt_override = IndicoDateTimeField(
        _("Start"), [Optional()],
        allow_clear=True,
        description=_(
            "Specifying this date overrides the start date displayed "
            "on the main conference page."))
    end_dt_override = IndicoDateTimeField(
        _("End"),
        [Optional(),
         LinkedDateTime('start_dt_override', not_equal=True)],
        allow_clear=True,
        description=_("Specifying this date overrides the end date displayed "
                      "on the main conference page."))

    def __init__(self, *args, **kwargs):
        self.event = kwargs.pop('event')
        super(EventDatesForm, self).__init__(*args, **kwargs)
        # timetable synchronization
        self.check_timetable_boundaries = (self.event.type_ !=
                                           EventType.lecture)
        if self.check_timetable_boundaries:
            self.toplevel_timetable_entries = get_top_level_entries(self.event)
            if not self.toplevel_timetable_entries:
                self.check_timetable_boundaries = False
        if not self.check_timetable_boundaries:
            del self.update_timetable
        # displayed dates
        self.has_displayed_dates = (self.event.type_ == EventType.conference)
        if self.has_displayed_dates:
            start_dt = self.start_dt.data or self.start_dt.object_data
            end_dt = self.end_dt.data or self.end_dt.object_data
            self.start_dt_override.default_time = start_dt.astimezone(
                timezone(self.timezone.data)).time()
            self.end_dt_override.default_time = end_dt.astimezone(
                timezone(self.timezone.data)).time()
        else:
            del self.start_dt_override
            del self.end_dt_override

    def validate_start_dt(self, field):
        if not self.check_timetable_boundaries or self.update_timetable.data or field.object_data == field.data:
            return
        if field.data > min(self.toplevel_timetable_entries,
                            key=attrgetter('start_dt')).start_dt:
            raise ValidationError(
                _("To use this start date the timetable must be updated."))

    def validate_end_dt(self, field):
        if not self.check_timetable_boundaries:
            return
        if self.update_timetable.data:
            # if we move timetable entries according to the start date
            # change, check that there's enough time at the end.
            start_dt_offset = self.start_dt.data - self.start_dt.object_data
            end_buffer = field.data - max(self.toplevel_timetable_entries,
                                          key=attrgetter('end_dt')).end_dt
            delta = max(timedelta(), start_dt_offset - end_buffer)
            if delta:
                delta_str = format_human_timedelta(delta, 'minutes', True)
                raise ValidationError(
                    _("The event is too short to fit all timetable entries. "
                      "It must be at least {} longer.").format(delta_str))
        else:
            # if we do not update timetable entries, only check that
            # the event does not end before its last timetable entry;
            # a similar check for the start time is done above in that
            # field's validation method.
            max_end_dt = max(self.toplevel_timetable_entries,
                             key=attrgetter('end_dt')).end_dt
            if field.data < max_end_dt:
                raise ValidationError(
                    _("The event cannot end before its last timetable entry, which is at {}."
                      ).format(
                          to_unicode(
                              format_datetime(max_end_dt,
                                              timezone=self.event.tzinfo))))