def update(id_: int) -> Union[str, Response]: entity = Entity.get_by_id(id_, types=True, aliases=True) check_update_access(entity) if entity.check_for_too_many_links_for_single_type(): abort(422) place_info = get_place_info_for_update(entity) form = build_form(entity.class_.name, entity, location=place_info['location']) if form.validate_on_submit(): if isinstance(entity, Type) and not check_type(entity, form): return redirect(url_for('view', id_=entity.id)) if was_modified(form, entity): # pragma: no cover del form.save flash(_('error modified'), 'error') return render_template( 'entity/update.html', form=form, entity=entity, modifier=link(logger.get_log_info(entity.id)['modifier'])) return redirect(save(form, entity)) populate_update_form(form, entity) if entity.class_.view in ['artifact', 'place']: entity.set_image_for_places() return render_template( 'entity/update.html', form=form, entity=entity, gis_data=place_info['gis_data'], overlays=place_info['overlays'], geonames_module=check_geonames_module(entity.class_.name), title=entity.name, crumbs=add_crumbs(entity.class_.name, entity, place_info['structure']))
def index(view: str, delete_id: Optional[int] = None) -> Union[str, Response]: if delete_id: # Delete before showing index to prevent additional redirect if current_user.group == 'contributor': # pragma: no cover info = logger.get_log_info(delete_id) if not info['creator'] or info['creator'].id != current_user.id: abort(403) if url := delete_entity(delete_id): return redirect(url)
def display_delete_link(entity: Union[Entity, Type]) -> str: from openatlas.models.type import Type confirm = '' if isinstance(entity, Type): url = url_for('type_delete', id_=entity.id) if entity.count or entity.subs: url = url_for('type_delete_recursive', id_=entity.id) else: if current_user.group == 'contributor': # pragma: no cover info = logger.get_log_info(entity.id) if not info['creator'] or info['creator'].id != current_user.id: return '' url = url_for('index', view=entity.class_.view, delete_id=entity.id) confirm = _('Delete %(name)s?', name=entity.name.replace('\'', '')) return button(_('delete'), url, onclick=f"return confirm('{confirm}')" if confirm else '')
def get_system_data(entity: Entity) -> dict[str, Any]: data = {} if 'entity_show_class' in current_user.settings \ and current_user.settings['entity_show_class']: data[_('class')] = link(entity.cidoc_class) info = logger.get_log_info(entity.id) if 'entity_show_dates' in current_user.settings \ and current_user.settings['entity_show_dates']: data[_('created')] = \ f"{format_date(entity.created)} {link(info['creator'])}" if info['modified']: data[_('modified')] = \ f"{format_date(info['modified'])} {link(info['modifier'])}" if 'entity_show_import' in current_user.settings \ and current_user.settings['entity_show_import']: data[_('imported from')] = link(info['project']) data[_('imported by')] = link(info['importer']) data['origin ID'] = info['origin_id'] if 'entity_show_api' in current_user.settings \ and current_user.settings['entity_show_api']: data['API'] = render_template('util/api_links.html', entity=entity) return data
def overview() -> str: tabs = { 'info': Tab('info'), 'bookmarks': Tab('bookmarks', table=Table(['name', 'class', 'begin', 'end'])), 'notes': Tab('notes', table=Table( ['date', _('visibility'), 'entity', 'class', _('note')])) } tables = { 'overview': Table(paging=False, defs=[{ 'className': 'dt-body-right', 'targets': 1 }]), 'latest': Table(paging=False, order=[[0, 'desc']]) } if current_user.is_authenticated and hasattr(current_user, 'bookmarks'): for entity_id in current_user.bookmarks: entity = Entity.get_by_id(entity_id) tabs['bookmarks'].table.rows.append([ link(entity), entity.class_.label, entity.first, entity.last, bookmark_toggle(entity.id, True) ]) for note in User.get_notes_by_user_id(current_user.id): entity = Entity.get_by_id(note['entity_id']) tabs['notes'].table.rows.append([ format_date(note['created']), uc_first(_('public') if note['public'] else _('private')), link(entity), entity.class_.label, note['text'], f'<a href="{url_for("note_view", id_=note["id"])}">' f'{uc_first(_("view"))}</a>' ]) for name, count in Entity.get_overview_counts().items(): if not count: continue # pragma: no cover url = url_for('index', view=g.class_view_mapping[name]) if name == 'administrative_unit': url = f"{url_for('type_index')}#menu-tab-place" elif name == 'type': url = url_for('type_index') elif name in [ 'feature', 'human_remains', 'stratigraphic_unit', 'source_translation' ]: url = '' tables['overview'].rows.append([ link(g.classes[name].label, url) if url else g.classes[name].label, format_number(count) ]) for entity in Entity.get_latest(10): tables['latest'].rows.append([ format_date(entity.created), link(entity), entity.class_.label, entity.first, entity.last, link(logger.get_log_info(entity.id)['creator']) ]) tabs['info'].content = render_template('index/index.html', intro=get_translation('intro'), tables=tables) return render_template('tabs.html', tabs=tabs, crumbs=['overview'])