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 hierarchy_insert(param: str) -> Union[str, Response]: form = build_form('hierarchy', code=param) form.forms.choices = Node.get_form_choices() if form.validate_on_submit(): if Node.check_hierarchy_exists(form.name.data): flash(_('error name exists'), 'error') return render_template('display_form.html', form=form) save(form, param=param) flash(_('entity created'), 'info') return redirect(url_for('node_index') + '#menu-tab-' + param) return render_template( 'display_form.html', form=form, manual_page='entity/type', title=_('types'), crumbs=[[_('types'), url_for('node_index')], '+ ' + uc_first(_(param))])