From f29620876805cd083545e18664838f4cca56f83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= <michal@cihar.com> Date: Tue, 15 Aug 2023 08:52:52 +0200 Subject: [PATCH] templates: use shared breadcrumb renderer This will make projectlanguge and category work consistently at all levels. Issue #263 --- weblate/templates/addons/addon_detail.html | 3 +-- weblate/templates/addons/addon_list.html | 3 +-- weblate/templates/browse.html | 7 ++----- weblate/templates/component-progress.html | 4 ++-- weblate/templates/component-settings.html | 3 +-- weblate/templates/component.html | 3 +-- weblate/templates/contributor-agreement.html | 3 +-- weblate/templates/guide.html | 3 +-- weblate/templates/matrix.html | 3 +-- weblate/templates/new-language.html | 3 +-- weblate/templates/project.html | 2 +- weblate/templates/replace.html | 13 +------------ .../templates/screenshots/screenshot_detail.html | 3 +-- weblate/templates/screenshots/screenshot_list.html | 3 +-- .../templates/snippets/component-breadcrumb.html | 6 ------ .../templates/snippets/translation-breadcrumb.html | 9 --------- weblate/templates/translate.html | 9 +-------- weblate/templates/translation.html | 5 ++--- weblate/templates/zen.html | 6 +----- weblate/trans/views/basic.py | 6 ++++++ weblate/trans/views/edit.py | 3 +++ weblate/utils/views.py | 2 +- 22 files changed, 30 insertions(+), 72 deletions(-) delete mode 100644 weblate/templates/snippets/component-breadcrumb.html delete mode 100644 weblate/templates/snippets/translation-breadcrumb.html diff --git a/weblate/templates/addons/addon_detail.html b/weblate/templates/addons/addon_detail.html index 42794697c39e..6a50894e952d 100644 --- a/weblate/templates/addons/addon_detail.html +++ b/weblate/templates/addons/addon_detail.html @@ -5,8 +5,7 @@ {% load permissions %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} <li><a href="{% url 'addons' path=object.get_url_path %}">{% trans "Add-ons" %}</a></li> <li> {% if instance %} diff --git a/weblate/templates/addons/addon_list.html b/weblate/templates/addons/addon_list.html index 931d7bdb9d2f..db69e00e1175 100644 --- a/weblate/templates/addons/addon_list.html +++ b/weblate/templates/addons/addon_list.html @@ -5,8 +5,7 @@ {% load permissions %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} <li><a href="{% url 'addons' path=object.get_url_path %}">{% trans "Add-ons" %}</a></li> {% endblock %} diff --git a/weblate/templates/browse.html b/weblate/templates/browse.html index 9b84be97102f..f8e1b45c087f 100644 --- a/weblate/templates/browse.html +++ b/weblate/templates/browse.html @@ -15,11 +15,8 @@ {% endblock %} {% block breadcrumbs %} -<li><a href="{{ project.get_absolute_url }}">{{ project }}</a></li> -{% if object.component.slug != "-" %} -{% include "snippets/component-breadcrumb.html" with object=object.component %} -{% endif %} -{% include "snippets/translation-breadcrumb.html" %} +{% path_object_breadcrumbs object %} + <li><a href="{% url 'browse' path=object.get_url_path %}">{% trans "Browse" %}</a></li> <a class="pull-right flip" href="{{ object.get_widgets_url }}"> <img src="{% url 'widget-image' path=object.get_url_path widget='svg' color='badge' extension='svg' %}?native=1" /> diff --git a/weblate/templates/component-progress.html b/weblate/templates/component-progress.html index bf318c94b1a1..311597f605ba 100644 --- a/weblate/templates/component-progress.html +++ b/weblate/templates/component-progress.html @@ -4,8 +4,8 @@ {% load permissions %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} + <li><a href="{% url 'component_progress' path=object.get_url_path %}">{% trans "Progress" %}</a></li> {% endblock %} diff --git a/weblate/templates/component-settings.html b/weblate/templates/component-settings.html index 6abadf56d931..ff9478660894 100644 --- a/weblate/templates/component-settings.html +++ b/weblate/templates/component-settings.html @@ -4,8 +4,7 @@ {% load crispy_forms_tags %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} <li><a href="{% url 'settings' path=object.get_url_path %}">{% trans "Settings" %}</a></li> {% endblock %} diff --git a/weblate/templates/component.html b/weblate/templates/component.html index 613ccde3a437..52985bc998dc 100644 --- a/weblate/templates/component.html +++ b/weblate/templates/component.html @@ -6,8 +6,7 @@ {% load metrics %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs path_object %} <a class="pull-right flip" href="{{ object.get_widgets_url }}"> <img src="{% url 'widget-image' path=object.get_url_path widget='svg' color='badge' extension='svg' %}?native=1" /> diff --git a/weblate/templates/contributor-agreement.html b/weblate/templates/contributor-agreement.html index 06c52921a1d9..9dd3f57abcd0 100644 --- a/weblate/templates/contributor-agreement.html +++ b/weblate/templates/contributor-agreement.html @@ -4,8 +4,7 @@ {% load crispy_forms_tags %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} <li><a href="{% url 'contributor-agreement' path=object.get_url_path %}">{% trans "Contributor agreement" %}</a></li> {% endblock %} diff --git a/weblate/templates/guide.html b/weblate/templates/guide.html index 5b403d1312fb..d5743f6f9955 100644 --- a/weblate/templates/guide.html +++ b/weblate/templates/guide.html @@ -5,8 +5,7 @@ {% load icons %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs path_object %} <li><a href="{% url 'guide' path=object.get_url_path %}">{% trans "Community localization checklist" %}</a></li> <a class="pull-right flip" href="{{ object.get_widgets_url }}"> diff --git a/weblate/templates/matrix.html b/weblate/templates/matrix.html index 102b16f07db1..3761ce3a687f 100644 --- a/weblate/templates/matrix.html +++ b/weblate/templates/matrix.html @@ -4,8 +4,7 @@ {% load icons %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} <li><a href="{% url 'matrix' path=object.get_url_path %}">{% trans "Matrix" %}</a></li> {% endblock %} diff --git a/weblate/templates/new-language.html b/weblate/templates/new-language.html index cd84d511bbe8..03c053eb0adf 100644 --- a/weblate/templates/new-language.html +++ b/weblate/templates/new-language.html @@ -5,8 +5,7 @@ {% load crispy_forms_tags %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs path_object %} {% endblock %} {% block content %} diff --git a/weblate/templates/project.html b/weblate/templates/project.html index 2b8e8d37b8d8..a3546c8e17c7 100644 --- a/weblate/templates/project.html +++ b/weblate/templates/project.html @@ -6,7 +6,7 @@ {% load metrics %} {% block breadcrumbs %} -<li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li> +{% path_object_breadcrumbs path_object %} <a class="pull-right flip" href="{{ object.get_widgets_url }}"> <img src="{% url 'widget-image' path=object.get_url_path widget='svg' color='badge' extension='svg' %}?native=1" /> diff --git a/weblate/templates/replace.html b/weblate/templates/replace.html index cc490a5dacc3..1c33dbf56c3e 100644 --- a/weblate/templates/replace.html +++ b/weblate/templates/replace.html @@ -4,18 +4,7 @@ {% load icons %} {% block breadcrumbs %} -<li><a href="{{ project.get_absolute_url }}">{{ project.name }}</a></li> -{% if component %} -{% include "snippets/component-breadcrumb.html" with object=component %} -{% if translation %} -{% include "snippets/translation-breadcrumb.html" with object=translation %} -{% endif %} -{% elif language %} -<li> - <a href="{{ language.get_absolute_url }}">{{ language }}</a> -</li> - -{% endif %} +{% path_object_breadcrumbs path_object %} <li>{% trans "Search and replace" %}</li> {% endblock %} diff --git a/weblate/templates/screenshots/screenshot_detail.html b/weblate/templates/screenshots/screenshot_detail.html index a0ae2bd7ec60..267294fe45f2 100644 --- a/weblate/templates/screenshots/screenshot_detail.html +++ b/weblate/templates/screenshots/screenshot_detail.html @@ -6,8 +6,7 @@ {% load icons %} {% block breadcrumbs %} -<li><a href="{{ object.translation.component.project.get_absolute_url }}">{{ object.translation.component.project }}</a></li> -{% include "snippets/component-breadcrumb.html" with object=object.translation.component %} +{% path_object_breadcrumbs object.translation.component %} <li><a href="{% url 'screenshots' path=object.translation.component.get_url_path %}">{% trans "Screenshots" %}</a></li> <li><a href="{{ object.get_absolute_url }}">{{ object.name }}</a></li> {% endblock %} diff --git a/weblate/templates/screenshots/screenshot_list.html b/weblate/templates/screenshots/screenshot_list.html index cc67e17b6ac1..35f4fcac8e30 100644 --- a/weblate/templates/screenshots/screenshot_list.html +++ b/weblate/templates/screenshots/screenshot_list.html @@ -6,8 +6,7 @@ {% load icons %} {% block breadcrumbs %} -<li><a href="{{ object.project.get_absolute_url }}">{{ object.project }}</a></li> -{% include "snippets/component-breadcrumb.html" %} +{% path_object_breadcrumbs object %} <li><a href="{% url 'screenshots' path=object.get_url_path %}">{% trans "Screenshots" %}</a></li> {% endblock %} diff --git a/weblate/templates/snippets/component-breadcrumb.html b/weblate/templates/snippets/component-breadcrumb.html deleted file mode 100644 index 74abb65753e5..000000000000 --- a/weblate/templates/snippets/component-breadcrumb.html +++ /dev/null @@ -1,6 +0,0 @@ -<li> - <a href="{{ object.get_absolute_url }}"> - {% include "snippets/component-glossary-badge.html" %} - {{ object.name }} - </a> -</li> diff --git a/weblate/templates/snippets/translation-breadcrumb.html b/weblate/templates/snippets/translation-breadcrumb.html deleted file mode 100644 index c186248fe4b6..000000000000 --- a/weblate/templates/snippets/translation-breadcrumb.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load icons %} -<li> - <a href="{{ object.get_absolute_url }}"> - {{ object.language }} - {% if object.is_source %} - {% icon "source.svg" %} - {% endif %} - </a> -</li> diff --git a/weblate/templates/translate.html b/weblate/templates/translate.html index 07adc0ca6693..e4fc45d71410 100644 --- a/weblate/templates/translate.html +++ b/weblate/templates/translate.html @@ -19,14 +19,7 @@ {% endblock %} {% block breadcrumbs %} -<li><a href="{{ project.get_absolute_url }}">{{ project }}</a></li> -{% if object.component.slug != "-" %} -{% include "snippets/component-breadcrumb.html" with object=object.component %} -{% endif %} -{% include "snippets/translation-breadcrumb.html" %} -{% if object.component.slug == "-" %} -<li><a href="{{ unit.translation.component.get_absolute_url }}">{{ unit.translation.component.name }}</a></li> -{% endif %} +{% path_object_breadcrumbs path_object %} <li><a href="{{ object.get_translate_url }}">{% trans "Translate" %}</a></li> <a class="pull-right flip" href="{{ object.get_widgets_url }}"> <img src="{% url 'widget-image' path=object.get_url_path widget='svg' color='badge' extension='svg' %}?native=1" /> diff --git a/weblate/templates/translation.html b/weblate/templates/translation.html index fc831fddd78d..e3ecf39b3819 100644 --- a/weblate/templates/translation.html +++ b/weblate/templates/translation.html @@ -7,9 +7,8 @@ {% load metrics %} {% block breadcrumbs %} -<li><a href="{{ object.component.project.get_absolute_url }}">{{ object.component.project }}</a></li> -{% include "snippets/component-breadcrumb.html" with object=object.component %} -{% include "snippets/translation-breadcrumb.html" %} +{% path_object_breadcrumbs path_object %} + <a class="pull-right flip" href="{{ object.get_widgets_url }}"> <img src="{% url 'widget-image' path=object.get_url_path widget='svg' color='badge' extension='svg' %}?native=1" /> </a> diff --git a/weblate/templates/zen.html b/weblate/templates/zen.html index 20eef06bf6d3..132deba76e8a 100644 --- a/weblate/templates/zen.html +++ b/weblate/templates/zen.html @@ -18,11 +18,7 @@ {% endblock %} {% block breadcrumbs %} -<li><a href="{{ project.get_absolute_url }}">{{ project }}</a></li> -{% if object.component.slug != "-" %} -{% include "snippets/component-breadcrumb.html" with object=object.component %} -{% endif %} -{% include "snippets/translation-breadcrumb.html" %} +{% path_object_breadcrumbs path_object %} <li><a href="{% url 'zen' path=object.get_url_path %}">{% trans "Zen" %}</a></li> <a class="pull-right flip" href="{{ object.get_widgets_url }}"> <img src="{% url 'widget-image' path=object.get_url_path widget='svg' color='badge' extension='svg' %}?native=1" /> diff --git a/weblate/trans/views/basic.py b/weblate/trans/views/basic.py index 152131ccc629..8ef478ae21fc 100644 --- a/weblate/trans/views/basic.py +++ b/weblate/trans/views/basic.py @@ -141,6 +141,7 @@ def show_engage(request, path): { "allow_index": True, "object": obj, + "path_object": obj, "project": project, "full_stats": obj.stats, "languages": stats_obj.languages, @@ -211,6 +212,7 @@ def show_project(request, obj): { "allow_index": True, "object": obj, + "path_object": obj, "project": obj, "last_changes": last_changes, "last_announcements": last_announcements, @@ -272,6 +274,7 @@ def show_component(request, obj): { "allow_index": True, "object": obj, + "path_object": obj, "project": obj.project, "component": obj, "translations": translations, @@ -358,6 +361,7 @@ def show_translation(request, obj): "translation.html", { "allow_index": True, + "path_object": obj, "object": obj, "project": project, "component": obj.component, @@ -484,6 +488,7 @@ def new_language(request, path): "new-language.html", { "object": obj, + "path_object": obj, "project": obj.project, "component": obj, "form": form, @@ -526,6 +531,7 @@ def guide(request, path): "guide.html", { "object": obj, + "path_object": obj, "project": obj.project, "component": obj, "guidelines": obj.guidelines, diff --git a/weblate/trans/views/edit.py b/weblate/trans/views/edit.py index 3970df133ffe..77c08ab8d09d 100644 --- a/weblate/trans/views/edit.py +++ b/weblate/trans/views/edit.py @@ -632,6 +632,7 @@ def translate(request, path): # noqa: C901 request, "translate.html", { + "path_object": obj, "this_unit_url": this_unit_url, "first_unit_url": base_unit_url + "1", "last_unit_url": base_unit_url + str(num_results), @@ -901,6 +902,7 @@ def load_zen(request, path): "zen-units.html", { "object": obj, + "path_object": obj, "project": project, "component": obj.component if not isinstance(obj, ProjectLanguage) @@ -1032,6 +1034,7 @@ def browse(request, path): "browse.html", { "object": obj, + "path_object": obj, "project": project, "component": getattr(obj, "component", None), "units": units, diff --git a/weblate/utils/views.py b/weblate/utils/views.py index f18cde6faa0a..c768a4de0ae0 100644 --- a/weblate/utils/views.py +++ b/weblate/utils/views.py @@ -219,7 +219,7 @@ def parse_path( def parse_path_units(request, path: list[str], types: tuple[Any]): obj = parse_path(request, path, types) - context = {"components": None} + context = {"components": None, "path_object": obj} if isinstance(obj, Translation): unit_set = obj.unit_set.all() context["translation"] = obj