def hierarchy_update(id_: int) -> str: root = g.nodes[id_] if root.system: abort(403) form = build_form(HierarchyForm, 'hierarchy', root) # type: HierarchyForm form.forms.choices = NodeMapper.get_form_choices(root) if root.value_type: del form.multiple elif root.multiple: form.multiple.render_kw = {'disabled': 'disabled'} if form.validate_on_submit(): if form.name.data != root.name and NodeMapper.get_nodes(form.name.data): flash(_('error name exists'), 'error') return redirect(url_for('node_index') + '#tab-' + str(root.id)) save(form, root) flash(_('info update'), 'info') return redirect(url_for('node_index') + '#tab-' + str(root.id)) form.multiple = root.multiple table = Table(['form', 'count'], paging=False) for form_id, form_ in root.forms.items(): url = url_for('hierarchy_remove_form', id_=root.id, remove_id=form_id) link = '<a href="' + url + '">' + uc_first(_('remove')) + '</a>' count = NodeMapper.get_form_count(root, form_id) table.rows.append([form_['name'], format_number(count) if count else link]) return render_template('hierarchy/update.html', node=root, form=form, table=table, forms=[form.id for form in form.forms])
def hierarchy_update(id_): root = g.nodes[id_] if root.system: abort(403) form = build_form(HierarchyForm, 'hierarchy', root) form.forms.choices = NodeMapper.get_form_choices(root) if root.value_type: del form.multiple elif root.multiple: form.multiple.render_kw = {'disabled': 'disabled'} if form.validate_on_submit(): if form.name.data != root.name and NodeMapper.get_nodes(form.name.data): flash(_('error name exists'), 'error') return redirect(url_for('node_index') + '#tab-' + str(root.id)) save(form, root) flash(_('info update'), 'info') return redirect(url_for('node_index') + '#tab-' + str(root.id)) form.multiple = root.multiple table = {'id': 'used_forms', 'show_pager': False, 'data': [], 'sort': 'sortList: [[0, 0]]', 'header': ['form', 'count']} for form_id, form_ in root.forms.items(): url = url_for('hierarchy_remove_form', id_=root.id, remove_id=form_id) link = '<a href="' + url + '">' + uc_first(_('remove')) + '</a>' count = NodeMapper.get_form_count(root, form_id) table['data'].append([form_['name'], format_number(count) if count else link]) return render_template('hierarchy/update.html', node=root, form=form, table=table, forms=[form.id for form in form.forms])
def hierarchy_insert(param: str) -> str: form = build_form(HierarchyForm, 'hierarchy') # type: HierarchyForm form.forms.choices = NodeMapper.get_form_choices() if param == 'value': del form.multiple if form.validate_on_submit(): if NodeMapper.get_nodes(form.name.data): flash(_('error name exists'), 'error') return render_template('hierarchy/insert.html', form=form) node = save(form, value_type=True if param == 'value' else False) flash(_('entity created'), 'info') return redirect(url_for('node_index') + '#tab-' + str(node.id)) return render_template('hierarchy/insert.html', form=form, param=param)
def hierarchy_insert(param): form = build_form(HierarchyForm, 'hierarchy') form.forms.choices = NodeMapper.get_form_choices() if param == 'value': del form.multiple if form.validate_on_submit(): if NodeMapper.get_nodes(form.name.data): flash(_('error name exists'), 'error') return render_template('hierarchy/insert.html', form=form) node = save(form, value_type=True if param == 'value' else False) flash(_('entity created'), 'info') return redirect(url_for('node_index') + '#tab-' + str(node.id)) return render_template('hierarchy/insert.html', form=form, param=param)
def hierarchy_update(id_): node = g.nodes[id_] if node.system: abort(403) form = build_form(HierarchyForm, 'hierarchy', node) form.forms.choices = NodeMapper.get_form_choices() if node.value_type: del form.multiple elif node.multiple: form.multiple.render_kw = {'disabled': 'disabled'} if form.validate_on_submit(): if form.name.data != node.name and NodeMapper.get_nodes(form.name.data): flash(_('error name exists'), 'error') return redirect(url_for('node_index') + '#tab-' + str(node.id)) save(form, node) flash(_('info update'), 'info') return redirect(url_for('node_index') + '#tab-' + str(node.id)) form.multiple = node.multiple return render_template( 'hierarchy/update.html', node=node, form=form, forms=[form.id for form in form.forms])