def add_sub_department(self, location): c.menu_items = location_edit_menu_items(location) c.current_menu_item = 'sub-departments' form = Form(location, request, schema=SubDepartmentAddForm(), action='ADD') result = form.work() if result is not None: sub_department = SubDepartment(result['title'], location) sub_department.site_url = result['site_url'] sub_department.description = result['description'] meta.Session.commit() redirect(location.url(action='edit_sub_departments')) c.form = form return render('location/add_sub_department.mako')
def edit_sub_department(self, location): sub_department_id = request.urlvars['id'] sub_department = SubDepartment.get(sub_department_id) c.menu_items = location_edit_menu_items(location) c.current_menu_item = 'sub-departments' form = Form(sub_department, request, defaults={'title': sub_department.title, 'site_url': sub_department.site_url, 'description': sub_department.description}, schema=SubDepartmentAddForm(), action='UPDATE') result = form.work() if result is not None: sub_department.title = result['title'] sub_department.site_url = result['site_url'] sub_department.description = result['description'] meta.Session.commit() redirect(location.url(action='edit_sub_departments')) c.form = form return render('location/edit_sub_department.mako')