def create_question(self): template_vars = { 'page_title': 'Create Question', 'username': self.request.username, 'question_choices': forms.get_question_select_options(self.request.route_url('question_creation_form')), } if self.request.method == 'POST': try: schema, question_type = forms.get_question_creation_schema(self.request.POST) action = self.request.route_path('create_question', question_set_id=self.request.question_set.id) form = Form(schema.bind(request=self.request), buttons=('create',), action=action) appstruct = form.validate(self.request.POST.items()) question_set_id = self.request.matchdict['question_set_id'] Question.create(question_set_id, appstruct, self.request.db) return HTTPFound(self.request.route_url('profile')) except ValueError as e: exc = colander.Invalid(form.widget, str(e)) form.widget.handle_error(form,exc) template_vars['form'] = (question_type, form.render()) except ValidationFailure as e: template_vars['form'] = (question_type, e.render()) return template_vars
def _makeForm(self, schema): from deform.form import Form return Form(schema, formid='myform')
def _makeOne(self, schema, **kw): from deform.form import Form return Form(schema, **kw)
def my_view(request): form = Form(SampleSchema(), buttons=('up', )) return {'project': 'fileupload', 'form': form}
def _makeForm(self, schema): # Deform from deform.form import Form return Form(schema, formid="myform")
def gamedep_add_binary(context, request): check_owner(context, request) gamedeptype = request.matchdict.get('type') g = GameDepLib(gamedeptype) page_id = request.matchdict.get('page_id') binary_id = request.matchdict.get('binary_id') revision = request.matchdict.get('revision') edittype = request.matchdict.get('edittype') try: bin_obj = g.show_binary(binary_id) except GameDepNotFound: bin_obj = None if binary_id and edittype: pass # Initialise form library if not binary_id and not edittype: schema = AddBinarySchema() elif binary_id and edittype == "1": schema = EditBinarySchema() elif binary_id and edittype == "2": schema = EditOSArchSchema() else: request.session.flash(s.show_setting("ERROR_INVALID_BINARY_ID"), ERROR) return redirect(request, "gamedep_item", page_id=page_id, type=gamedeptype) schema = schema.bind(gamedep_type=gamedeptype, bin_obj=bin_obj, req_file_folder=["%s/" % page_id]) myform = Form(schema, buttons=['submit']) reqts = myform.get_widget_resources() if 'submit' in request.POST: controls = request.POST.items() try: deserialized = myform.validate(controls) except ValidationFailure as e: # Failed validation return { 'page_id': page_id, 'form': e.render(), 'js_links': reqts['js'] } # Form submitted, all validated! binary = deserialized.get("binary") operatingsystem = deserialized.get("operatingsystem") architecture = deserialized.get("architecture") if not binary_id and not edittype: g.create_binary(page_id, revision, operatingsystem, architecture, binary['fp'], binary['mimetype'], binary['filename'], request) request.session.flash( s.show_setting("INFO_BINARY_ADDED") % binary['filename'], INFO) else: g.update_binary(page_id, revision, binary_id, operatingsystem, architecture, binary, request) request.session.flash( s.show_setting("INFO_BINARY_UPDATED") % binary['filename'], INFO) return redirect(request, "gamedep_item", page_id=page_id, type=gamedeptype) # Display default form return { 'page_id': page_id, 'form': myform.render(), 'js_links': reqts['js'] }