def profile_index() -> str: tabs = {'profile': Tab( 'profile', content=display_info(get_form_settings(ProfileForm(), True)), buttons=[manual('tools/profile')])} if is_authorized('contributor'): tabs['modules'] = Tab( 'modules', content=display_info(get_form_settings(ModulesForm(), True)), buttons=[manual('tools/profile')]) tabs['display'] = Tab( 'display', content=display_info(get_form_settings(DisplayForm(), True)), buttons=[manual('tools/profile')]) if not app.config['DEMO_MODE']: tabs['profile'].buttons += [ button(_('edit'), url_for('profile_settings', category='profile')), button(_('change password'), url_for('profile_password'))] tabs['modules'].buttons.append( button(_('edit'), url_for('profile_settings', category='modules'))) tabs['display'].buttons.append( button(_('edit'), url_for('profile_settings', category='display'))) return render_template( 'tabs.html', tabs=tabs, title=_('profile'), crumbs=[_('profile')])
def add_buttons(entity: Entity, type_problem: bool = False) -> list[str]: if not is_authorized(entity.class_.write_access): return [] # pragma: no cover buttons = [] if isinstance(entity, Type): if entity.root and entity.category != 'system': buttons.append(button(_('edit'), url_for('update', id_=entity.id))) buttons.append(display_delete_link(entity)) elif isinstance(entity, ReferenceSystem): buttons.append(button(_('edit'), url_for('update', id_=entity.id))) if not entity.classes and not entity.system: buttons.append(display_delete_link(entity)) elif entity.class_.name == 'source_translation': buttons.append(button(_('edit'), url_for('update', id_=entity.id))) buttons.append(display_delete_link(entity)) else: if not type_problem: buttons.append(button(_('edit'), url_for('update', id_=entity.id))) if entity.class_.view != 'place' \ or not entity.get_linked_entities('P46'): buttons.append(display_delete_link(entity)) if entity.class_.name == 'stratigraphic_unit': buttons.append( button(_('tools'), url_for('anthropology_index', id_=entity.id))) return buttons
def note_view(id_: int) -> str: note = User.get_note_by_id(id_) if not note['public'] and note['user_id'] != current_user.id: abort(403) # pragma: no cover entity = Entity.get_by_id(note['entity_id']) buttons: list[str] = [manual('tools/notes')] if note['user_id'] == current_user.id: buttons += [ button(_('edit'), url_for('note_update', id_=note['id'])), button(_('delete'), url_for('note_delete', id_=note['id'])) ] elif is_authorized('manager'): # pragma: no cover buttons += [ button(_('set private'), url_for('note_set_private', id_=note['id'])) ] tabs = { 'info': Tab('info', buttons=buttons, content=f"<h1>{uc_first(_('note'))}</h1>{note['text']}") } return render_template('tabs.html', tabs=tabs, entity=entity, crumbs=[[ _(entity.class_.view), url_for('index', view=entity.class_.view) ], link(entity), _('note')])
def add_tabs_for_reference_system(entity: ReferenceSystem) -> dict[str, Tab]: tabs = {} for name in entity.classes: tabs[name] = Tab( name, entity=entity, table=Table([_('entity'), 'id', _('precision')])) for link_ in entity.get_links('P67'): name = link_.description if entity.resolver_url: name = \ f'<a href="{entity.resolver_url}{name}"' \ f' target="_blank" rel="noopener noreferrer">{name}</a>' tabs[link_.range.class_.name].table.rows.append([ link(link_.range), name, link_.type.name]) for name in entity.classes: tabs[name].buttons = [] if not tabs[name].table.rows and is_authorized('manager'): tabs[name].buttons = [button( _('remove'), url_for( 'reference_system_remove_class', system_id=entity.id, class_name=name))] return tabs
def sex(id_: int) -> Union[str, Response]: entity = Entity.get_by_id(id_, types=True) buttons = [manual('tools/anthropological_analyses')] if is_authorized('contributor'): buttons.append(button(_('edit'), url_for('sex_update', id_=entity.id))) data = [] for item in SexEstimation.get_types(entity): type_ = g.types[item['id']] feature = SexEstimation.features[type_.name] data.append({ 'name': type_.name, 'category': feature['category'], 'feature_value': feature['value'], 'option_value': SexEstimation.options[item['description']], 'value': item['description'] }) return render_template('anthropology/sex.html', entity=entity, buttons=buttons, data=data, result=print_result(entity), crumbs=[ entity, [ _('anthropological analyses'), url_for('anthropology_index', id_=entity.id) ], _('sex estimation') ])
def overlay_update(id_: int) -> Union[str, Response]: overlay = Overlay.get_by_id(id_) form = OverlayForm() if form.validate_on_submit(): Overlay.update(form=form, image_id=overlay.image_id, place_id=overlay.place_id) flash(_('info update'), 'info') return redirect( f"{url_for('entity_view', id_=overlay.place_id)}#tab-file") bounding = ast.literal_eval(overlay.bounding_box) if len(bounding) == 2: # pragma no cover bounding = [[0, 0], [0, 0], [0, 0]] # For data entered before 6.4.0 form.top_left_easting.data = bounding[0][1] form.top_left_northing.data = bounding[0][0] form.top_right_easting.data = bounding[1][1] form.top_right_northing.data = bounding[1][0] form.bottom_left_easting.data = bounding[2][1] form.bottom_left_northing.data = bounding[2][0] entity = Entity.get_by_id(overlay.place_id) return render_template( 'overlay.html', form=form, overlay=overlay, entity=entity, buttons=[ button(_('remove'), url_for('overlay_remove', id_=overlay.id, place_id=entity.id), onclick=f"return confirm('{uc_first(_('remove'))}?');") ], crumbs=[[_('place'), url_for('index', view='place')], entity, Entity.get_by_id(overlay.image_id), _('update overlay')])
def get_buttons(view: str) -> list[str]: buttons = [] for name in [view] if view in ['artifact', 'place'] \ else g.view_class_mapping[view]: if is_authorized(g.classes[name].write_access): buttons.append( button(g.classes[name].label, url_for('insert', class_=name))) return buttons
def anthropology_index(id_: int) -> Union[str, Response]: entity = Entity.get_by_id(id_) buttons = [ manual('tools/anthropological_analyses'), button(_('sex estimation'), url_for('sex', id_=entity.id)), print_result(entity) ] return render_template('anthropology/index.html', entity=entity, buttons=buttons, crumbs=[entity, _('anthropological analyses')])
def add_buttons(entity: Entity) -> List[str]: if not is_authorized(entity.class_.write_access): return [] # pragma: no cover buttons = [] if isinstance(entity, Node): if entity.root and not g.nodes[entity.root[0]].locked: buttons.append(button(_('edit'), url_for('update', id_=entity.id))) if not entity.locked and entity.count < 1 and not entity.subs: buttons.append(display_delete_link(entity)) elif isinstance(entity, ReferenceSystem): buttons.append(button(_('edit'), url_for('update', id_=entity.id))) if not entity.forms and not entity.system: buttons.append(display_delete_link(entity)) elif entity.class_.name == 'source_translation': buttons.append( button(_('edit'), url_for('translation_update', id_=entity.id))) buttons.append(display_delete_link(entity)) else: buttons.append(button(_('edit'), url_for('update', id_=entity.id))) if entity.class_.view != 'place' \ or not entity.get_linked_entities('P46'): buttons.append(display_delete_link(entity)) return buttons
def admin_index(action: Optional[str] = None, id_: Optional[int] = None) -> Union[str, Response]: if is_authorized('manager'): if id_ and action == 'delete_user': user = User.get_by_id(id_) if not user \ or user.id == current_user.id \ or (user.group == 'admin' and not is_authorized('admin')): abort(403) User.delete(id_) flash(_('user deleted'), 'info') elif action == 'remove_logo': Settings.set_logo() return redirect(f"{url_for('admin_index')}#tab-file") tables = { 'user': Table([ 'username', 'name', 'group', 'email', 'newsletter', 'created', 'last login', 'entities' ], defs=[{ 'className': 'dt-body-right', 'targets': 7 }]), 'content': Table(['name'] + list(app.config['LANGUAGES'])) } for user in User.get_all(): count = User.get_created_entities_count(user.id) email = user.email \ if is_authorized('manager') or user.settings['show_email'] else '' tables['user'].rows.append([ link(user), user.real_name, user.group, email, _('yes') if user.settings['newsletter'] else '', format_date(user.created), format_date(user.login_last_success), format_number(count) if count else '' ]) for item, languages in get_content().items(): content = [uc_first(_(item))] for language in app.config['LANGUAGES']: content.append(sanitize(languages[language], 'text')) content.append(link(_('edit'), url_for('admin_content', item=item))) tables['content'].rows.append(content) form = None if is_authorized('admin'): form = TestMailForm() if form.validate_on_submit( ) and g.settings['mail']: # pragma: no cover subject = _('Test mail from %(site_name)s', site_name=g.settings['site_name']) body = _('This test mail was sent by %(username)s', username=current_user.username) body += f" {_('at')} '{request.headers['Host']}" if send_mail(subject, body, form.receiver.data): flash( _('A test mail was sent to %(email)s.', email=form.receiver.data), 'info') else: form.receiver.data = current_user.email tabs = { 'files': Tab(_('files'), buttons=[ manual('entity/file'), button(_('edit'), url_for('admin_settings', category='files')) if is_authorized('manager') else '', button(_('list'), url_for('index', view='file')), button(_('file'), url_for('insert', class_='file')) ], content=render_template('admin/file.html', info=get_form_settings(FilesForm()), disk_space_info=get_disk_space_info())), 'user': Tab(_('user'), table=tables['user'], buttons=[ manual('admin/user'), button(_('activity'), url_for('user_activity')), button(_('newsletter'), url_for('admin_newsletter')) if is_authorized('manager') and g.settings['mail'] else '', button(_('user'), url_for('user_insert')) if is_authorized('manager') else '' ]) } if is_authorized('admin'): tabs['general'] = Tab( 'general', content=display_info(get_form_settings(GeneralForm())), buttons=[ manual('admin/general'), button(_('edit'), url_for('admin_settings', category='general')), button(_('system log'), url_for('admin_log')) ]) tabs['email'] = Tab( 'email', content=display_info(get_form_settings(MailForm())), buttons=[ manual('admin/mail'), button(_('edit'), url_for('admin_settings', category='mail')) ]) if g.settings['mail']: tabs['email'].content += display_form(form) if is_authorized('manager'): tabs['modules'] = Tab(_('modules'), content=f""" <h1>{_('Defaults for new user')}</h1> {display_info(get_form_settings(ModulesForm()))}""", buttons=[ manual('admin/modules'), button( _('edit'), url_for('admin_settings', category='modules')) ]) tabs['map'] = Tab('map', content=display_info(get_form_settings(MapForm())), buttons=[ manual('admin/map'), button(_('edit'), url_for('admin_settings', category='map')) ]) tabs['content'] = Tab('content', content=tables['content'].display(), buttons=[manual('admin/content')]) if is_authorized('contributor'): tabs['data'] = Tab('data', content=render_template( 'admin/data.html', imports=Import.get_all_projects(), info=get_form_settings(ApiForm()))) return render_template('tabs.html', tabs=tabs, title=_('admin'), crumbs=[_('admin')])
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)), 'types': Tab('type', table=Table( ['name', 'root'], [[link(type_), link(g.types[type_.root[0]])] for type_ in Type.get_type_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', types=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 os.path.isfile(file) \ 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')])
def entity_view(id_: int) -> Union[str, Response]: if id_ in g.nodes: # Nodes have their own view entity = g.nodes[id_] if not entity.root: if entity.class_.name == 'administrative_unit': tab_hash = '#menu-tab-places_collapse-' elif entity.standard: tab_hash = '#menu-tab-standard_collapse-' elif entity.value_type: tab_hash = '#menu-tab-value_collapse-' else: tab_hash = '#menu-tab-custom_collapse-' return redirect(f"{url_for('node_index')}{tab_hash}{id_}") elif id_ in g.reference_systems: entity = g.reference_systems[id_] else: entity = Entity.get_by_id(id_, nodes=True, aliases=True) if not entity.class_.view: flash(_("This entity can't be viewed directly."), 'error') abort(400) event_links = None # Needed for actor overlays = None # Needed for place tabs = {'info': Tab('info')} if isinstance(entity, Node): tabs['subs'] = Tab('subs', entity=entity) tabs['entities'] = Tab('entities', entity=entity) root = g.nodes[entity.root[-1]] if entity.root else None if root and root.value_type: # pragma: no cover tabs['entities'].table.header = [ _('name'), _('value'), _('class'), _('info') ] for item in entity.get_linked_entities(['P2', 'P89'], inverse=True, nodes=True): if item.class_.name in ['location', 'reference_system']: continue # pragma: no cover if item.class_.name == 'object_location': # pragma: no cover item = item.get_linked_entity_safe('P53', inverse=True) data = [link(item)] if root and root.value_type: # pragma: no cover data.append(format_number(item.nodes[entity])) data.append(item.class_.label) data.append(item.description) tabs['entities'].table.rows.append(data) for sub_id in entity.subs: sub = g.nodes[sub_id] tabs['subs'].table.rows.append( [link(sub), sub.count, sub.description]) if not tabs['entities'].table.rows: # If no entities available get links with this type_id tabs['entities'].table.header = [_('domain'), _('range')] for row in Link.get_entities_by_node(entity): tabs['entities'].table.rows.append([ link(Entity.get_by_id(row['domain_id'])), link(Entity.get_by_id(row['range_id'])) ]) elif isinstance(entity, ReferenceSystem): for form_id, form in entity.get_forms().items(): tabs[form['name']] = Tab(form['name'], entity=entity) tabs[form['name']].table = \ Table([_('entity'), 'id', _('precision')]) for link_ in entity.get_links('P67'): name = link_.description if entity.resolver_url: name = \ f'<a href="{entity.resolver_url + name}"' \ f' target="_blank" rel="noopener noreferrer">{name}</a>' tab_name = link_.range.class_.name tabs[tab_name].table.rows.append( [link(link_.range), name, link_.type.name]) for form_id, form in entity.get_forms().items(): tabs[form['name']].buttons = [] if not tabs[form['name']].table.rows and is_authorized('manager'): tabs[form['name']].buttons = [ button( _('remove'), url_for('reference_system_remove_form', system_id=entity.id, form_id=form_id)) ] elif entity.class_.view == 'actor': for name in [ 'source', 'event', 'relation', 'member_of', 'member', 'artifact' ]: tabs[name] = Tab(name, entity=entity) event_links = entity.get_links(['P11', 'P14', 'P22', 'P23', 'P25'], True) for link_ in event_links: event = link_.domain places = event.get_linked_entities(['P7', 'P26', 'P27']) link_.object_ = None # Needed for first/last appearance for place in places: object_ = place.get_linked_entity_safe('P53', True) entity.linked_places.append(object_) link_.object_ = object_ first = link_.first if not link_.first and event.first: first = f'<span class="inactive">{event.first}</span>' last = link_.last if not link_.last and event.last: last = f'<span class="inactive">{event.last}</span>' data = [ link(event), event.class_.label, _('moved') if link_.property.code == 'P25' else link( link_.type), first, last, link_.description ] if link_.property.code == 'P25': data += [''] else: add_edit_link( data, url_for('involvement_update', id_=link_.id, origin_id=entity.id)) add_remove_link(data, link_.domain.name, link_, entity, 'event') tabs['event'].table.rows.append(data) for link_ in entity.get_links('OA7') + entity.get_links('OA7', True): type_ = '' if entity.id == link_.domain.id: related = link_.range if link_.type: type_ = link(link_.type.get_name_directed(), url_for('entity_view', id_=link_.type.id)) else: related = link_.domain if link_.type: type_ = link(link_.type.get_name_directed(True), url_for('entity_view', id_=link_.type.id)) data = [ type_, link(related), link_.first, link_.last, link_.description ] add_edit_link( data, url_for('relation_update', id_=link_.id, origin_id=entity.id)) add_remove_link(data, related.name, link_, entity, 'relation') tabs['relation'].table.rows.append(data) for link_ in entity.get_links('P107', True): data = [ link(link_.domain), link(link_.type), link_.first, link_.last, link_.description ] add_edit_link( data, url_for('member_update', id_=link_.id, origin_id=entity.id)) add_remove_link(data, link_.domain.name, link_, entity, 'member-of') tabs['member_of'].table.rows.append(data) if entity.class_.name != 'group': del tabs['member'] else: for link_ in entity.get_links('P107'): data = [ link(link_.range), link(link_.type), link_.first, link_.last, link_.description ] add_edit_link( data, url_for('member_update', id_=link_.id, origin_id=entity.id)) add_remove_link(data, link_.range.name, link_, entity, 'member') tabs['member'].table.rows.append(data) for link_ in entity.get_links('P52', True): data = [ link(link_.domain), link_.domain.class_.label, link(link_.domain.standard_type), link_.domain.first, link_.domain.last, link_.domain.description ] tabs['artifact'].table.rows.append(data) elif entity.class_.view == 'artifact': tabs['source'] = Tab('source', entity=entity) elif entity.class_.view == 'event': for name in ['subs', 'source', 'actor']: tabs[name] = Tab(name, entity=entity) for sub_event in entity.get_linked_entities('P117', inverse=True, nodes=True): tabs['subs'].table.rows.append(get_base_table_data(sub_event)) tabs['actor'].table.header.insert(5, _('activity')) # Activity column for link_ in entity.get_links(['P11', 'P14', 'P22', 'P23']): first = link_.first if not link_.first and entity.first: first = f'<span class="inactive">{entity.first}</span>' last = link_.last if not link_.last and entity.last: last = f'<span class="inactive">{entity.last}</span>' data = [ link(link_.range), link_.range.class_.label, link_.type.name if link_.type else '', first, last, g.properties[link_.property.code].name_inverse, link_.description ] add_edit_link( data, url_for('involvement_update', id_=link_.id, origin_id=entity.id)) add_remove_link(data, link_.range.name, link_, entity, 'actor') tabs['actor'].table.rows.append(data) entity.linked_places = [ location.get_linked_entity_safe('P53', True) for location in entity.get_linked_entities(['P7', 'P26', 'P27']) ] elif entity.class_.view == 'file': for name in [ 'source', 'event', 'actor', 'place', 'feature', 'stratigraphic_unit', 'artifact', 'human_remains', 'reference', 'type' ]: tabs[name] = Tab(name, entity=entity) entity.image_id = entity.id if get_file_path(entity.id) else None for link_ in entity.get_links('P67'): range_ = link_.range data = get_base_table_data(range_) add_remove_link(data, range_.name, link_, entity, range_.class_.name) tabs[range_.class_.view].table.rows.append(data) for link_ in entity.get_links('P67', True): data = get_base_table_data(link_.domain) data.append(link_.description) add_edit_link( data, url_for('reference_link_update', link_id=link_.id, origin_id=entity.id)) add_remove_link(data, link_.domain.name, link_, entity, 'reference') tabs['reference'].table.rows.append(data) elif entity.class_.view == 'place': tabs['source'] = Tab('source', entity=entity) if entity.class_.name == 'place': tabs['event'] = Tab('event', entity=entity) tabs['reference'] = Tab('reference', entity=entity) if entity.class_.name == 'place': tabs['actor'] = Tab('actor', entity=entity) tabs['feature'] = Tab('feature', entity=entity) elif entity.class_.name == 'feature': tabs['stratigraphic_unit'] = Tab('stratigraphic_unit', entity=entity) elif entity.class_.name == 'stratigraphic_unit': tabs['find'] = Tab('find', entity=entity) tabs['human_remains'] = Tab('human_remains', entity=entity) entity.location = entity.get_linked_entity_safe('P53', nodes=True) event_ids = [] # Keep track of inserted events to prevent doubles for event in entity.location.get_linked_entities(['P7', 'P26', 'P27'], inverse=True): tabs['event'].table.rows.append(get_base_table_data(event)) event_ids.append(event.id) for event in entity.get_linked_entities('P24', inverse=True): if event.id not in event_ids: # Don't add again if already in table tabs['event'].table.rows.append(get_base_table_data(event)) if 'actor' in tabs: for link_ in entity.location.get_links(['P74', 'OA8', 'OA9'], inverse=True): actor = Entity.get_by_id(link_.domain.id) tabs['actor'].table.rows.append([ link(actor), g.properties[link_.property.code].name, actor.class_.name, actor.first, actor.last, actor.description ]) elif entity.class_.view == 'reference': for name in [ 'source', 'event', 'actor', 'place', 'feature', 'stratigraphic_unit', 'human_remains', 'artifact', 'file' ]: tabs[name] = Tab(name, entity=entity) for link_ in entity.get_links('P67'): range_ = link_.range data = get_base_table_data(range_) data.append(link_.description) add_edit_link( data, url_for('reference_link_update', link_id=link_.id, origin_id=entity.id)) add_remove_link(data, range_.name, link_, entity, range_.class_.name) tabs[range_.class_.view].table.rows.append(data) elif entity.class_.view == 'source': for name in [ 'actor', 'artifact', 'feature', 'event', 'human_remains', 'place', 'stratigraphic_unit', 'text' ]: tabs[name] = Tab(name, entity=entity) for text in entity.get_linked_entities('P73', nodes=True): tabs['text'].table.rows.append([ link(text), next(iter(text.nodes)).name if text.nodes else '', text.description ]) for link_ in entity.get_links('P67'): range_ = link_.range data = get_base_table_data(range_) add_remove_link(data, range_.name, link_, entity, range_.class_.name) tabs[range_.class_.view].table.rows.append(data) if entity.class_.view in [ 'actor', 'artifact', 'event', 'place', 'source', 'type' ]: if entity.class_.view != 'reference' and not isinstance(entity, Node): tabs['reference'] = Tab('reference', entity=entity) if entity.class_.view == 'artifact': tabs['event'] = Tab('event', entity=entity) for link_ in entity.get_links('P25', True): data = get_base_table_data(link_.domain) tabs['event'].table.rows.append(data) tabs['file'] = Tab('file', entity=entity) entity.image_id = entity.get_profile_image_id() if entity.class_.view == 'place' and is_authorized('editor') and \ current_user.settings['module_map_overlay']: tabs['file'].table.header.append(uc_first(_('overlay'))) for link_ in entity.get_links('P67', inverse=True): domain = link_.domain data = get_base_table_data(domain) if domain.class_.view == 'file': # pragma: no cover extension = data[3] data.append( get_profile_image_table_link(domain, entity, extension, entity.image_id)) if not entity.image_id \ and extension in app.config['DISPLAY_FILE_EXTENSIONS']: entity.image_id = domain.id if entity.class_.view == 'place' \ and is_authorized('editor') \ and current_user.settings['module_map_overlay']: overlays = Overlay.get_by_object(entity) if extension in app.config['DISPLAY_FILE_EXTENSIONS']: if domain.id in overlays: add_edit_link( data, url_for('overlay_update', id_=overlays[domain.id].id)) else: data.append( link( _('link'), url_for('overlay_insert', image_id=domain.id, place_id=entity.id, link_id=link_.id))) else: # pragma: no cover data.append('') if domain.class_.view not in ['source', 'file']: data.append(link_.description) add_edit_link( data, url_for('reference_link_update', link_id=link_.id, origin_id=entity.id)) if domain.class_.view == 'reference_system': entity.reference_systems.append(link_) continue add_remove_link(data, domain.name, link_, entity, domain.class_.view) tabs[domain.class_.view].table.rows.append(data) structure = None # Needed for place gis_data = None # Needed for place if entity.class_.view in ['artifact', 'place']: structure = get_structure(entity) if structure: for item in structure['subunits']: tabs[item.class_.name].table.rows.append( get_base_table_data(item)) gis_data = Gis.get_all([entity], structure) if gis_data['gisPointSelected'] == '[]' \ and gis_data['gisPolygonSelected'] == '[]' \ and gis_data['gisLineSelected'] == '[]' \ and (not structure or not structure['super_id']): gis_data = {} if not gis_data: gis_data = Gis.get_all(entity.linked_places) \ if entity.linked_places else None entity.info_data = get_entity_data(entity, event_links=event_links) tabs['note'] = Tab('note', entity=entity) for note in current_user.get_notes_by_entity_id(entity.id): data = [ format_date(note['created']), uc_first(_('public')) if note['public'] else uc_first(_('private')), link(User.get_by_id(note['user_id'])), note['text'], f'<a href="{url_for("note_view", id_=note["id"])}">' f'{uc_first(_("view"))}</a>' ] tabs['note'].table.rows.append(data) if 'file' in tabs and current_user.settings['table_show_icons'] and \ session['settings']['image_processing']: tabs['file'].table.header.insert(1, uc_first(_('icon'))) for row in tabs['file'].table.rows: row.insert( 1, file_preview( int(row[0].replace('<a href="/entity/', '').split('"')[0]))) tabs['info'].content = render_template( 'entity/view.html', buttons=add_buttons(entity), entity=entity, gis_data=gis_data, structure=structure, # Needed for place views overlays=overlays, # Needed for place views title=entity.name) return render_template('tabs.html', tabs=tabs, gis_data=gis_data, crumbs=add_crumbs(entity, structure), entity=entity)
def add_buttons(self, name: str, buttons: List[str], view: Union[None, str], id_: Union[None, int], class_: Union[None, SystemClass]) -> None: if name == 'actor': if view == 'place': self.table.header = [ 'actor', 'property', 'class', 'first', 'last', 'description' ] elif view == 'file': buttons += [ button('link', url_for('file_add', id_=id_, view=name)) ] elif view == 'reference': buttons += [ button('link', url_for('reference_add', id_=id_, view=name)) ] elif view == 'source': buttons += [ button('link', url_for('link_insert', id_=id_, view=name)) ] elif view == 'event': self.table.header = [ 'actor', 'class', 'involvement', 'first', 'last', 'description' ] buttons += [ button('link', url_for('involvement_insert', origin_id=id_)) ] for item in g.view_class_mapping['actor']: buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'artifact': buttons += [ button('link', url_for('link_insert', id_=id_, view='artifact')), button(g.classes['artifact'].label, url_for('insert', class_='artifact', origin_id=id_)) ] elif name == 'entities': if id_: buttons += [ button(_('move entities'), url_for('node_move_entities', id_=id_)) ] elif name == 'event': if view == 'file': buttons += [ button('link', url_for('file_add', id_=id_, view='event')) ] elif view == 'actor': self.table.header = [ 'event', 'class', 'involvement', 'first', 'last', 'description' ] buttons += [ button('link', url_for('involvement_insert', origin_id=id_)) ] elif view == 'source': buttons += [ button('link', url_for('link_insert', id_=id_, view='event')) ] elif view == 'reference': buttons += [ button('link', url_for('reference_add', id_=id_, view='event')) ] if view == 'artifact': buttons += [ button(g.classes['move'].label, url_for('insert', class_='move', origin_id=id_)) ] else: for item in g.view_class_mapping['event']: buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'feature': if current_user.settings['module_sub_units'] \ and class_.name == 'place': buttons += [ button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_)) ] elif name == 'find': if current_user.settings['module_sub_units'] \ and class_.name == 'stratigraphic_unit': buttons += [ button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_)) ] elif name == 'file': if view == 'reference': buttons += [ button('link', url_for('reference_add', id_=id_, view=name)) ] else: self.table.header += [_('main image')] buttons += [ button('link', url_for('entity_add_file', id_=id_)) ] buttons.append( button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'human_remains': if current_user.settings['module_sub_units'] \ and class_.name == 'stratigraphic_unit': buttons += [ button(g.classes[name].label, url_for('insert', origin_id=id_, class_=name)) ] elif name == 'member': buttons += [ button('link', url_for('member_insert', origin_id=id_)) ] elif name == 'member_of': buttons += [ button( 'link', url_for('member_insert', origin_id=id_, code='membership')) ] elif name == 'note': if is_authorized('contributor'): buttons += [ button(_('note'), url_for('note_insert', entity_id=id_)) ] elif name == 'place': if class_.name == 'file': buttons += [ button('link', url_for('file_add', id_=id_, view=name)) ] elif view == 'reference': buttons += [ button('link', url_for('reference_add', id_=id_, view=name)) ] elif view == 'source': buttons += [ button('link', url_for('link_insert', id_=id_, view=name)) ] buttons.append( button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'reference': buttons += [ button('link', url_for('entity_add_reference', id_=id_)) ] for item in g.view_class_mapping['reference']: buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'relation': buttons += [ button('link', url_for('relation_insert', origin_id=id_)) ] for item in g.view_class_mapping['actor']: buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'source': if class_.name == 'file': buttons += [ button(_('link'), url_for('file_add', id_=id_, view=name)) ] elif view == 'reference': buttons += [ button('link', url_for('reference_add', id_=id_, view=name)) ] else: buttons += [ button('link', url_for('entity_add_source', id_=id_)) ] buttons.append( button(g.classes['source'].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'subs': self.table.header = [_('name'), _('count'), _('info')] if view == 'event': self.table.header = g.table_headers['event'] elif name == 'stratigraphic_unit': if current_user.settings['module_sub_units'] \ and class_.name == 'feature': buttons += [ button(g.classes['stratigraphic_unit'].label, url_for('insert', class_=name, origin_id=id_)) ] elif name == 'text': buttons += [ button(_('text'), url_for('translation_insert', source_id=id_)) ]
def set_buttons(self, name: str, buttons: Optional[list[str]], entity: Optional[Entity] = None) -> None: view = entity.class_.view if entity else None id_ = entity.id if entity else None class_ = entity.class_ if entity else None self.buttons = buttons if buttons else [] if name == 'actor': if view == 'file': self.buttons.append( button('link', url_for('file_add', id_=id_, view=name))) elif view == 'reference': self.buttons.append( button('link', url_for('reference_add', id_=id_, view=name))) elif view == 'source': self.buttons.append( button('link', url_for('link_insert', id_=id_, view=name))) elif view == 'event': self.buttons.append( button('link', url_for('involvement_insert', origin_id=id_))) for item in g.view_class_mapping['actor']: self.buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'artifact': if class_ and class_.name != 'stratigraphic_unit': self.buttons.append( button('link', url_for('link_insert', id_=id_, view='artifact'))) self.buttons.append( button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'entities': if id_: self.buttons.append( button(_('move entities'), url_for('type_move_entities', id_=id_))) elif name == 'event': if view == 'file': self.buttons.append( button('link', url_for('file_add', id_=id_, view='event'))) elif view == 'actor': self.buttons.append( button('link', url_for('involvement_insert', origin_id=id_))) elif view == 'source': self.buttons.append( button('link', url_for('link_insert', id_=id_, view='event'))) elif view == 'reference': self.buttons.append( button('link', url_for('reference_add', id_=id_, view='event'))) if view == 'artifact': for item in ['move', 'production']: self.buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) else: for item in g.view_class_mapping['event']: self.buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'feature': if current_user.settings['module_sub_units'] \ and class_ \ and class_.name == 'place': self.buttons.append( button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'file': if view == 'reference': self.buttons.append( button('link', url_for('reference_add', id_=id_, view=name))) else: self.buttons.append( button('link', url_for('entity_add_file', id_=id_))) self.buttons.append( button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'human_remains': if current_user.settings['module_sub_units'] \ and class_ \ and class_.name == 'stratigraphic_unit': self.buttons.append( button(g.classes[name].label, url_for('insert', origin_id=id_, class_=name))) elif name == 'member': self.buttons.append( button('link', url_for('member_insert', origin_id=id_))) elif name == 'member_of': self.buttons.append( button( 'link', url_for('member_insert', origin_id=id_, code='membership'))) elif name == 'note' and is_authorized('contributor'): self.buttons.append( button(_('note'), url_for('note_insert', entity_id=id_))) elif name == 'place': if class_ and class_.name == 'file': self.buttons.append( button('link', url_for('file_add', id_=id_, view=name))) elif view == 'reference': self.buttons.append( button('link', url_for('reference_add', id_=id_, view=name))) elif view == 'source': self.buttons.append( button('link', url_for('link_insert', id_=id_, view=name))) self.buttons.append( button(g.classes[name].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'reference': self.buttons.append( button('link', url_for('entity_add_reference', id_=id_))) for item in g.view_class_mapping['reference']: self.buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'relation': self.buttons.append( button('link', url_for('relation_insert', origin_id=id_))) for item in g.view_class_mapping['actor']: self.buttons.append( button(g.classes[item].label, url_for('insert', class_=item, origin_id=id_))) elif name == 'source': if class_ and class_.name == 'file': self.buttons.append( button(_('link'), url_for('file_add', id_=id_, view=name))) elif view == 'reference': self.buttons.append( button('link', url_for('reference_add', id_=id_, view=name))) else: self.buttons.append( button('link', url_for('entity_add_source', id_=id_))) self.buttons.append( button(g.classes['source'].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'stratigraphic_unit': if current_user.settings['module_sub_units'] \ and class_ \ and class_.name == 'feature': self.buttons.append( button(g.classes['stratigraphic_unit'].label, url_for('insert', class_=name, origin_id=id_))) elif name == 'text': self.buttons.append( button( _('text'), url_for('insert', class_='source_translation', origin_id=id_)))