diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c3dc7a9e..dac852109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Current (in progress) -- Nothing yet +- Use beta admin as default [#621](https://github.com/datagouv/udata-front/pull/621) ## 6.1.1 (2025-01-31) diff --git a/udata_front/frontend/helpers.py b/udata_front/frontend/helpers.py index 6528d1fcd..996f53d85 100644 --- a/udata_front/frontend/helpers.py +++ b/udata_front/frontend/helpers.py @@ -109,6 +109,23 @@ def in_url(*args, **kwargs): ) +@front.app_template_global() +def beta_admin_url_for(path, fallback_path, **kwargs): + ''' + A helper to route to the new admin if available. + If NEW_ADMIN_URL is defined, we build the target url pointing to it using `path`. + Else we route to the old admin using `fallback_path`. + Kwargs are forwarded as as params in the first case + and as arguments of url_for in the seconde case. + ''' + if current_app.config['NEW_ADMIN_URL']: + scheme, netloc, path, query, fragments = urlsplit( + current_app.config['NEW_ADMIN_URL'] + path + ) + return urlunsplit((scheme, netloc, path, url_encode(kwargs), fragments)) + return url_for('admin.index', path=fallback_path, **kwargs) + + @front.app_template_filter() @pass_context def placeholder(ctx, url, name='default', external=False): diff --git a/udata_front/theme/gouvfr/templates/dataset/display.html b/udata_front/theme/gouvfr/templates/dataset/display.html index 3485ce1fb..c96f6682b 100644 --- a/udata_front/theme/gouvfr/templates/dataset/display.html +++ b/udata_front/theme/gouvfr/templates/dataset/display.html @@ -56,7 +56,7 @@
{{ _('Add a file') }} @@ -399,7 +399,7 @@
{{ _('Publish a reuse') }}
diff --git a/udata_front/theme/gouvfr/templates/header.html b/udata_front/theme/gouvfr/templates/header.html
index 40cf26968..bff21bcb5 100644
--- a/udata_front/theme/gouvfr/templates/header.html
+++ b/udata_front/theme/gouvfr/templates/header.html
@@ -3,14 +3,15 @@
{% set banner_activated = config['BANNER_ACTIVATED'] %}
{% set read_only_mode = config['READ_ONLY_MODE'] %}
{% set next_url = url_for(request.endpoint, **request.view_args) if not request.routing_exception else url_for('site.home') %}
-{% set publish_items = [
- {'icon': 'fr-icon-database-line', 'label': _('A dataset'), 'url': url_for('beta.datasets-new')},
- {'icon': 'fr-icon-code-s-slash-line', 'label': _('An API'), 'url': url_for('beta.dataservices-new')},
- {'icon': 'fr-icon-line-chart-line', 'label': _('A reuse'), 'url': url_for('beta.reuses-new')},
- {'icon': 'fr-icon-server-line', 'label': _('A harvester'), 'url': url_for('admin.index', path='harvester/new/')},
- {'icon': 'fr-icon-government-line', 'label': _('An organization'), 'url': url_for('beta.organizations-new')},
-] + ([{'icon': 'fr-icon-article-line', 'label': _('A post'), 'url': url_for('admin.index', path='post/new/')}] if current_user.sysadmin else [])
-%}
+
+{% set dataset_item = [{'icon': 'fr-icon-database-line', 'label': _('A dataset'), 'url': beta_admin_url_for(path='datasets/new', fallback_path='dataset/new/')}] %}
+{% set dataservice_item = [{'icon': 'fr-icon-database-line', 'label': _('An API'), 'url': beta_admin_url_for(path='dataservices/new', fallback_path='')}] if config.NEW_ADMIN_URL else [] %}
+{% set reuse_item = [{'icon': 'fr-icon-database-line', 'label': _('A reuse'), 'url': beta_admin_url_for(path='reuses/new', fallback_path='reuse/new/')}] %}
+{% set harvester_item = [{'icon': 'fr-icon-database-line', 'label': _('A harvester'), 'url': beta_admin_url_for(path='harvesters/new', fallback_path='harvester/new/')}] %}
+{% set organization_item = [{'icon': 'fr-icon-database-line', 'label': _('A organization'), 'url': beta_admin_url_for(path='organizations/new', fallback_path='organization/new/')}] %}
+{% set post_item = [{'icon': 'fr-icon-database-line', 'label': _('A post'), 'url': beta_admin_url_for(path='posts/new', fallback_path='post/new/')}] if current_user.sysadmin else [] %}
+
+{% set publish_items = dataset_item + dataservice_item + reuse_item + harvester_item + organization_item + post_item %}