def admin_orphans() -> str: header = [ 'name', 'class', 'type', 'system type', 'created', 'updated', 'description' ] tables = { 'orphans': Table(header), 'unlinked': Table(header), 'missing_files': Table(header), 'circular': Table(['entity']), 'nodes': Table(['name', 'root']), 'orphaned_files': Table(['name', 'size', 'date', 'ext']) } tables['circular'].rows = [[link(entity)] for entity in Entity.get_circular()] for entity in Entity.get_orphans(): if isinstance(entity, ReferenceSystem): continue name = 'unlinked' if entity.class_.view else 'orphans' tables[name].rows.append([ link(entity), link(entity.class_), entity.print_standard_type(), entity.class_.label, format_date(entity.created), format_date(entity.modified), entity.description ]) for node in Node.get_node_orphans(): tables['nodes'].rows.append([link(node), link(g.nodes[node.root[-1]])]) # Get orphaned file entities with no corresponding file entity_file_ids = [] for entity in Entity.get_by_class('file', nodes=True): entity_file_ids.append(entity.id) if not get_file_path(entity): tables['missing_files'].rows.append([ link(entity), link(entity.class_), entity.print_standard_type(), entity.class_.label, format_date(entity.created), format_date(entity.modified), entity.description ]) # Get orphaned files with no corresponding entity for file in app.config['UPLOAD_DIR'].iterdir(): if file.name != '.gitignore' and int(file.stem) not in entity_file_ids: tables['orphaned_files'].rows.append([ file.stem, convert_size(file.stat().st_size), format_date( datetime.datetime.utcfromtimestamp(file.stat().st_ctime)), file.suffix, link(_('download'), url_for('download_file', filename=file.name)), delete_link(file.name, url_for('admin_file_delete', filename=file.name)) ]) return render_template( 'admin/check_orphans.html', tables=tables, title=_('admin'), crumbs=[[_('admin'), url_for('admin_index') + '#tab-data'], _('orphans')])
def admin_orphans() -> str: header = [ 'name', 'class', 'type', 'system type', 'created', 'updated', 'description'] tabs = { 'orphans': Tab('orphans', table=Table(header)), 'unlinked': Tab('unlinked', table=Table(header)), 'nodes': Tab('type', table=Table( ['name', 'root'], [[link(node), link(g.nodes[node.root[-1]])] for node in Node.get_node_orphans()])), 'missing_files': Tab('missing_files', table=Table(header)), 'orphaned_files': Tab( 'orphaned_files', table=Table(['name', 'size', 'date', 'ext'])), 'circular': Tab('circular_dependencies', table=Table( ['entity'], [[link(e)] for e in Entity.get_entities_linked_to_itself()]))} for entity in filter( lambda x: not isinstance(x, ReferenceSystem), Entity.get_orphans()): tabs[ 'unlinked' if entity.class_.view else 'orphans'].table.rows.append([ link(entity), link(entity.class_), link(entity.standard_type), entity.class_.label, format_date(entity.created), format_date(entity.modified), entity.description]) # Orphaned file entities with no corresponding file entity_file_ids = [] for entity in Entity.get_by_class('file', nodes=True): entity_file_ids.append(entity.id) if not get_file_path(entity): tabs['missing_files'].table.rows.append([ link(entity), link(entity.class_), link(entity.standard_type), entity.class_.label, format_date(entity.created), format_date(entity.modified), entity.description]) # Orphaned files with no corresponding entity for file in app.config['UPLOAD_DIR'].iterdir(): if file.name != '.gitignore' and int(file.stem) not in entity_file_ids: tabs['orphaned_files'].table.rows.append([ file.stem, convert_size(file.stat().st_size), format_date( datetime.datetime.utcfromtimestamp(file.stat().st_ctime)), file.suffix, link( _('download'), url_for('download_file', filename=file.name)), delete_link( file.name, url_for('admin_file_delete', filename=file.name))]) for tab in tabs.values(): tab.buttons = [manual('admin/data_integrity_checks')] if not tab.table.rows: tab.content = _('Congratulations, everything looks fine!') if tabs['orphaned_files'].table.rows and is_authorized('admin'): text = uc_first(_('delete all files without corresponding entities?')) tabs['orphaned_files'].buttons.append( button( _('delete all files'), url_for('admin_file_delete', filename='all'), onclick=f"return confirm('{text}')")) return render_template( 'tabs.html', tabs=tabs, title=_('admin'), crumbs=[ [_('admin'), f"{url_for('admin_index')}#tab-data"], _('orphans')])