def get_project_form(request): """ Returns the project add/edit form """ schema = get_project_schema().bind(request=request) form = Form(schema, buttons=(submit_btn, )) form.widget = GridFormWidget(named_grid=FORM_GRID) return form
def get_project_form(request): """ Returns the project add/edit form """ schema = get_project_schema().bind(request=request) form = Form(schema, buttons=(submit_btn,)) form.widget = GridFormWidget(grid=FORM_GRID) return form
class ProjectAdd(BaseFormView): add_template_vars = ( 'title', 'codes', ) title = u"Ajout d'un nouveau projet" schema = get_project_schema() buttons = (submit_btn, ) validation_msg = u"Le projet a été ajouté avec succès" @property def codes(self): codes = [(project.code, project.name) \ for project in self.context.projects] codes.sort() return codes def before(self, form): populate_actionmenu(self.request) form.widget = GridFormWidget(grid=FORM_GRID) # If there's no customer, redirect to customer view if len(self.request.context.customers) == 0: redirect_to_customerslist(self.request, self.request.context) def submit_success(self, appstruct): """ Add a project with a default phase in the database """ if self.context.__name__ == 'company': # It's an add form model = self.schema.objectify(appstruct) model.company = self.context # Add a default phase to the project default_phase = Phase() model.phases.append(default_phase) self.dbsession.add(model) else: # It's an edition one model = self.schema.objectify(appstruct, self.context) model = self.dbsession.merge(model) self.dbsession.flush() self.session.flash(self.validation_msg) return HTTPFound(self.request.route_path('project', id=model.id))