def post(self, participant_id, field_slug): participant = self.get_object(participant_id) cf = self.get_custom_field(participant, field_slug) if participant.participant_type == Participant.PARTICIPANT: form_class = ParticipantEditForm g.rule_type = Rule.PARTICIPANT else: form_class = MediaParticipantEditForm g.rule_type = Rule.MEDIA field_types = [CustomField.IMAGE] Object = custom_object_factory(participant, field_types) Form = custom_form_factory(form_class, field_slugs=[field_slug]) form = Form(obj=Object()) if form.validate(): form.save(participant) cfv = (cf.custom_field_values.filter_by( participant=participant).scalar()) if cfv: data = get_custom_file_as_filestorage(cfv.value) else: data = {} else: return make_response(jsonify(form.errors), 400) html = render_template('meetings/custom_field/_image_widget.html', data=data) return jsonify(html=html)
def post(self, participant_id, field_slug): participant = self.get_object(participant_id) cf = self.get_custom_field(participant, field_slug) if participant.participant_type == Participant.PARTICIPANT: form_class = ParticipantEditForm else: form_class = MediaParticipantEditForm field_types = [CustomField.IMAGE] Object = custom_object_factory(participant, field_types) Form = custom_form_factory(form_class, field_slugs=[field_slug]) form = Form(obj=Object()) if form.validate(): form.save(participant) cfv = (cf.custom_field_values.filter_by(participant=participant) .scalar()) if cfv: data = get_custom_file_as_filestorage(cfv.value) else: data = {} else: return make_response(jsonify(form.errors), 400) html = render_template('meetings/custom_field/_image_widget.html', data=data) return jsonify(html=html)
def get(self, participant_id=None): participant = self.get_object(participant_id) Form = self.get_form() Object = custom_object_factory(participant) form = Form(obj=Object()) return render_template(self.template, form=form, participant=participant)
def get(self, participant_id): participant = self._get_queryset(participant_id) Form = custom_form_factory(self.form_class) Object = custom_object_factory(participant) form = Form(obj=Object()) return render_template(self.template, participant=participant, form=form)
def get(self): queryset = self.get_queryset() participants = search_for_participant(request.args['search'], queryset) results = [] Form = custom_form_factory(self.form_class) for p in participants: Object = custom_object_factory(p) form = Form(obj=Object()) info = self.serialize_participant(form) info['value'] = p.name results.append(info) return json.dumps(results, cls=JSONEncoder)
def test_custom_form_factory(app): pic = ProfilePictureFactory() upload_dir = local(app.config['UPLOADED_CUSTOM_DEST']) upload_dir.ensure(pic.value) g.meeting = pic.participant.meeting field_types = [CustomField.IMAGE] Obj = custom_object_factory(pic.participant, field_types) Form = custom_form_factory(ParticipantEditForm, field_slugs=[pic.custom_field.label.english]) with app.test_request_context(): form = Form(obj=Obj()) assert pic.custom_field.label.english in form._fields
def test_custom_object_factory(app): pic = ProfilePictureFactory() g.meeting = pic.custom_field.meeting badge_field = CustomFieldFactory(label__english='badge', meeting=g.meeting) badge = ProfilePictureFactory(participant=pic.participant, custom_field=badge_field) attrs = (pic.custom_field.label.english, badge.custom_field.label.english) field_types = [CustomField.IMAGE] Obj = custom_object_factory(pic.participant, field_types) for attr in attrs: assert attr in Obj.__dict__
def post(self, participant_id=None): participant = self.get_object(participant_id) Form = self.get_form() Object = custom_object_factory(participant) form = Form(obj=Object()) if form.validate(): participant = form.save(participant) flash("Person information saved", "success") is_created = True if participant_id else False self._edit_signals(participant, is_created) return redirect(self.get_success_url(participant)) return render_template(self.template, form=form, participant=participant)
def get(self): queryset = self.get_queryset() participants = search_for_participant(request.args["search"], queryset) results = [] Form = custom_form_factory(self.form_class) for p in participants: Object = custom_object_factory(p) form = Form(obj=Object()) info = self.serialize_participant(form) info["value"] = p.name results.append(info) return json.dumps(results, cls=JSONEncoder)
def get(self): Form = custom_form_factory(self.form_class, registration_fields=True) form = Form() header_phrase = self.get_header_phrase() footer_phrase = self.get_footer_phrase() if current_user.is_authenticated: participant = self.get_default_participant(current_user) Object = custom_object_factory(participant) form = Form(obj=Object()) return render_template(self.template_name, form=form, header_phrase=header_phrase, footer_phrase=footer_phrase)
def post(self, participant_id=None): participant = self.get_object(participant_id) Form = self.get_form() Object = custom_object_factory(participant) form = Form(obj=Object()) if form.validate(): participant = form.save(participant) flash('Person information saved', 'success') is_created = True if participant_id else False self._edit_signals(participant, is_created) return redirect(self.get_success_url(participant)) return render_template(self.template, form=form, participant=participant)
def get(self): registration_token = session.get('registration_token', None) if not registration_token: abort(400) session.pop('registration_token', None) participant = (Participant.query.filter_by( registration_token=registration_token).first_or_404()) if participant.language: set_language(participant.lang) if participant.participant_type == Participant.PARTICIPANT: class_form = ParticipantEditForm g.rule_type = Rule.PARTICIPANT else: class_form = MediaParticipantEditForm g.rule_type = Rule.MEDIA Form = custom_form_factory(class_form) Object = custom_object_factory(participant) form = Form(obj=Object()) return render_template('meetings/registration/user_success.html', form=form)