def _process(self): self.regform.is_deleted = True signals.event.registration_form_deleted.send(self.regform) flash(_("Registration form deleted"), 'success') logger.info("Registration form %s deleted by %s", self.regform, session.user) return redirect(url_for('.manage_regform_list', self.event))
def _process_DELETE(self): if self.section.type == RegistrationFormItemType.section_pd: raise BadRequest self.section.is_deleted = True db.session.flush() logger.info('Section %s deleted by %s', self.section, session.user) return jsonify(success=True)
def create_registration(regform, data, invitation=None, management=False, notify_user=True): registration = Registration(registration_form=regform, user=get_user_by_email(data['email']), base_price=regform.base_price, currency=regform.currency) for form_item in regform.active_fields: if form_item.parent.is_manager_only: with db.session.no_autoflush: value = form_item.field_impl.default_value else: value = data.get(form_item.html_field_name) with db.session.no_autoflush: data_entry = RegistrationData() registration.data.append(data_entry) for attr, value in form_item.field_impl.process_form_data(registration, value).iteritems(): setattr(data_entry, attr, value) if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column: setattr(registration, form_item.personal_data_type.column, value) if invitation is None: # Associate invitation based on email in case the user did not use the link with db.session.no_autoflush: invitation = (RegistrationInvitation .find(email=data['email'], registration_id=None) .with_parent(regform) .first()) if invitation: invitation.state = InvitationState.accepted invitation.registration = registration registration.sync_state(_skip_moderation=management) db.session.flush() notify_registration_creation(registration, notify_user) logger.info('New registration %s by %s', registration, session.user) regform.event.log(EventLogRealm.management if management else EventLogRealm.participants, EventLogKind.positive, 'Registration', 'New registration: {}'.format(registration.full_name), session.user, data={'Email': registration.email}) return registration
def _process_DELETE(self): if self.field.type == RegistrationFormItemType.field_pd: raise BadRequest self.field.is_deleted = True _remove_regform_item_gaps(self.regform.form_items, self.field.position) db.session.flush() logger.info('Field %s deleted by %s', self.field, session.user) return jsonify()
def _process(self): check_in = request.form['flag'] == '1' msg = 'checked-in' if check_in else 'not checked-in' for registration in self.registrations: registration.checked_in = check_in logger.info('Registration %s marked as %s by %s', registration, msg, session.user) flash(_("Selected registrations marked as {} successfully.").format(msg), 'success') return jsonify_data(**self.list_generator.render_list())
def _process(self): section = RegistrationFormSection(registration_form=self.regform) section.title = request.json['title'] section.description = request.json.get('description') section.is_manager_only = request.json['is_manager_only'] db.session.add(section) db.session.flush() logger.info('Section %s created by %s', section, session.user) return jsonify_data(**section.view_data)
def _modify_registration_status(registration, approve): if approve: registration.update_state(approved=True) else: registration.update_state(rejected=True) db.session.flush() notify_registration_state_update(registration) status = 'approved' if approve else 'rejected' logger.info('Registration %s was %s by %s', registration, status, session.user)
def _process_PATCH(self): changes = request.json['changes'] if set(changes.viewkeys()) > {'title', 'description'}: raise BadRequest for field, value in changes.iteritems(): setattr(self.section, field, value) db.session.flush() logger.info('Section %s modified by %s: %s', self.section, session.user, changes) return jsonify(self.section.view_data)
def _process(self): self.regform.end_dt = now_utc() if not self.regform.has_started: self.regform.start_dt = self.regform.end_dt flash( _("Registrations for {} are now closed").format( self.regform.title), 'success') logger.info("Registrations for %s closed by %s", self.regform, session.user) return redirect(url_for('.manage_regform', self.regform))
def _process(self): if self.regform.has_ended: self.regform.end_dt = None else: self.regform.start_dt = now_utc() logger.info("Registrations for %s opened by %s", self.regform, session.user) flash( _("Registrations for {} are now open").format(self.regform.title), 'success') return redirect(url_for('.manage_regform', self.regform))
def _process_POST(self): enabled = request.args.get('enable') == 'true' if not enabled and self.section.type == RegistrationFormItemType.section_pd: raise BadRequest self.section.is_enabled = enabled db.session.flush() if self.section.is_enabled: logger.info('Section %s enabled by %s', self.section, session.user) else: logger.info('Section %s disabled by %s', self.section, session.user) return jsonify_data(**self.section.view_data)
def _process(self): for registration in self.registrations: registration.is_deleted = True signals.event.registration_deleted.send(registration) logger.info('Registration %s deleted by %s', registration, session.user) self.event.log(EventLogRealm.management, EventLogKind.negative, 'Registration', 'Registration deleted: {}'.format(registration.full_name), session.user, data={'Email': registration.email}) num_reg_deleted = len(self.registrations) flash(ngettext("Registration was deleted.", "{num} registrations were deleted.", num_reg_deleted).format(num=num_reg_deleted), 'success') return jsonify_data()
def _process(self): form = RegistrationFormScheduleForm(obj=FormDefaults(self.regform), regform=self.regform) if form.validate_on_submit(): self.regform.start_dt = form.start_dt.data self.regform.end_dt = form.end_dt.data self.regform.modification_end_dt = form.modification_end_dt.data flash( _("Registrations for {} have been scheduled").format( self.regform.title), 'success') logger.info("Registrations for %s scheduled by %s", self.regform, session.user) return jsonify_data(flash=False) return jsonify_form(form, submit=_('Schedule'))
def modify_registration(registration, data, management=False, notify_user=True): old_price = registration.price personal_data_changes = {} with db.session.no_autoflush: regform = registration.registration_form data_by_field = registration.data_by_field if management or not registration.user: registration.user = get_user_by_email(data['email']) billable_items_locked = not management and registration.is_paid for form_item in regform.active_fields: field_impl = form_item.field_impl if management or not form_item.parent.is_manager_only: value = data.get(form_item.html_field_name) elif form_item.id not in data_by_field: # set default value for manager-only field if it didn't have one before value = field_impl.default_value else: # manager-only field that has data which should be preserved continue if form_item.id not in data_by_field: data_by_field[form_item.id] = RegistrationData(registration=registration, field_data=form_item.current_data) attrs = field_impl.process_form_data(registration, value, data_by_field[form_item.id], billable_items_locked=billable_items_locked) for key, val in attrs.iteritems(): setattr(data_by_field[form_item.id], key, val) if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column: key = form_item.personal_data_type.column if getattr(registration, key) != value: personal_data_changes[key] = value setattr(registration, key, value) registration.sync_state() db.session.flush() # sanity check if billable_items_locked and old_price != registration.price: raise Exception("There was an error while modifying your registration (price mismatch: %s / %s)", old_price, registration.price) if personal_data_changes: signals.event.registration_personal_data_modified.send(registration, change=personal_data_changes) notify_registration_modification(registration, notify_user) logger.info('Registration %s modified by %s', registration, session.user) regform.event.log(EventLogRealm.management if management else EventLogRealm.participants, EventLogKind.change, 'Registration', 'Registration modified: {}'.format(registration.full_name), session.user, data={'Email': registration.email})
def _process(self): enabled = request.args.get('enable') == 'true' if (not enabled and self.field.type == RegistrationFormItemType.field_pd and self.field.personal_data_type.is_required): raise BadRequest if not enabled: _remove_regform_item_gaps(self.regform.form_items, self.field.position) positions = [ x.position for x in self.regform.form_items if x.is_enabled == enabled ] self.field.position = max( positions) + 1 if positions else FIRST_DISABLED_POSITION self.field.is_enabled = enabled db.session.flush() logger.info('Field %s modified by %s', self.field, session.user) return jsonify(view_data=self.field.view_data)