def _get_next_activity_form(request, counter): """ Return the form used to configure the next activity """ form = deform.Form(schema=CreateActivitySchema().bind(request=request), use_ajax=True, buttons=(NEW_ACTIVITY_BUTTON, ), **_get_next_activity_form_options(request, counter)) return form
class ActivityEditView(BaseFormView): """ Activity Edition View, entry point for activity recording, allow to modify metadatas, provide forms for other actions : recording program new activity """ add_template_vars = ( 'title', 'next_activity_form', 'record_form', ) schema = CreateActivitySchema() @property def title(self): """ Dynamic page title """ participants = self.request.context.participants participants_list = [ render_api.format_account(account) for account in participants ] return u"Accompagnement de {0}".format(", ".join(participants_list)) @property def next_activity_form(self): form = _get_next_activity_form(self.request, self.counter) form.set_appstruct(self.get_appstruct()) return form.render() @property def record_form(self): """ Return a form for recording the activity informations This form's submission will be handled in the ajax_submission page """ submit_url = self.request.route_path( "activity", id=self.request.context.id, _query=dict(action="record"), ) form = deform.Form( schema=RecordActivitySchema().bind(request=self.request), buttons=( ACTIVITY_RECORD_BUTTON, ACTIVITY_CANCEL_BUTTON, ACTIVITY_PDF_BUTTON, ), counter=self.counter, formid="record_form", action=submit_url, ) form.set_appstruct(self.get_appstruct()) auto_need(form) return form.render() def get_appstruct(self): return _get_appstruct_from_activity(self.request.context) def before(self, form): """ fill the form before it will be handled """ populate_actionmenu(self.request) self.counter = form.counter appstruct = self.get_appstruct() form.set_appstruct(appstruct) auto_need(form) timepicker_fr.need() def submit_success(self, appstruct): """ called when the edition form is submitted """ appstruct = handle_rel_in_appstruct(appstruct) message = u"Les informations ont bien été mises à jour" return record_changes(self.request, appstruct, message, query_options={'action': 'edit'})