From 053f922da99d8dda1b3cc5b5daa54c71b8dbde34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20De=CC=81le=CC=80ze?= Date: Wed, 16 Sep 2020 09:19:50 +0200 Subject: [PATCH] organisation: rename `unisi` to `usi` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../modules/documents/dojson/rerodoc/model.py | 5 ++++ sonar/modules/ext.py | 6 +++-- sonar/modules/utils.py | 17 +++++++++++++ sonar/theme/assets/scss/common/_theme.scss | 5 ---- .../scss/{sonar => global}/_variables.scss | 0 .../assets/scss/{sonar => global}/theme.scss | 0 .../scss/{unisi => usi}/_variables.scss | 0 .../assets/scss/{unisi => usi}/theme.scss | 0 sonar/theme/static/images/unisi-logo.svg | 15 ----------- sonar/theme/templates/sonar/frontpage.html | 18 +++++++------ sonar/theme/templates/sonar/page.html | 12 +-------- .../theme/templates/sonar/partial/navbar.html | 14 ++++++++--- sonar/theme/webpack.py | 4 +-- sonar/translations/manual_translations.txt | 2 +- .../dojson/rerodoc/test_rerodoc_model.py | 15 +++++++++++ tests/ui/documents/test_documents_views.py | 6 ++--- tests/ui/test_utils.py | 25 ++++++++++++++++++- 17 files changed, 94 insertions(+), 50 deletions(-) rename sonar/theme/assets/scss/{sonar => global}/_variables.scss (100%) rename sonar/theme/assets/scss/{sonar => global}/theme.scss (100%) rename sonar/theme/assets/scss/{unisi => usi}/_variables.scss (100%) rename sonar/theme/assets/scss/{unisi => usi}/theme.scss (100%) delete mode 100644 sonar/theme/static/images/unisi-logo.svg diff --git a/sonar/modules/documents/dojson/rerodoc/model.py b/sonar/modules/documents/dojson/rerodoc/model.py index b53f6039..f0bd4fb2 100644 --- a/sonar/modules/documents/dojson/rerodoc/model.py +++ b/sonar/modules/documents/dojson/rerodoc/model.py @@ -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) diff --git a/sonar/modules/ext.py b/sonar/modules/ext.py index b23499b9..6b100910 100644 --- a/sonar/modules/ext.py +++ b/sonar/modules/ext.py @@ -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 @@ -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): diff --git a/sonar/modules/utils.py b/sonar/modules/utils.py index c0c035ff..7d8ac8f0 100644 --- a/sonar/modules/utils.py +++ b/sonar/modules/utils.py @@ -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. @@ -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' diff --git a/sonar/theme/assets/scss/common/_theme.scss b/sonar/theme/assets/scss/common/_theme.scss index 1ba8376b..3ac5951e 100644 --- a/sonar/theme/assets/scss/common/_theme.scss +++ b/sonar/theme/assets/scss/common/_theme.scss @@ -28,11 +28,6 @@ background-color: $bg-organisation; } -img.logo { - width: 100%; - max-height: 90px; -} - .standalone-editor { legend, button.btn-outline-danger { display: none; diff --git a/sonar/theme/assets/scss/sonar/_variables.scss b/sonar/theme/assets/scss/global/_variables.scss similarity index 100% rename from sonar/theme/assets/scss/sonar/_variables.scss rename to sonar/theme/assets/scss/global/_variables.scss diff --git a/sonar/theme/assets/scss/sonar/theme.scss b/sonar/theme/assets/scss/global/theme.scss similarity index 100% rename from sonar/theme/assets/scss/sonar/theme.scss rename to sonar/theme/assets/scss/global/theme.scss diff --git a/sonar/theme/assets/scss/unisi/_variables.scss b/sonar/theme/assets/scss/usi/_variables.scss similarity index 100% rename from sonar/theme/assets/scss/unisi/_variables.scss rename to sonar/theme/assets/scss/usi/_variables.scss diff --git a/sonar/theme/assets/scss/unisi/theme.scss b/sonar/theme/assets/scss/usi/theme.scss similarity index 100% rename from sonar/theme/assets/scss/unisi/theme.scss rename to sonar/theme/assets/scss/usi/theme.scss diff --git a/sonar/theme/static/images/unisi-logo.svg b/sonar/theme/static/images/unisi-logo.svg deleted file mode 100644 index dfc641e4..00000000 --- a/sonar/theme/static/images/unisi-logo.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - diff --git a/sonar/theme/templates/sonar/frontpage.html b/sonar/theme/templates/sonar/frontpage.html index d8138b4b..6a00b7ca 100755 --- a/sonar/theme/templates/sonar/frontpage.html +++ b/sonar/theme/templates/sonar/frontpage.html @@ -23,14 +23,18 @@
- diff --git a/sonar/theme/templates/sonar/page.html b/sonar/theme/templates/sonar/page.html index c140981d..756fbcdd 100755 --- a/sonar/theme/templates/sonar/page.html +++ b/sonar/theme/templates/sonar/page.html @@ -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" %}{% endassets #} - - + {{ webpack[get_specific_theme()] }} {%- endblock css %} {%- endblock head %} diff --git a/sonar/theme/templates/sonar/partial/navbar.html b/sonar/theme/templates/sonar/partial/navbar.html index e3e8ee3b..f3a81c82 100644 --- a/sonar/theme/templates/sonar/partial/navbar.html +++ b/sonar/theme/templates/sonar/partial/navbar.html @@ -38,9 +38,17 @@