def hierarchy_update(id_: int) -> Union[str, Response]: hierarchy = g.nodes[id_] if hierarchy.standard: abort(403) form = build_form('hierarchy', hierarchy) form.forms.choices = Node.get_form_choices(hierarchy) if hasattr(form, 'multiple') and form.multiple.data: form.multiple.render_kw = {'disabled': 'disabled'} if form.validate_on_submit(): if form.name.data != hierarchy.name and Node.get_nodes(form.name.data): flash(_('error name exists'), 'error') else: save(form, hierarchy) flash(_('info update'), 'info') tab = 'value' if g.nodes[id_].value_type else 'custom' return redirect( f"{url_for('node_index')}#menu-tab-{tab}_collapse-{hierarchy.id}") form.multiple = hierarchy.multiple table = Table(paging=False) for form_id, form_ in hierarchy.forms.items(): count = Node.get_form_count(hierarchy, form_id) table.rows.append([ g.classes[form_['name']].label, format_number(count) if count else link( _('remove'), url_for('remove_form', id_=hierarchy.id, form_id=form_id)) ]) return render_template('display_form.html', form=form, table=table, manual_page='entity/type', title=_('types'), crumbs=[[_('types'), url_for('node_index')], hierarchy, _('edit')])
def remove_form(id_: int, form_id: int) -> Response: root = g.nodes[id_] if Node.get_form_count(root, form_id): abort(403) # pragma: no cover try: Node.remove_form_from_hierarchy(form_id, root.id) flash(_('info update'), 'info') except Exception as e: # pragma: no cover logger.log('error', 'database', 'remove form from hierarchy failed', e) flash(_('error database'), 'error') return redirect(url_for('hierarchy_update', id_=id_))