예제 #1
0
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')])
예제 #2
0
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')
                           ])
예제 #3
0
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')])
예제 #4
0
def admin_check_dates() -> str:
    tabs = {
        'dates':
        Tab('invalid_dates',
            table=Table(
                ['name', 'class', 'type', 'created', 'updated',
                 'description'])),
        'link_dates':
        Tab('invalid_link_dates', table=Table(['link', 'domain', 'range'])),
        'involvement_dates':
        Tab('invalid_involvement_dates',
            table=Table(
                ['actor', 'event', 'class', 'involvement', 'description']))
    }
    for entity in Entity.get_invalid_dates():
        tabs['dates'].table.rows.append([
            link(entity), entity.class_.label,
            link(entity.standard_type),
            format_date(entity.created),
            format_date(entity.modified), entity.description
        ])
    for link_ in Link.get_invalid_link_dates():
        name = ''
        if link_.property.code == 'OA7':  # pragma: no cover
            name = 'relation'
        elif link_.property.code == 'P107':  # pragma: no cover
            name = 'member'
        elif link_.property.code in ['P11', 'P14', 'P22', 'P23']:
            name = 'involvement'
        tabs['link_dates'].table.rows.append([
            link(
                _(name),
                url_for('link_update', id_=link_.id,
                        origin_id=link_.domain.id)),
            link(link_.domain),
            link(link_.range)
        ])
    for link_ in Link.invalid_involvement_dates():
        event = link_.domain
        actor = link_.range
        data = [
            link(actor),
            link(event), event.class_.label,
            link_.type.name if link_.type else '', link_.description,
            link(_('edit'),
                 url_for('link_update', id_=link_.id, origin_id=actor.id))
        ]
        tabs['involvement_dates'].table.rows.append(data)
    for tab in tabs.values():
        tab.buttons = [manual('admin/data_integrity_checks')]
        if not tab.table.rows:  # pragma: no cover
            tab.content = _('Congratulations, everything looks fine!')
    return render_template(
        'tabs.html',
        tabs=tabs,
        title=_('admin'),
        crumbs=[[_('admin'), f"{url_for('admin_index')}#tab-data"],
                _('check dates')])
예제 #5
0
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')])
예제 #6
0
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')])
예제 #7
0
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')])