Beispiel #1
0
    def _process(self):
        defaults = FormDefaults(self.plugin.get_vc_room_attach_form_defaults(self.event_new))
        form = self.plugin.vc_room_attach_form(
            prefix="vc-", obj=defaults, event=self.event_new, service=self.plugin.service_name
        )

        if form.validate_on_submit():
            vc_room = form.data["room"]
            if not self.plugin.can_manage_vc_rooms(session.user, self.event_new):
                flash(
                    _("You are not allowed to attach {plugin_name} rooms to this event.").format(
                        plugin_name=self.plugin.friendly_name
                    ),
                    "error",
                )
            elif not self.plugin.can_manage_vc_room(session.user, vc_room):
                flash(_("You are not authorized to attach the room '{room.name}'".format(room=vc_room)), "error")
            else:
                event_vc_room = process_vc_room_association(self.plugin, self.event_new, vc_room, form)
                if event_vc_room:
                    flash(_("The room has been attached to the event."), "success")
                    db.session.add(event_vc_room)
            return redirect_or_jsonify(url_for(".manage_vc_rooms", self.event_new), flash=False)

        return WPVCManageEvent.render_template(
            "attach_room.html",
            self._conf,
            event=self.event_new,
            form=form,
            skip_fields=form.conditional_fields | {"room"},
            plugin=self.plugin,
        )
Beispiel #2
0
 def _process(self):
     action = request.args.get('vc_room_action', '.manage_vc_rooms_create')
     return WPVCManageEvent.render_template(
         'manage_event_select.html',
         self._conf,
         vc_room_action=action,
         event=self._conf,
         plugins=get_vc_plugins().values())
Beispiel #3
0
 def _process(self):
     try:
         room_event_assocs = VCRoomEventAssociation.find_for_event(self._conf, include_hidden=True,
                                                                   include_deleted=True).all()
     except ValueError:
         raise IndicoError(_('This page is not available for legacy events.'))
     event_vc_rooms = [event_vc_room for event_vc_room in room_event_assocs if event_vc_room.vc_room.plugin]
     return WPVCManageEvent.render_template('manage_event.html', self._conf, event=self._conf,
                                            event_vc_rooms=event_vc_rooms, plugins=get_vc_plugins().values())
Beispiel #4
0
 def _process(self):
     action = request.args.get("vc_room_action", ".manage_vc_rooms_create")
     attach = request.args.get("attach", "")
     return WPVCManageEvent.render_template(
         "manage_event_select.html",
         self._conf,
         vc_room_action=action,
         event=self.event_new,
         plugins=get_vc_plugins().values(),
         attach=attach,
     )
Beispiel #5
0
 def _process(self):
     room_event_assocs = VCRoomEventAssociation.find_for_event(
         self.event, include_hidden=True, include_deleted=True).all()
     event_vc_rooms = [
         event_vc_room for event_vc_room in room_event_assocs
         if event_vc_room.vc_room.plugin
     ]
     return WPVCManageEvent.render_template(
         'manage_event.html',
         self.event,
         event_vc_rooms=event_vc_rooms,
         plugins=get_vc_plugins().values())
Beispiel #6
0
 def _process(self):
     room_event_assocs = VCRoomEventAssociation.find_for_event(
         self.event_new, include_hidden=True, include_deleted=True
     ).all()
     event_vc_rooms = [event_vc_room for event_vc_room in room_event_assocs if event_vc_room.vc_room.plugin]
     return WPVCManageEvent.render_template(
         "manage_event.html",
         self._conf,
         event=self.event_new,
         event_vc_rooms=event_vc_rooms,
         plugins=get_vc_plugins().values(),
     )
Beispiel #7
0
    def _process(self):
        if not self.plugin.can_manage_vc_rooms(session.user, self.event_new):
            flash(
                _('You are not allowed to create {plugin_name} rooms for this event.'
                  ).format(plugin_name=self.plugin.friendly_name), 'error')
            return redirect(url_for('.manage_vc_rooms', self.event_new))

        form = self.plugin.create_form(event=self.event_new)

        if form.validate_on_submit():
            vc_room = VCRoom(created_by_user=session.user)
            vc_room.type = self.plugin.service_name
            vc_room.status = VCRoomStatus.created

            event_vc_room = process_vc_room_association(
                self.plugin, self.event_new, vc_room, form)
            if not event_vc_room:
                return redirect(url_for('.manage_vc_rooms', self.event_new))

            with db.session.no_autoflush:
                self.plugin.update_data_vc_room(vc_room, form.data)

            try:
                # avoid flushing the incomplete vc room to the database
                with db.session.no_autoflush:
                    self.plugin.create_room(vc_room, self.event_new)
                notify_created(self.plugin, vc_room, event_vc_room,
                               self.event_new, session.user)
            except VCRoomError as err:
                if err.field is None:
                    raise
                field = getattr(form, err.field)
                field.errors.append(err.message)
                transaction.abort(
                )  # otherwise the incomplete vc room would be added to the db!
            else:
                db.session.add(vc_room)
                # TODO: notify_created(vc_room, self.event_new, session.user)

                flash(
                    _("{plugin_name} room '{room.name}' created").format(
                        plugin_name=self.plugin.friendly_name, room=vc_room),
                    'success')
                return redirect(url_for('.manage_vc_rooms', self.event_new))

        form_html = self.plugin.render_form(plugin=self.plugin,
                                            event=self.event_new,
                                            form=form,
                                            skip_fields=form.skip_fields
                                            | {'name'})

        return WPVCManageEvent.render_string(form_html, self.event)
Beispiel #8
0
    def _process(self):
        if not self.plugin.can_manage_vc_rooms(session.user, self.event):
            flash(_('You are not allowed to modify {} rooms for this event.').format(self.plugin.friendly_name),
                  'error')
            return redirect(url_for('.manage_vc_rooms', self.event))

        form = self.plugin.create_form(self.event,
                                       existing_vc_room=self.vc_room,
                                       existing_event_vc_room=self.event_vc_room)

        if form.validate_on_submit():

            self.plugin.update_data_vc_room(self.vc_room, form.data)

            event_vc_room = process_vc_room_association(
                self.plugin, self.event, self.vc_room, form, event_vc_room=self.event_vc_room, allow_same_room=True)
            if not event_vc_room:
                return redirect(url_for('.manage_vc_rooms', self.event))

            self.vc_room.modified_dt = now_utc()

            try:
                self.plugin.update_room(self.vc_room, self.event)
            except VCRoomNotFoundError as err:
                Logger.get('modules.vc').warning("VC room {} not found. Setting it as deleted.".format(self.vc_room))
                self.vc_room.status = VCRoomStatus.deleted
                flash(err.message, 'error')
                return redirect(url_for('.manage_vc_rooms', self.event))
            except VCRoomError as err:
                if err.field is None:
                    raise
                field = getattr(form, err.field)
                field.errors.append(err.message)
                transaction.abort()
            else:
                # TODO
                # notify_modified(self.vc_room, self.event, session.user)

                flash(_("{plugin_name} room '{room.name}' updated").format(
                    plugin_name=self.plugin.friendly_name, room=self.vc_room), 'success')
                return redirect(url_for('.manage_vc_rooms', self.event))

        form_html = self.plugin.render_form(plugin=self.plugin, event=self.event, form=form,
                                            existing_vc_room=self.vc_room,
                                            skip_fields=form.skip_fields | {'name'})

        return WPVCManageEvent.render_string(form_html, self.event)
Beispiel #9
0
    def _process(self):
        if not self.plugin.can_manage_vc_rooms(session.avatar, self.event):
            flash(_('You are not allowed to modify {} rooms for this event.').format(self.plugin.friendly_name),
                  'error')
            return redirect(url_for('.manage_vc_rooms', self.event))

        form = self.plugin.create_form(self.event,
                                       existing_vc_room=self.vc_room,
                                       existing_event_vc_room=self.event_vc_room)

        if form.validate_on_submit():

            self.plugin.update_data_vc_room(self.vc_room, form.data)

            event_vc_room = process_vc_room_association(
                self.plugin, self.event, self.vc_room, form, event_vc_room=self.event_vc_room, allow_same_room=True)
            if not event_vc_room:
                return redirect(url_for('.manage_vc_rooms', self.event))

            self.vc_room.modified_dt = now_utc()

            try:
                self.plugin.update_room(self.vc_room, self.event)
            except VCRoomNotFoundError as err:
                Logger.get('modules.vc').warning("VC room {} not found. Setting it as deleted.".format(self.vc_room))
                self.vc_room.status = VCRoomStatus.deleted
                flash(err.message, 'error')
                return redirect(url_for('.manage_vc_rooms', self.event))
            except VCRoomError as err:
                if err.field is None:
                    raise
                field = getattr(form, err.field)
                field.errors.append(err.message)
                transaction.abort()
            else:
                # TODO
                # notify_modified(self.vc_room, self.event, session.avatar)

                flash(_("{plugin_name} room '{room.name}' updated").format(
                    plugin_name=self.plugin.friendly_name, room=self.vc_room), 'success')
                return redirect(url_for('.manage_vc_rooms', self.event))

        form_html = self.plugin.render_form(plugin=self.plugin, event=self.event, form=form,
                                            existing_vc_room=self.vc_room,
                                            skip_fields=form.skip_fields | {'name'})

        return WPVCManageEvent.render_string(form_html, self.event)
Beispiel #10
0
    def _process(self):
        if not self.plugin.can_manage_vc_rooms(session.user, self.event):
            flash(_('You are not allowed to create {plugin_name} rooms for this event.').format(
                plugin_name=self.plugin.friendly_name), 'error')
            return redirect(url_for('.manage_vc_rooms', self.event))

        form = self.plugin.create_form(event=self.event)

        if form.validate_on_submit():
            vc_room = VCRoom(created_by_user=session.user)
            vc_room.type = self.plugin.service_name
            vc_room.status = VCRoomStatus.created

            event_vc_room = process_vc_room_association(self.plugin, self.event, vc_room, form)
            if not event_vc_room:
                return redirect(url_for('.manage_vc_rooms', self.event))

            with db.session.no_autoflush:
                self.plugin.update_data_vc_room(vc_room, form.data)

            try:
                # avoid flushing the incomplete vc room to the database
                with db.session.no_autoflush:
                    self.plugin.create_room(vc_room, self.event)
                notify_created(self.plugin, vc_room, event_vc_room, self.event, session.user)
            except VCRoomError as err:
                if err.field is None:
                    raise
                field = getattr(form, err.field)
                field.errors.append(err.message)
                transaction.abort()  # otherwise the incomplete vc room would be added to the db!
            else:
                db.session.add(vc_room)
                # TODO: notify_created(vc_room, self.event, session.user)

                flash(_("{plugin_name} room '{room.name}' created").format(
                    plugin_name=self.plugin.friendly_name, room=vc_room), 'success')
                return redirect(url_for('.manage_vc_rooms', self.event))

        form_html = self.plugin.render_form(plugin=self.plugin, event=self.event, form=form,
                                            skip_fields=form.skip_fields | {'name'})

        return WPVCManageEvent.render_string(form_html, self.event)
Beispiel #11
0
    def _process(self):
        defaults = FormDefaults(self.plugin.get_vc_room_attach_form_defaults(self.event))
        form = self.plugin.vc_room_attach_form(prefix='vc-', obj=defaults, event=self.event,
                                               service=self.plugin.service_name)

        if form.validate_on_submit():
            vc_room = form.data['room']
            if not self.plugin.can_manage_vc_rooms(session.avatar, self.event):
                flash(_("You are not allowed to attach {plugin_name} rooms to this event.").format(
                    plugin_name=self.plugin.friendly_name), 'error')
            elif not self.plugin.can_manage_vc_room(session.avatar, vc_room):
                flash(_("You are not authorized to attach the room '{room.name}'".format(room=vc_room)), 'error')
            else:
                event_vc_room = process_vc_room_association(self.plugin, self.event, vc_room, form)
                if event_vc_room:
                    flash(_("The room has been attached to the event."), 'success')
                    db.session.add(event_vc_room)
            return redirect_or_jsonify(url_for('.manage_vc_rooms', self.event), flash=False)

        return WPVCManageEvent.render_template('attach_room.html', self._conf, event=self._conf, form=form,
                                               skip_fields=form.conditional_fields | {'room'},
                                               plugin=self.plugin)
Beispiel #12
0
    def _process(self):
        if not self.plugin.can_manage_vc_rooms(session.avatar, self.event):
            flash(_('You are not allowed to create {plugin_name} rooms for this event.').format(
                plugin_name=self.plugin.friendly_name), 'error')
            return redirect(url_for('.manage_vc_rooms', self.event))

        form = self.plugin.create_form(event=self.event)

        if form.validate_on_submit():
            vc_room = VCRoom(created_by_user=session.avatar)
            vc_room.type = self.plugin.service_name
            vc_room.status = VCRoomStatus.created

            event_vc_room = process_vc_room_association(self.plugin, self.event, vc_room, form)
            if not event_vc_room:
                return redirect(url_for('.manage_vc_rooms', self.event))

            self.plugin.update_data_vc_room(vc_room, form.data)

            try:
                self.plugin.create_room(vc_room, self.event)
                notify_created(self.plugin, vc_room, event_vc_room, self.event, session.avatar)
            except VCRoomError as err:
                if err.field is None:
                    raise
                field = getattr(form, err.field)
                field.errors.append(err.message)
            else:
                db.session.add_all((vc_room, event_vc_room))
                # TODO: notify_created(vc_room, self.event, session.avatar)

                flash(_("{plugin_name} room '{room.name}' created").format(
                    plugin_name=self.plugin.friendly_name, room=vc_room), 'success')
                return redirect(url_for('.manage_vc_rooms', self.event))

        form_html = self.plugin.render_form(plugin=self.plugin, event=self.event, form=form,
                                            skip_fields=form.skip_fields | {'name'})

        return WPVCManageEvent.render_string(form_html, self.event)
Beispiel #13
0
 def _process(self):
     action = request.args.get('vc_room_action', '.manage_vc_rooms_create')
     attach = request.args.get('attach', '')
     return WPVCManageEvent.render_template('manage_event_select.html', self._conf, vc_room_action=action,
                                            event=self.event_new, plugins=get_vc_plugins().values(), attach=attach)