Skip to content

Commit

Permalink
organisation: rename unisi to usi
Browse files Browse the repository at this point in the history
* Forces the code to `usi` if organisation is `unisi` in RERODOC imports.
* Renames logo, styles file with the right acronym `usi`.
* Renames global styles from `sonar` to `global` for consistency.
* Removes useless style `img.logo`
* Fallbacks to global theme if a specific theme does not exist for an organisation.
* Displays the logo associated to the organisation in dedicated views, instead of a static one.
* Displays the name of the organisation if no logo is available.
* Removes static logo for `unisi`.
* Closes #307.
* Closes #308.

Co-Authored-by: Sébastien Délèze <[email protected]>
  • Loading branch information
Sébastien Délèze committed Oct 19, 2020
1 parent c960a49 commit 053f922
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 50 deletions.
5 changes: 5 additions & 0 deletions sonar/modules/documents/dojson/rerodoc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def marc21_to_type_and_organisation(self, key, value):
if value.get('b'):
organisation = value.get('b').lower()

# Specific transformation for `unisi`, because the real acronym is
# `usi`.
if organisation == 'unisi':
organisation = 'usi'

if organisation not in marc21tojson.registererd_organisations:
marc21tojson.create_organisation(organisation)
marc21tojson.registererd_organisations.append(organisation)
Expand Down
6 changes: 4 additions & 2 deletions sonar/modules/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
file_uploaded_listener
from sonar.modules.users.api import current_user_record
from sonar.modules.users.signals import user_registered_handler
from sonar.modules.utils import get_switch_aai_providers, get_view_code
from sonar.modules.utils import get_specific_theme, get_switch_aai_providers, \
get_view_code

from . import config

Expand All @@ -45,7 +46,8 @@ def utility_processor():
ui_version=config.SONAR_APP_UI_VERSION,
aai_providers=get_switch_aai_providers,
view_code=get_view_code(),
current_user_record=current_user_record)
current_user_record=current_user_record,
get_specific_theme=get_specific_theme)


class Sonar(object):
Expand Down
17 changes: 17 additions & 0 deletions sonar/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from wand.color import Color
from wand.image import Image

from sonar.theme.webpack import theme


def create_thumbnail_from_file(file_path, mimetype):
"""Create a thumbnail from given file path and return image blob.
Expand Down Expand Up @@ -147,3 +149,18 @@ def format_date(date):
'%Y-%m-%d').strftime('%d.%m.%Y')

return date


def get_specific_theme():
"""Return the webpack entry for the current organisation.
:returns: String representing the webpack entry. Default to `global`.
"""
if g.get('organisation', {}).get('isDedicated'):
theme_name = '{organisation}-theme'.format(
organisation=g.organisation['pid'])

if theme.entry.get(theme_name):
return '{theme}.css'.format(theme=theme_name)

return 'global-theme.css'
5 changes: 0 additions & 5 deletions sonar/theme/assets/scss/common/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
background-color: $bg-organisation;
}

img.logo {
width: 100%;
max-height: 90px;
}

.standalone-editor {
legend, button.btn-outline-danger {
display: none;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 0 additions & 15 deletions sonar/theme/static/images/unisi-logo.svg

This file was deleted.

18 changes: 11 additions & 7 deletions sonar/theme/templates/sonar/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
<div class="bg-organisation p-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-8 col-xs-6 col-lg-4 py-3 py-sm-5">
<div class="col-8 col-xs-6 col-lg-3 py-3 py-sm-5 text-center">
<a href="{{ url_for('documents.index', view=view_code if g.get('organisation', {}).get('isDedicated') else config.SONAR_APP_DEFAULT_ORGANISATION) }}">
{%- if config.THEME_LOGO %}
{% set logo_code = view_code if g.get('organisation', {}).get('isDedicated') else config.SONAR_APP_DEFAULT_ORGANISATION %}
<img src="{{ url_for('static', filename='images/' ~ logo_code ~ '-logo.svg')}}" alt="{{_(config.THEME_SITENAME)}}" class="logo"/>
{%- else %}
{{_(config.THEME_SITENAME)}}
{%- endif %}
{% if g.get('organisation', {}).get('isDedicated') %}
{% set thumbnail = g.organisation | record_image_url %}
{% if thumbnail %}
<img src="{{ thumbnail }}" class="img-fluid">
{% else %}
<h1>{{g.organisation.name}}</h1>
{% endif %}
{% else %}
<img src="{{ url_for('static', filename='images/global-logo.svg') }}" class="img-fluid">
{% endif %}
</a>
</div>
</div>
Expand Down
12 changes: 1 addition & 11 deletions sonar/theme/templates/sonar/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,7 @@
{%- endblock head_links %}

{%- block css %}
{% if g.get('organisation', {}).get('isDedicated') %}
{{ webpack[view_code ~ '-theme.css'] }}
{% else %}
{{ webpack['sonar-theme.css'] }}
{% endif %}
{# assets "invenio_theme_css" %}<link href="{{ ASSET_URL }}" rel="stylesheet">{% endassets #}
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
{{ webpack[get_specific_theme()] }}
{%- endblock css %}

{%- endblock head %}
Expand Down
14 changes: 11 additions & 3 deletions sonar/theme/templates/sonar/partial/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
{% if page != 'home' %}
<a class="navbar-brand" href="{{ url_for('documents.index', view=view_code) }}">
{% set logo_code = view_code if g.get('organisation', {}).get('isDedicated') else config.SONAR_APP_DEFAULT_ORGANISATION %}
<img src="{{ url_for('static', filename='images/' ~ logo_code ~ '-logo.svg')}}" height="50"
class="d-inline-block align-top mr-3 my-4" alt="">
{% if g.get('organisation', {}).get('isDedicated') %}
{% set thumbnail = g.organisation | record_image_url %}
{% if thumbnail %}
<img src="{{ thumbnail }}" height="50" class="d-inline-block align-top mr-3 my-2" alt="">
{% else %}
{{g.organisation.name}}
{% endif %}
{% else %}
<img src="{{ url_for('static', filename='images/global-logo.svg') }}" height="50"
class="d-inline-block align-top mr-3 my-2" alt="">
{% endif %}
</a>
{% if not admin %}
<form action="{{ url_for('documents.search', view=view_code if g.get('organisation', {}).get('isDedicated') else config.SONAR_APP_DEFAULT_ORGANISATION) }}"
Expand Down
4 changes: 2 additions & 2 deletions sonar/theme/webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
'assets',
entry={
'app': './js/app.js',
'sonar-theme': './scss/sonar/theme.scss',
'unisi-theme': './scss/unisi/theme.scss'
'global-theme': './scss/global/theme.scss',
'usi-theme': './scss/usi/theme.scss'
},
dependencies={
'popper.js': '^1.15',
Expand Down
2 changes: 1 addition & 1 deletion sonar/translations/manual_translations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ _('eduid')

# Organisations
_('csal')
_('unisi')
_('usi')
_('unifr')
15 changes: 15 additions & 0 deletions tests/ui/documents/dojson/rerodoc/test_rerodoc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ def test_marc21_to_type_and_organisation(app, bucket_location):
'$ref': 'https://sonar.ch/api/organisations/baage'
}

# Specific conversion for unisi
marc21xml = """
<record>
<datafield tag="980" ind1=" " ind2=" ">
<subfield code="b">UNISI</subfield>
</datafield>
</record>
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert not data.get('documentType')
assert data.get('organisation') == {
'$ref': 'https://sonar.ch/api/organisations/usi'
}


def test_marc21_to_title_245():
"""Test dojson marc21_to_title."""
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/documents/test_documents_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def test_has_external_urls_for_files(app):
assert not views.has_external_urls_for_files({
'pid': 1,
'organisation': {
'pid': 'unisi'
'pid': 'usi'
}
})

Expand Down Expand Up @@ -420,8 +420,8 @@ def test_get_current_organisation_code(app, organisation):

# Args has organisation view
with app.test_request_context() as req:
req.request.args = {'view': 'unisi'}
assert views.get_current_organisation_code() == 'unisi'
req.request.args = {'view': 'usi'}
assert views.get_current_organisation_code() == 'usi'


def test_abstracts(app):
Expand Down
25 changes: 24 additions & 1 deletion tests/ui/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sonar.modules.documents.views import store_organisation
from sonar.modules.utils import change_filename_extension, \
create_thumbnail_from_file, format_date, get_current_language, \
get_switch_aai_providers, get_view_code
get_specific_theme, get_switch_aai_providers, get_view_code


def test_change_filename_extension(app):
Expand Down Expand Up @@ -109,3 +109,26 @@ def test_format_date():

# No processing
assert format_date('July 31, 2020') == 'July 31, 2020'


def test_get_specific_theme(app, organisation, make_organisation):
"""Test getting a theme by organisation."""
with app.test_request_context() as req:
req.request.view_args['view'] = 'org'
store_organisation()

# Not dedicated --> global theme
assert get_specific_theme() == 'global-theme.css'

# Dedicated, but no specific style --> global theme
g.organisation['isDedicated'] = True
assert get_specific_theme() == 'global-theme.css'

# Dedicated and specific style --> specific theme
make_organisation('usi')
with app.test_request_context() as req:
req.request.view_args['view'] = 'usi'
store_organisation()

g.organisation['isDedicated'] = True
assert get_specific_theme() == 'usi-theme.css'

0 comments on commit 053f922

Please sign in to comment.