Esempio n. 1
0
 def update_hierarchy(type_: Type, name: str, classes: list[str],
                      multiple: bool) -> None:
     Db.update_hierarchy({
         'id': type_.id,
         'name': name,
         'multiple': multiple
     })
     Db.add_classes_to_hierarchy(type_.id, classes)
Esempio n. 2
0
 def insert_hierarchy(type_: Type, category: str, classes: list[str],
                      multiple: bool) -> None:
     Db.insert_hierarchy({
         'id': type_.id,
         'name': type_.name,
         'multiple': multiple,
         'category': category
     })
     Db.add_classes_to_hierarchy(type_.id, classes)
Esempio n. 3
0
    def move_entities(old_type: Type, new_type_id: int,
                      checkbox_values: str) -> None:
        root = g.types[old_type.root[0]]
        entity_ids = ast.literal_eval(checkbox_values)
        delete_ids = []
        if new_type_id:  # A new type was selected
            if root.multiple:
                cleaned_entity_ids = []
                for entity in Entity.get_by_ids(entity_ids, types=True):
                    if any(type_.id == int(new_type_id)
                           for type_ in entity.types):
                        delete_ids.append(entity.id)
                    else:
                        cleaned_entity_ids.append(entity.id)
                entity_ids = cleaned_entity_ids
            if entity_ids:
                data = {
                    'old_type_id': old_type.id,
                    'new_type_id': new_type_id,
                    'entity_ids': tuple(entity_ids)
                }
                if root.name in app.config['PROPERTY_TYPES']:
                    Db.move_link_type(data)
                else:
                    Db.move_entity_type(data)
        else:
            delete_ids = entity_ids  # No new type selected so delete all links

        if delete_ids:
            if root.name in app.config['PROPERTY_TYPES']:
                Db.remove_link_type(old_type.id, delete_ids)
            else:
                Db.remove_entity_type(old_type.id, delete_ids)
Esempio n. 4
0
 def get_all() -> dict[int, Type]:
     types = {}
     for row in \
             Db.get_types('type', 'P127') + \
             Db.get_types('type_anthropology', 'P127') + \
             Db.get_types('administrative_unit', 'P89'):
         type_ = Type(row)
         types[type_.id] = type_
         type_.count = row['count'] if row['count'] \
             else row['count_property']
         type_.count_subs = 0
         type_.subs = []
         type_.root = [row['super_id']] if row['super_id'] else []
     Type.populate_subs(types)
     return types
Esempio n. 5
0
 def populate_subs(types: dict[int, Type]) -> None:
     hierarchies = {row['id']: row for row in Db.get_hierarchies()}
     for type_ in types.values():
         if type_.root:
             super_ = types[type_.root[-1]]
             super_.subs.append(type_.id)
             type_.root = Type.get_root_path(types, type_, type_.root[-1],
                                             type_.root)
             type_.category = hierarchies[type_.root[0]]['category']
         else:
             type_.category = hierarchies[type_.id]['category']
             type_.multiple = hierarchies[type_.id]['multiple']
             type_.directional = hierarchies[type_.id]['directional']
             for class_ in g.classes.values():
                 if class_.hierarchies and type_.id in class_.hierarchies:
                     type_.classes.append(class_.name)
Esempio n. 6
0
 def remove_by_entity_and_type(entity_id: int, type_id: int) -> None:
     Db.remove_by_entity_and_type(entity_id, type_id)
Esempio n. 7
0
 def remove_class_from_hierarchy(class_name: str,
                                 hierarchy_id: int) -> None:
     Db.remove_class_from_hierarchy(class_name, hierarchy_id)
Esempio n. 8
0
 def get_form_count(root_type: Type, class_name: str) -> Optional[int]:
     if type_ids := Type.get_all_sub_ids(root_type):
         return Db.get_form_count(class_name, type_ids)