コード例 #1
0
 def get() -> Union[Tuple[Resource, int], Response]:
     parser = language.parse_args()
     lang = parser['lang']
     content = {
         'intro': Ct.get_translation('intro_for_frontend', lang),
         'contact': Ct.get_translation('contact_for_frontend', lang),
         'siteName': Ct.get_translation('site_name_for_frontend', lang),
         'imageSizes': app.config['IMAGE_SIZE'],
         'legalNotice': Ct.get_translation('legal_notice_for_frontend', lang)
     }
     template = ContentTemplate.content_template()
     if parser['download']:
         return download(content, template, 'content')
     return marshal(content, template), 200
コード例 #2
0
ファイル: filters.py プロジェクト: NinaBrundke/OpenAtlas
def display_citation_example(self: Any, code: str) -> str:
    text = Content.get_translation('citation_example')
    if not text or code != 'reference':
        return ''
    return Markup('<h1>{title}</h1>{text}'.format(
        title=display.uc_first(_('citation_example')),
        text=text))
コード例 #3
0
ファイル: content.py プロジェクト: NinaBrundke/OpenAtlas
 def get(self) -> Union[Tuple[Resource, int], Response]:
     parser = language_parser.parse_args()
     content = {
         'intro':
         Content.get_translation('intro_for_frontend', parser['lang']),
         'contact':
         Content.get_translation('contact_for_frontend', parser['lang']),
         'legal-notice':
         Content.get_translation('legal_notice_for_frontend',
                                 parser['lang'])
     }
     template = ContentTemplate.content_template()
     if parser['download']:
         return Download.download(data=content,
                                  template=template,
                                  name='content')
     return marshal(content, ContentTemplate.content_template()), 200
コード例 #4
0
ファイル: admin.py プロジェクト: NinaBrundke/OpenAtlas
def admin_content(item: str) -> Union[str, Response]:
    languages = app.config['LANGUAGES'].keys()
    for language in languages:
        setattr(ContentForm, language, TextAreaField())
    form = ContentForm()
    if form.validate_on_submit():
        Content.update_content(item, form)
        flash(_('info update'), 'info')
        return redirect(url_for('admin_index') + '#tab-content')
    content = Content.get_content()
    for language in languages:
        form.__getattribute__(language).data = content[item][language]
    return render_template(
        'admin/content.html',
        item=item,
        form=form,
        languages=languages,
        title=_('content'),
        crumbs=[[_('admin'),
                 url_for('admin_index') + '#tab-content'],
                _(item)])
コード例 #5
0
ファイル: util.py プロジェクト: stefaneichert/OpenAtlas
def display_content_translation(text: str) -> str:
    return Content.get_translation(text)
コード例 #6
0
ファイル: util.py プロジェクト: stefaneichert/OpenAtlas
def display_citation_example(code: str) -> str:
    text = Content.get_translation('citation_example')
    if not text or code != 'reference':
        return ''
    return Markup(f'<h1>{uc_first(_("citation_example"))}</h1>{text}')
コード例 #7
0
ファイル: admin.py プロジェクト: NinaBrundke/OpenAtlas
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)  # pragma: no cover
            User.delete(id_)
            flash(_('user deleted'), 'info')
        elif action == 'remove_logo':
            Settings.set_logo()
            return redirect(url_for('admin_index') + '#tab-file')
    dirs = {
        'uploads':
        True if os.access(app.config['UPLOAD_DIR'], os.W_OK) else False,
        'export/sql':
        True if os.access(app.config['EXPORT_DIR'] /
                          'sql', os.W_OK) else False,
        'export/csv':
        True if os.access(app.config['EXPORT_DIR'] / 'csv', os.W_OK) else False
    }
    tables = {
        'user':
        Table([
            'username', 'name', 'group', 'email', 'newsletter', 'created',
            'last login', 'entities'
        ]),
        'content':
        Table(['name'] +
              [language for language in app.config['LANGUAGES'].keys()])
    }
    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 Content.get_content().items():
        content = [uc_first(_(item))]
        for language in app.config['LANGUAGES'].keys():
            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 session['settings']['mail']:  # pragma: no cover
            subject = _('Test mail from %(site_name)s',
                        site_name=session['settings']['site_name'])
            body = _('This test mail was sent by %(username)s',
                     username=current_user.username)
            body += ' ' + _('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
    return render_template('admin/index.html',
                           form=form,
                           tables=tables,
                           settings=session['settings'],
                           writeable_dirs=dirs,
                           disk_space_info=get_disk_space_info(),
                           imports=Import.get_all_projects(),
                           title=_('admin'),
                           crumbs=[_('admin')],
                           info={
                               'file': get_form_settings(FilesForm()),
                               'general': get_form_settings(GeneralForm()),
                               'mail': get_form_settings(MailForm()),
                               'map': get_form_settings(MapForm()),
                               'api': get_form_settings(ApiForm()),
                               'modules': get_form_settings(ModulesForm())
                           })
コード例 #8
0
ファイル: admin.py プロジェクト: stefaneichert/OpenAtlas
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)  # pragma: no cover
            User.delete(id_)
            flash(_('user deleted'), 'info')
        elif action == 'remove_logo':
            Settings.set_logo()
            return redirect(f"{url_for('admin_index')}#tab-file")
    dirs = {
        'uploads': os.access(app.config['UPLOAD_DIR'], os.W_OK),
        'export/sql': os.access(app.config['EXPORT_DIR'] / 'sql', os.W_OK),
        'export/csv': os.access(app.config['EXPORT_DIR'] / 'csv', os.W_OK)}
    tables = {
        'user': Table(
            [
                'username',
                'name',
                'group',
                'email',
                'newsletter',
                'created',
                'last login',
                'entities'],
            defs=[{'className': 'dt-body-right', 'targets': 7}]),
        'content': Table(['name'] + [
            language for language in app.config['LANGUAGES'].keys()])}
    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 Content.get_content().items():
        content = [uc_first(_(item))]
        for language in app.config['LANGUAGES'].keys():
            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 session['settings']['mail']:  # pragma: no cover
            subject = _(
                'Test mail from %(site_name)s',
                site_name=session['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',
                writeable_dirs=dirs,
                info=get_form_settings(FilesForm()),
                settings=session['settings'],
                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 session['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 session['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')])
コード例 #9
0
ファイル: index.py プロジェクト: stefaneichert/OpenAtlas
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 count:
                url = url_for('index', view=g.class_view_mapping[name])
                if name == 'administrative_unit':
                    url = f"{url_for('node_index')}#menu-tab-places"
                elif name == 'type':
                    url = url_for('node_index')
                elif name == 'find':
                    url = url_for('index', view='artifact')
                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(8):
            tables['latest'].rows.append([
                format_date(entity.created),
                link(entity), entity.class_.label, entity.first, entity.last,
                link(logger.get_log_for_advanced_view(entity.id)['creator'])
            ])
    tabs['info'].content = render_template(
        'index/index.html',
        intro=Content.get_translation('intro'),
        tables=tables)
    return render_template('tabs.html', tabs=tabs, crumbs=['overview'])
コード例 #10
0
ファイル: index.py プロジェクト: stefaneichert/OpenAtlas
def index_content(item: str) -> str:
    return render_template('index/content.html',
                           text=Content.get_translation(item),
                           title=_(_(item)),
                           crumbs=[_(item)])
コード例 #11
0
ファイル: filters.py プロジェクト: NinaBrundke/OpenAtlas
def display_content_translation(self: Any, text: str) -> str:
    from openatlas.models.content import Content
    return Content.get_translation(text)