Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view: change the view routes #533

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import os

import sphinx.environment

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down
65 changes: 62 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mock = ">=2.0.0"
pytest-invenio = ">=1.4.1,<1.5.0"
safety = ">=1.8"
appnope = { version = "*", optional = true }
autoflake = "^1.4"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
1 change: 1 addition & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ fi
safety check -i 39462 && \
pydocstyle sonar tests docs && \
isort --check-only --diff "${SCRIPT_PATH}/.." && \
autoflake -rc --remove-all-unused-imports --ignore-init-module-imports . && \
sphinx-build -qnNW docs docs/_build/html && \
pytest
21 changes: 19 additions & 2 deletions sonar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,27 @@ def _(x):
SECURITY_REGISTER_USER_TEMPLATE = 'sonar/accounts/signup.html'

RECORDS_UI_ENDPOINTS = {
'doc': {
'pid_type': 'doc',
'route': '/<org_code:view>/documents/<pid_value>',
'view_imp': 'sonar.modules.documents.views:detail',
'record_class': 'sonar.modules.documents.api:DocumentRecord',
'template': 'documents/record.html',
'permission_factory_imp': 'sonar.modules.documents.permissions:only_public'
},
'doc_previewer': {
'pid_type': 'doc',
'route': '/documents/<pid_value>/preview/<filename>',
'view_imp': 'invenio_previewer.views:preview',
'record_class': 'sonar.modules.documents.api:DocumentRecord'
'record_class': 'sonar.modules.documents.api:DocumentRecord',
'permission_factory_imp': 'sonar.modules.documents.permissions:only_public'
},
'doc_files': {
'pid_type': 'doc',
'route': '/documents/<pid_value>/files/<filename>',
'view_imp': 'invenio_records_files.utils:file_download_ui',
'record_class': 'invenio_records_files.api:Record'
'record_class': 'invenio_records_files.api:Record',
'permission_factory_imp': 'sonar.modules.documents.permissions:only_public'
},
'depo_previewer': {
'pid_type': 'depo',
Expand All @@ -295,6 +305,13 @@ def _(x):
'view_imp': 'invenio_records_files.utils:file_download_ui',
'record_class': 'invenio_records_files.api:Record'
},
'proj': {
'pid_type': 'proj',
'route': '/<org_code:view>/projects/<pid_value>',
'view_imp': 'sonar.resources.projects.views:detail',
'record_class': 'sonar.resources.projects.api:Record',
'template': 'sonar/projects/detail.html'
}
}
"""Records UI for sonar."""

Expand Down
18 changes: 17 additions & 1 deletion sonar/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from __future__ import absolute_import, print_function

import jinja2
from flask import current_app
from flask import current_app, render_template
from flask_bootstrap import Bootstrap
from flask_security import user_registered
from flask_wiki import Wiki
Expand All @@ -41,6 +41,7 @@
RecordService as ProjectRecordService

from . import config_sonar
from .route_converters import OrganisationCodeConverter


def utility_processor():
Expand Down Expand Up @@ -77,6 +78,7 @@ def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
self.create_resources()
self.init_views(app)

app.extensions['sonar'] = self

Expand Down Expand Up @@ -105,6 +107,20 @@ def init_config(self, app):
if k.startswith('SONAR_APP_'):
app.config.setdefault(k, getattr(config_sonar, k))

def init_views(self, app):
"""Initialize the main flask views."""
app.url_map.converters['org_code'] = OrganisationCodeConverter

@app.route('/<org_code:view>')
def index(view):
"""Homepage."""
return render_template('sonar/frontpage.html')

@app.template_filter()
def nl2br(string):
r"""Replace \n to <br>."""
return string.replace('\n', '<br>')
sebdeleze marked this conversation as resolved.
Show resolved Hide resolved

def create_resources(self):
"""Create resources."""
# Initialize the project resource with the corresponding service.
Expand Down
3 changes: 1 addition & 2 deletions sonar/modules/documents/cli/oaiharvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

import click
from click.exceptions import ClickException
from flask import current_app
from flask.cli import with_appcontext
from invenio_db import db
from invenio_oaiharvester.cli import harvest, oaiharvester
from invenio_oaiharvester.cli import oaiharvester
from invenio_oaiharvester.models import OAIHarvestConfig


Expand Down
1 change: 0 additions & 1 deletion sonar/modules/documents/dojson/rerodoc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from dojson import utils
from flask import current_app

from sonar.modules.documents.api import DocumentRecord
from sonar.modules.documents.dojson.rerodoc.overdo import Overdo
from sonar.modules.organisations.api import OrganisationRecord
from sonar.modules.utils import remove_trailing_punctuation
Expand Down
Loading