Ejemplo n.º 1
0
def hierarchy_update(id_: int) -> Union[str, Response]:
    hierarchy = g.types[id_]
    if hierarchy.category in ('standard', 'system'):
        abort(403)
    form = build_form('hierarchy', hierarchy)
    form.classes.choices = Type.get_class_choices(hierarchy)
    linked_entities = set()
    has_multiple_links = False
    for entity in get_entities_linked_to_type_recursive(id_, []):
        if entity.id in linked_entities:
            has_multiple_links = True
            break
        linked_entities.add(entity.id)
    if hasattr(form, 'multiple') and has_multiple_links:
        form.multiple.render_kw = {'disabled': 'disabled'}
    if form.validate_on_submit():
        if form.name.data != hierarchy.name and Type.get_types(form.name.data):
            flash(_('error name exists'), 'error')
        else:
            Transaction.begin()
            try:
                Type.update_hierarchy(hierarchy,
                                      sanitize(form.name.data),
                                      form.classes.data,
                                      multiple=(hierarchy.category == 'value'
                                                or (hasattr(form, 'multiple')
                                                    and form.multiple.data)
                                                or has_multiple_links))
                hierarchy.update(process_form_data(form, hierarchy))
                Transaction.commit()
            except Exception as e:  # pragma: no cover
                Transaction.rollback()
                logger.log('error', 'database', 'transaction failed', e)
                flash(_('error transaction'), 'error')
                abort(418)
            flash(_('info update'), 'info')
        tab = 'value' if g.types[id_].category == 'value' else 'custom'
        return redirect(
            f"{url_for('type_index')}#menu-tab-{tab}_collapse-{hierarchy.id}")
    form.multiple = hierarchy.multiple
    table = Table(paging=False)
    for class_name in hierarchy.classes:
        count = Type.get_form_count(hierarchy, class_name)
        table.rows.append([
            g.classes[class_name].label,
            format_number(count) if count else link(
                _('remove'),
                url_for(
                    'remove_class', id_=hierarchy.id, class_name=class_name))
        ])
    return render_template('display_form.html',
                           form=form,
                           table=table,
                           manual_page='entity/type',
                           title=_('types'),
                           crumbs=[[_('types'),
                                    url_for('type_index')], hierarchy,
                                   _('edit')])
Ejemplo n.º 2
0
 def get_node_overview() -> dict[str, dict[Entity, str]]:
     nodes: dict[str, Any] = {
         'standard': {},
         'custom': {},
         'place': {},
         'value': {},
         'system': {},
         'anthropology': {}
     }
     for node in g.types.values():
         if node.root:
             continue
         nodes[node.category][node.name] = GetNodeOverview.walk_tree(
             Type.get_types(node.name))
     return nodes
Ejemplo n.º 3
0
 def get_node_overview() -> dict[str, dict[Entity, str]]:
     nodes: dict[str, Any] = {
         'standard': [],
         'custom': [],
         'place': [],
         'value': [],
         'system': [],
         'anthropology': []}
     for node in g.types.values():
         if node.root:
             continue
         nodes[node.category].append({
             "id": node.id,
             "name": node.name,
             "viewClass": node.classes,
             "children":
                 GetTypeOverview.walk_tree(Type.get_types(node.name))})
     return nodes
Ejemplo n.º 4
0
def type_index() -> str:
    types: dict[str, dict[Entity, str]] = {
        'standard': {},
        'custom': {},
        'place': {},
        'value': {},
        'system': {}
    }
    for type_ in [type_ for type_ in g.types.values() if not type_.root]:
        if type_.category not in types:
            continue  # pragma: no cover, remove after anthropology features
        types[type_.category][type_] = render_template(
            'forms/tree_select_item.html',
            name=sanitize(type_.name),
            data=walk_tree(Type.get_types(type_.name)))
    return render_template('type/index.html',
                           types=types,
                           title=_('types'),
                           crumbs=[_('types')])
Ejemplo n.º 5
0
 def prepare_feature_types() -> None:
     for category_id in Type.get_types('Features for sexing'):
         for id_ in g.types[category_id].subs:
             SexEstimation.features[g.types[id_].name]['id'] = \
                 g.types[id_].id