Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use URL reversing #7740

Closed
etj opened this issue Jul 6, 2021 · 6 comments
Closed

Use URL reversing #7740

etj opened this issue Jul 6, 2021 · 6 comments
Assignees
Labels
frontend Issues regarding Frontend and styling major A high priority issue which might affect a lot of people or large parts of the codebase
Milestone

Comments

@etj
Copy link
Contributor

etj commented Jul 6, 2021

Is your feature request related to a problem? Please describe.

In the code (both python and HTML templates) there are explicit URLs toward the internal GeoNode services.
If for some reason these URLs are programmatically changed (for instance for adding a root context path), the templates need to be modified/overridden in order to use the modified URLs.
Most of the code already uses URL reversal resolution, but in some cases URL are still composed by hand.

Describe the solution you'd like

URL reverse functions should be used whenever possibile.

HTML code like

<li><a target="_blank" href="../catalogue/csw_to_extra_format/{{resource.uuid}}/{{resource.title | slugify }}.txt"> {% trans "Text format" %} </a></li>

should be modified so to use the {% url %} tag:

<li><a target="_blank" href="{% url 'csw_render_extra_format_txt'  resource.uuid resource.title|slugify %}"> {% trans "Text format" %} </a></li>

Python code like:

        return HttpResponseRedirect(
            f'/admin/{model_class._meta.app_label}/{model}/'
        )

should be modified as well.

@etj
Copy link
Contributor Author

etj commented Jul 6, 2021

First batch of explicit URLs found:

  • ./geonode/templates/metadata_form_js.html: url: '/geonode/h_keywords_api',
    quite straightforward

  • find ../geonode/ -name batch_permissions.html | xargs grep permissions/batch/
    <form action="/{{ model|lower }}s/permissions/batch/" method="post">
    
    find ../geonode/ -name urls.py | xargs grep permissions | grep batch
    ../geonode/geonode/layers/urls.py:    url(r'^permissions/batch/$',
    ../geonode/geonode/layers/urls.py:        views.layer_batch_permissions, name='layer_batch_permissions'),
    

    Even if the html is quite generic on the model, only Layer is implementing batch permission update.
    Can be replaced by

    <form action="{% url model|lower|add:'_batch_permissions' %}" method="post">

@etj
Copy link
Contributor Author

etj commented Jul 7, 2021

diff --git a/geonode/layers/templates/layers/layer_detail.html b/geonode/layers/templates/layers/layer_detail.html
index a6a64c618..278404b23 100644
--- a/geonode/layers/templates/layers/layer_detail.html
+++ b/geonode/layers/templates/layers/layer_detail.html
@@ -554,8 +554,8 @@
                 {% trans "Full metadata" %}
                 </h5>
                 <ul>
-                    <li><a target="_blank" href="../catalogue/csw_to_extra_format/{{resource.uuid}}/{{resource.title | slugify }}.txt"> {% trans "Text format" %} </a></li>
-                    <li><a target="_blank" href="../catalogue/csw_to_extra_format/{{resource.uuid}}/{{resource.title | slugify }}.html"> {% trans "HTML format" %} </a></li>
+                    <li><a target="_blank" href="{% url 'csw_render_extra_format_txt'  resource.uuid resource.title|slugify %}"> {% trans "Text format" %} </a></li>
+                    <li><a target="_blank" href="{% url 'csw_render_extra_format_html' resource.uuid resource.title|slugify %}"> {% trans "HTML format" %} </a></li>
                 </ul>
             </div>
             <div style="margin-bottom:20px">
@@ -691,7 +691,7 @@
     {% if resource.storeType == "remoteStore" %}
     <li class="list-group-item">
       <h4>{% trans "External service layer" %}</h4>
-      <div>{% trans "Source" %}: <a href="/services/{{resource.remote_service.id}}">{{ resource.remote_service.title }}</a>
+      <div>{% trans "Source" %}: <a href="{% url 'service_detail' resource.remote_service.id %}">{{ resource.remote_service.title }}</a>
       </div>
       <div>{% trans "Type" %}: {{ resource.remote_service.type }}</div>
     </li>

@etj
Copy link
Contributor Author

etj commented Jul 7, 2021

These are some of templates to be fixed yet:

$ find  geonode -name "*.html" | xargs grep 'href="/' 
geonode/client/templates/leaflet/maps/map_edit.html:    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"/>
geonode/client/templates/leaflet/maps/map_view.html:    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"/>
geonode/templates/metadata_detail.html:        <dd><a href="/search/?category__identifier__in={{ resource.category.identifier }}">{{ resource.category }}</a> {% if resource.category.description %}<a href="#category-more" data-toggle="collapse" data-target=".category-more"><i class="fa fa-info-circle"></i></a>{% endif %}</dd>
geonode/templates/metadata_detail.html:        <dd><a href="/groups/group/{{ resource.group.name }}/activity/">{{ group }}</a> </dd>
geonode/templates/help.html:    <p>The <a href="/layers">Layers</a> tab allows you to browse data uploaded to this GeoNode.</p>
geonode/templates/help.html:    <p>The <a href="/developer"> Developer</a> page is the place for developers to get started building applications against the GeoNode. It includes instructions on using the web services, links to the source code of the GeoNode, and information about the open source projects used to create it.</p>
geonode/templates/help.html:    <p>The <a href="/maps">Maps</a> tab is a gateway to map exploration on GeoNode.  From here you can <strong>search for a map</strong> or <strong>create a map</strong>, which will open the <a href="/maps/new">Map Composer</a>.</p>
geonode/templates/help.html:    <p>To create a new map go to the <a href="/maps">Contributed Maps</a> tab and click the <a href="/maps/new">create your own map</a> link.</p>
geonode/templates/help.html:    <p>This will take you to the <a href="/maps/new">Map Composer</a> with a base layer loaded.</p>
geonode/templates/help.html:    <p>Note that the <a href="/maps/new">Map Composer</a> also has a button to publish the map. Just be sure to save the map before publishing if there are changes that you want others to see. It publishes the last saved version, not the last viewed version.</p>
geonode/templates/help.html:    <p>You will be able to see your new map when you search for it from the <a href="/maps">Maps</a> tab.</p>
geonode/templates/privacy-cookies.html:<p style="text-align: justify;"><a class="navbar-brand" style="background-color: #028BAF" href="/">GeoNode</a></p>
geonode/templates/500.html:              <li><a href="/admin/people/profile/add/">{% trans "Add User" %}</a></li>
geonode/templates/500.html:              <li><a title="{% trans "Help" %}" rel="tooltip" href="/help/"><i class="fa fa-question-circle"></i> {% trans "Help" %}</a></li>
geonode/base/templates/base/_resourcebase_info_panel.html:    <dd><a href="/groups/group/{{ resource.group.name }}/activity/">{{ group }}</a> </dd>
geonode/layers/templates/layers/layer_change_poc.html:{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans "Home" %}</a> &rsaquo; {% trans "Change point of contact" %}</div>{% endblock %}
geonode/layers/templates/layers/layer_style_manage.html:      Manage Available Styles for <a href="/layers/{{ layer_title }}">{{ layer_title }}</a>
geonode/static/geonode/js/templates/upload.html:    a href="/data/geonode:<%= name %>" class='btn'>Layer page</a>

@etj etj self-assigned this Jul 7, 2021
@etj
Copy link
Contributor Author

etj commented Jul 7, 2021

The file geonode/templates/help.html has some {% blocktrans %} that include hrefs.
This means that the URLs to be reversed are also into the .po files, such as https://github.com/GeoNode/geonode/blob/3.2.0/geonode/locale/en/LC_MESSAGES/django.po#L5275

etj added a commit to etj/geonode that referenced this issue Jul 7, 2021
@etj etj mentioned this issue Jul 7, 2021
12 tasks
@afabiani afabiani added the minor A low priority issue which might affect only some users and /or not the main functionality label Jul 8, 2021
@afabiani afabiani added this to the 3.2.1 milestone Jul 8, 2021
etj added a commit to etj/geonode that referenced this issue Jul 8, 2021
etj added a commit to etj/geonode that referenced this issue Jul 8, 2021
etj added a commit to etj/geonode that referenced this issue Jul 8, 2021
@etj
Copy link
Contributor Author

etj commented Jul 8, 2021

Can't find how to reverse /admin/maps/layer

https://github.com/GeoNode/geonode/blob/3.2.0/geonode/layers/views.py#L1293

@giohappy
Copy link
Contributor

giohappy commented Jul 8, 2021

@etj I suspect that layer_change_poc is a dead method. I don't see it used anyware and no url is defined for it.
I think we could remove it.

@giohappy giohappy modified the milestone: 3.2.1 Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
etj added a commit to etj/geonode that referenced this issue Jul 9, 2021
giohappy pushed a commit that referenced this issue Jul 9, 2021
* [#7740] Use URL reversing

* [#7740] Use URL reversing: po files

* [#7740] Use URL reversing: more changes in po files

* [#7740] Use URL reversing

* [#7740] Use URL reversing: py files

* [#7740] Use URL reversing: py files

* [#7740] Use URL reversing - fixes

* [#7740] Use URL reversing - fixes

* [#7740] Use URL reversing - fixes
@giohappy giohappy closed this as completed Jul 9, 2021
@afabiani afabiani added major A high priority issue which might affect a lot of people or large parts of the codebase frontend Issues regarding Frontend and styling and removed minor A low priority issue which might affect only some users and /or not the main functionality labels Jul 9, 2021
mattiagiupponi pushed a commit to mattiagiupponi/geonode that referenced this issue Jul 12, 2021
* [GeoNode#7740] Use URL reversing

* [GeoNode#7740] Use URL reversing: po files

* [GeoNode#7740] Use URL reversing: more changes in po files

* [GeoNode#7740] Use URL reversing

* [GeoNode#7740] Use URL reversing: py files

* [GeoNode#7740] Use URL reversing: py files

* [GeoNode#7740] Use URL reversing - fixes

* [GeoNode#7740] Use URL reversing - fixes

* [GeoNode#7740] Use URL reversing - fixes
mattiagiupponi added a commit that referenced this issue Jul 12, 2021
Fix reverse urls for get_url_for_app_model and get_url_for_model methods
giohappy pushed a commit that referenced this issue Jul 12, 2021
* [#7740] Use URL reversing (#7746)

* [#7740] Use URL reversing

* [#7740] Use URL reversing: po files

* [#7740] Use URL reversing: more changes in po files

* [#7740] Use URL reversing

* [#7740] Use URL reversing: py files

* [#7740] Use URL reversing: py files

* [#7740] Use URL reversing - fixes

* [#7740] Use URL reversing - fixes

* [#7740] Use URL reversing - fixes

* [Fixes #7771] Fix flake8 issues

* [Fixes #7771] Fix reverse urls for get_url_for_app_model and get_url_for_model methods

Co-authored-by: Emanuele Tajariol <[email protected]>
afabiani pushed a commit that referenced this issue Jul 13, 2021
* [Fixes #7740] Fix reverse urls

Fix reverse urls for get_url_for_app_model and get_url_for_model methods

* Remove unused import

* Fix flake8 formatting
afabiani pushed a commit that referenced this issue Jul 14, 2021
* [Fixes #7740] Fix reverse urls

Fix reverse urls for get_url_for_app_model and get_url_for_model methods

* Remove unused import

* Fix flake8 formatting

* [Fixes #7740] Reverse url fix for tests
afabiani pushed a commit that referenced this issue Jul 14, 2021
* [Backport Resolves #7392] Fix upload/replace/append layer

* [Fixes #7740] Fix reverse urls

Fix reverse urls for get_url_for_app_model and get_url_for_model methods

* Remove unused import

* Fix flake8 formatting

* [Fixes #7740] Reverse url fix for tests

* [Fixes #7801] Fix broken tests for 3.2.x build

* [Fixes #7801] Fix flake8 error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Issues regarding Frontend and styling major A high priority issue which might affect a lot of people or large parts of the codebase
Projects
None yet
Development

No branches or pull requests

3 participants