Ejemplo n.º 1
0
def node_move_entities(id_: int) -> Union[str, Response]:
    node = g.nodes[id_]
    root = g.nodes[node.root[-1]]
    if root.value_type:  # pragma: no cover
        abort(403)
    form = build_move_form(node)
    if form.validate_on_submit():
        Transaction.begin()
        Node.move_entities(node,
                           getattr(form, str(root.id)).data,
                           form.checkbox_values.data)
        Transaction.commit()
        flash(_('Entities were updated'), 'success')
        if node.class_.name == 'administrative_unit':
            tab = 'places'
        elif root.standard:
            tab = 'standard'
        elif node.value_type:  # pragma: no cover
            tab = 'value'
        else:
            tab = 'custom'
        return redirect(
            f"{url_for('node_index')}#menu-tab-{tab}_collapse-{root.id}")
    getattr(form, str(root.id)).data = node.id
    return render_template('types/move.html',
                           table=Table(header=['#', _('selection')],
                                       rows=[[item, item.label.text]
                                             for item in form.selection]),
                           root=root,
                           form=form,
                           entity=node,
                           crumbs=[[_('types'),
                                    url_for('node_index')], root, node,
                                   _('move entities')])
Ejemplo n.º 2
0
def node_move_entities(id_: int) -> Union[str, Response]:
    node = g.nodes[id_]
    root = g.nodes[node.root[-1]]
    if node.class_.name == 'administrative_unit':
        tab_hash = '#menu-tab-places_collapse-'
    elif root.standard:
        tab_hash = '#menu-tab-standard_collapse-'
    elif node.value_type:  # pragma: no cover
        tab_hash = '#menu-tab-value_collapse-'
    else:
        tab_hash = '#menu-tab-custom_collapse-'
    if root.value_type:  # pragma: no cover
        abort(403)
    form = build_move_form(node)
    if form.validate_on_submit():
        Transaction.begin()
        Node.move_entities(node, getattr(form, str(root.id)).data, form.checkbox_values.data)
        Transaction.commit()
        flash(_('Entities were updated'), 'success')
        return redirect(url_for('node_index') + tab_hash + str(root.id))
    getattr(form, str(root.id)).data = node.id
    return render_template(
        'types/move.html',
        node=node,
        root=root,
        form=form,
        title=_('types'),
        crumbs=[[_('types'), url_for('node_index')], root, node, _('move entities')])