示例#1
0
class NewBookingConfirmForm(NewBookingPeriodForm):
    booked_for_user = PrincipalField(_(u'User'), [DataRequired()],
                                     allow_external=True)
    contact_email = StringField(
        _(u'Email'),
        [InputRequired(), IndicoEmail(multi=True)])
    contact_phone = StringField(_(u'Telephone'))
    booking_reason = TextAreaField(_(u'Reason'), [DataRequired()])
    uses_vc = BooleanField(_(u'I will use videoconference equipment'))
    used_equipment = IndicoQuerySelectMultipleCheckboxField(
        _(u'VC equipment'), get_label=lambda x: x.name)
    needs_vc_assistance = BooleanField(
        _(u'Request assistance for the startup of the videoconference session. '
          u'This support is usually performed remotely.'))
    needs_assistance = BooleanField(
        _(u'Request personal assistance for meeting startup'))
    submit_book = SubmitField(_(u'Create booking'))
    submit_prebook = SubmitField(_(u'Create pre-booking'))

    def validate_used_equipment(self, field):
        if field.data and not self.uses_vc.data:
            raise ValidationError(_(u'Videoconference equipment is not used.'))
        elif not field.data and self.uses_vc.data:
            raise ValidationError(
                _(u'You need to select some Videoconference equipment'))

    def validate_needs_vc_assistance(self, field):
        if field.data and not self.uses_vc.data:
            raise ValidationError(_(u'Videoconference equipment is not used.'))
示例#2
0
文件: rooms.py 项目: zilehuda/indico
    def _make_form(self):
        room = self._room

        # New class so we can safely extend it
        form_class = type('RoomFormWithAttributes', (RoomForm, ), {})

        # Default values
        defaults = None
        if room.id is not None:
            skip_name = set() if room.has_special_name else {'name'}
            defaults = FormDefaults(
                room,
                skip_attrs={'nonbookable_periods', 'bookable_hours'}
                | skip_name)
            for ra in room.attributes.all():
                defaults['attribute_{}'.format(ra.attribute_id)] = ra.value

        # Custom attributes - new fields must be set on the class
        for attribute in self._location.attributes.order_by(
                RoomAttribute.parent_id).all():
            validators = [DataRequired()] if attribute.is_required else []
            if attribute.name == 'notification-email':
                validators.append(IndicoEmail(multi=True))
            field_name = 'attribute_{}'.format(attribute.id)
            field = StringField(attribute.title, validators)
            setattr(form_class, field_name, field)

        # Create the form
        form = form_class(obj=defaults)

        # Default values, part 2
        if not form.is_submitted() and room.id is not None:
            # This is ugly, but apparently FieldList+FormField does not work well with obj defaults
            for i, nbd in enumerate(room.nonbookable_periods.all()):
                if i >= len(form.nonbookable_periods.entries):
                    form.nonbookable_periods.append_entry()
                form.nonbookable_periods[
                    i].start_date.data = nbd.start_dt.date()
                form.nonbookable_periods[
                    i].start_time.data = nbd.start_dt.time()
                form.nonbookable_periods[i].end_date.data = nbd.end_dt.date()
                form.nonbookable_periods[i].end_time.data = nbd.end_dt.time()

            for i, bt in enumerate(room.bookable_hours.all()):
                if i >= len(form.bookable_hours.entries):
                    form.bookable_hours.append_entry()
                form.bookable_hours[i].start.data = bt.start_time
                form.bookable_hours[i].end.data = bt.end_time

        # Custom attributes, part 2
        form._attribute_fields = [
            field_ for name, field_ in form._fields.iteritems()
            if name.startswith('attribute_')
        ]

        # Equipment
        form.available_equipment.query = self._location.equipment_types.order_by(
            EquipmentType.name)

        return form
示例#3
0
class PluginSettingsForm(IndicoForm):
    managers = PrincipalListField(_('Managers'), groups=True,
                                  description=_('List of users who can manage recording/webcast requests.'))
    notification_emails = EmailListField(_('Notification email addresses'),
                                         description=_('Notifications about recording/webcast requests are sent to '
                                                       'these email addresses (one per line).'))
    notification_reply_email = StringField(_('E-mail notification "reply" address'),
                                           [IndicoEmail()],
                                           description=_('Notifications that are sent to event managers will use '
                                                         'this address in their "Reply-To:" fields.'))
    webcast_audiences = MultipleItemsField(_('Webcast Audiences'),
                                           fields=[{'id': 'audience', 'caption': _('Audience'), 'required': True}],
                                           unique_field='audience',
                                           description=_('List of audiences for non-public webcasts.'))
    webcast_ping_url = URLField(_('Webcast Ping URL'),
                                description=_("A ping is sent via HTTP GET to this URL whenever a webcast request "
                                              "enters/leaves the 'accepted' state."))
    webcast_url = URLField(_('Webcast URL'), [DataRequired()],
                           description=_("The URL to watch the webcast for an event. Can contain {event_id} which "
                                         "will be replaced with the ID of the event."))
    agreement_paper_url = URLField(_('Agreement Paper URL'),
                                   description=_("The URL to the agreement that can be printed and signed offline."))
    recording_cds_url = URLField(_('CDS URL'),
                                 description=_("The URL used when creating recording links. Must contain the {cds_id} "
                                               "placeholder."))
    room_feature = QuerySelectField(_("Room feature"), [DataRequired()], allow_blank=True,
                                    query_factory=lambda: RoomFeature.query, get_label='title',
                                    description=_("The feature indicating that a room supports webcast/recording."))

    def validate_recording_cds_url(self, field):
        if field.data and '{cds_id}' not in field.data:
            raise ValidationError('{cds_id} placeholder is missing')
示例#4
0
文件: forms.py 项目: mkopcic/indico
class RegistrationFormForm(IndicoForm):
    _price_fields = ('currency', 'base_price')
    _registrant_notification_fields = ('notification_sender_address',
                                       'message_pending', 'message_unpaid',
                                       'message_complete')
    _manager_notification_fields = ('manager_notifications_enabled',
                                    'manager_notification_recipients')
    _special_fields = _price_fields + _registrant_notification_fields + _manager_notification_fields

    title = StringField(_("Title"), [DataRequired()],
                        description=_("The title of the registration form"))
    introduction = TextAreaField(
        _("Introduction"),
        description=
        _("Introduction to be displayed when filling out the registration form"
          ))
    contact_info = StringField(
        _("Contact info"),
        description=
        _("How registrants can get in touch with somebody for extra information"
          ))
    moderation_enabled = BooleanField(
        _("Moderated"),
        widget=SwitchWidget(),
        description=_("If enabled, registrations require manager approval"))
    require_login = BooleanField(
        _("Only logged-in users"),
        widget=SwitchWidget(),
        description=_("Users must be logged in to register"))
    require_user = BooleanField(
        _("Registrant must have account"),
        widget=SwitchWidget(),
        description=_(
            "Registrations emails must be associated with an Indico account"))
    limit_registrations = BooleanField(
        _("Limit registrations"),
        widget=SwitchWidget(),
        description=_("Whether there is a limit of registrations"))
    registration_limit = IntegerField(
        _("Capacity"), [
            HiddenUnless('limit_registrations'),
            DataRequired(),
            NumberRange(min=1)
        ],
        description=_("Maximum number of registrations"))
    modification_mode = IndicoEnumSelectField(
        _("Modification allowed"),
        enum=ModificationMode,
        description=_("Will users be able to modify their data? When?"))
    publish_registrations_enabled = BooleanField(
        _('Publish registrations'),
        widget=SwitchWidget(),
        description=_("Registrations from this form will be displayed in the "
                      "event page"))
    publish_registration_count = BooleanField(
        _("Publish number of registrations"),
        widget=SwitchWidget(),
        description=_("Number of registered participants will be displayed in "
                      "the event page"))
    publish_checkin_enabled = BooleanField(
        _('Publish check-in status'),
        widget=SwitchWidget(),
        description=_(
            "Check-in status will be shown publicly on the event page"))
    base_price = DecimalField(
        _('Registration fee'), [
            NumberRange(min=0, max=999999.99),
            Optional(), _check_if_payment_required
        ],
        filters=[lambda x: x if x is not None else 0],
        widget=NumberInput(step='0.01'),
        description=_("A fixed fee all users have to pay when registering."))
    currency = SelectField(_('Currency'), [DataRequired()],
                           description=_('The currency for new registrations'))
    notification_sender_address = StringField(_('Notification sender address'),
                                              [IndicoEmail()],
                                              filters=[lambda x: (x or None)])
    message_pending = TextAreaField(
        _("Message for pending registrations"),
        description=_("Text included in emails sent to pending registrations"))
    message_unpaid = TextAreaField(
        _("Message for unpaid registrations"),
        description=_("Text included in emails sent to unpaid registrations"))
    message_complete = TextAreaField(
        _("Message for complete registrations"),
        description=_(
            "Text included in emails sent to complete registrations"))
    manager_notifications_enabled = BooleanField(
        _('Enabled'),
        widget=SwitchWidget(),
        description=_("Enable notifications to managers about registrations"))
    manager_notification_recipients = EmailListField(
        _('List of recipients'), [
            HiddenUnless('manager_notifications_enabled', preserve_data=True),
            DataRequired()
        ],
        description=_("Email addresses that will receive notifications"))

    def __init__(self, *args, **kwargs):
        self.event = kwargs.pop('event')
        super().__init__(*args, **kwargs)
        self._set_currencies()
        self.notification_sender_address.description = _(
            'Email address set as the sender of all '
            'notifications sent to users. If empty, '
            'then {} is used.'.format(config.NO_REPLY_EMAIL))

    def _set_currencies(self):
        currencies = [(c['code'], '{0[code]} ({0[name]})'.format(c))
                      for c in payment_settings.get('currencies')]
        self.currency.choices = sorted(currencies, key=lambda x: x[1].lower())
示例#5
0
 def validators(self):
     return [IndicoEmail()]