From 41d5a686426f92f79f26b52a83e7d952c7a9f1bf Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sep 10 2019 15:54:34 +0000 Subject: frontend: add new template macro owner_url This simplifies and de-duplicates the repo_file_href and copr_url macros. Note that for /repo/ routes we can not use copr_url, because that is adding unwanted `coprname=` argument, which is not accepted by that particular route and leads to additional query string. --- diff --git a/frontend/coprs_frontend/coprs/templates/_helpers.html b/frontend/coprs_frontend/coprs/templates/_helpers.html index 965dc48..37f3ae8 100644 --- a/frontend/coprs_frontend/coprs/templates/_helpers.html +++ b/frontend/coprs_frontend/coprs/templates/_helpers.html @@ -242,6 +242,24 @@ {% endmacro %} +{%- macro owner_url(view, owner) %} + {#- Given the owner object (user or group) generate proper URL for view + + Note that if you wan't to use this method for routes which _accept_ "coprname" + argument, you wan't to use `copr_url` below. + + Usage: + owner_url('coprs_ns.foo', groupX) + owner_url('coprs_ns.foo', user1, arg1='bar', arg2='baz') + #} + {%- if owner.at_name %} + {{- url_for(view, group_name=owner.name, **kwargs)|fix_url_https_frontend }} + {%- else %} + {{- url_for(view, username=owner.name, **kwargs)|fix_url_https_frontend }} + {%- endif %} +{% endmacro %} + + {%- macro copr_url(view, copr) %} {#- Examine given copr and generate proper URL for the `view` @@ -250,17 +268,13 @@ Usage: copr_url('coprs_ns.foo', copr) - copr_url('coprs_ns.foo', copr, arg1='bar', arg2='baz) + copr_url('coprs_ns.foo', copr, arg1='bar', arg2='baz') #} - {%- if not copr.is_a_group_project %} - {{- url_for(view, username=copr.user.name, coprname=copr.name, **kwargs) }} - {%- else %} - {{- url_for(view, group_name=copr.group.name, coprname=copr.name, **kwargs) }} - {%- endif %} + {{- owner_url(view, copr.owner, coprname=copr.name, **kwargs) }} {%- endmacro %} -{%- macro owner_url(copr) %} +{%- macro copr_owner_url(copr) %} {% if copr.is_a_group_project %} {{- url_for('groups_ns.list_projects_by_group', group_name=copr.group.name) }} {% else %} @@ -432,23 +446,12 @@ https://admin.fedoraproject.org/accounts/group/view/{{name}} {% macro repo_file_href(copr, repo) %} - {% if copr.is_a_group_project: %} - {{- url_for('coprs_ns.generate_repo_file', - group_name=copr.group.name, - copr_dirname=copr.main_dir.name, - name_release=repo.name_release, - repofile=repo.repo_file, - _external=True - )|fix_url_https_frontend -}} - {% else %} - {{- url_for('coprs_ns.generate_repo_file', - username=copr.user.name, - copr_dirname=copr.main_dir.name, - name_release=repo.name_release, - repofile=repo.repo_file, - _external=True - )|fix_url_https_frontend -}} - {% endif %} + {{- owner_url('coprs_ns.generate_repo_file', + copr.owner, + copr_dirname=copr.main_dir.name, + name_release=repo.name_release, + repofile=repo.repo_file, + _external=True) -}} {% endmacro %} diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/forks.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/forks.html index 6c6139c..6bc2de1 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/detail/forks.html +++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/forks.html @@ -1,5 +1,5 @@ {% extends "coprs/detail.html" %} -{% from "_helpers.html" import copr_name, owner_url, initialize_datatables %} +{% from "_helpers.html" import copr_name, copr_owner_url, initialize_datatables %} {% block title %}Forks of {{ copr_name(copr) }}{% endblock %} {% set selected_tab = "forks" %} @@ -27,7 +27,7 @@ {% for fork in copr.forks %} - {{ fork.owner_name }} + {{ fork.owner_name }} {{ fork.name }}