コード例 #1
0
ファイル: forms.py プロジェクト: ipaste/indico
class RoleForm(IndicoForm):
    name = StringField(_('Name'), [DataRequired()],
                       description=_('The full name of the role'))
    code = StringField(
        _('Abbreviation'), [DataRequired(), Length(max=3)],
        filters=[lambda x: x.upper() if x else ''],
        render_kw={
            'style': 'width:60px; text-align:center; text-transform:uppercase;'
        },
        description=_('A shortcut (max. 3 characters) for the role'))
    color = StringField(
        _('Colour'),
        [DataRequired(), Regexp(r'^[0-9A-Fa-f]{6}$')],
        filters=[lambda x: (x or '').replace('#', '')],
        widget=ColorPickerWidget(show_field=False),
        default='#00a4e4',
        description=_('The colour used when displaying the role'))

    def __init__(self, *args, **kwargs):
        self.role = kwargs.get('obj')
        self.event = kwargs.pop('event')
        super(RoleForm, self).__init__(*args, **kwargs)

    def validate_code(self, field):
        query = EventRole.query.with_parent(
            self.event).filter_by(code=field.data)
        if self.role is not None:
            query = query.filter(EventRole.id != self.role.id)
        if query.has_rows():
            raise ValueError(
                _('A role with this abbreviation already exists.'))
コード例 #2
0
ファイル: forms.py プロジェクト: timgates42/indico
class ConferenceLayoutForm(LoggedLayoutForm):
    is_searchable = BooleanField(_("Enable search"), widget=SwitchWidget(),
                                 description=_("Enable search within the event"))
    show_nav_bar = BooleanField(_("Show navigation bar"), widget=SwitchWidget(),
                                description=_("Show the navigation bar at the top"))
    show_banner = BooleanField(_("\"Now happening\""), widget=SwitchWidget(on_label=_("ON"), off_label=_("OFF")),
                               description=_("Show a banner with the current entries from the timetable"))
    show_social_badges = BooleanField(_("Show social badges"), widget=SwitchWidget())
    name_format = IndicoEnumSelectField(_('Name format'), enum=NameFormat, none=_('Inherit from user preferences'),
                                        description=_('Format in which names are displayed'))

    # Style
    header_text_color = StringField(_("Text colour"), widget=ColorPickerWidget())
    header_background_color = StringField(_("Background colour"), widget=ColorPickerWidget())

    # Announcement
    announcement = StringField(_("Announcement"),
                               [UsedIf(lambda form, field: form.show_announcement.data)],
                               description=_("Short message shown below the title"))
    show_announcement = BooleanField(_("Show announcement"), widget=SwitchWidget(),
                                     description=_("Show the announcement message"))

    # Timetable
    timetable_by_room = BooleanField(_("Group by room"), widget=SwitchWidget(),
                                     description=_("Group the entries of the timetable by room by default"))
    timetable_detailed = BooleanField(_("Show detailed view"), widget=SwitchWidget(),
                                      description=_("Show the detailed view of the timetable by default."))
    timetable_theme = SelectField(_('Theme'), [Optional()], coerce=lambda x: x or None)
    # Themes
    use_custom_css = BooleanField(_("Use custom CSS"), widget=SwitchWidget(),
                                  description=_("Use a custom CSS file as a theme for the conference page. Deactivate "
                                                "this option to reveal the available Indico themes."))
    theme = SelectField(_("Theme"), [Optional(), HiddenUnless('use_custom_css', False)],
                        coerce=lambda x: (x or None),
                        description=_("Currently selected theme of the conference page. Click on the Preview button to "
                                      "preview and select a different one."))

    def __init__(self, *args, **kwargs):
        self.event = kwargs.pop('event')
        super(ConferenceLayoutForm, self).__init__(*args, **kwargs)
        self.timetable_theme.choices = [('', _('Default'))] + _get_timetable_theme_choices(self.event)
        self.theme.choices = _get_conference_theme_choices()

    def validate_use_custom_css(self, field):
        if field.data and not self.event.has_stylesheet:
            raise ValidationError(_('Cannot enable custom stylesheet unless there is one.'))