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

[Fixes #7771] Use URL reversing (#7746) #7788

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion geonode/base/templates/base/_resourcebase_info_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

{% if resource.group %}
<dt>{% trans "Group" %}</dt>
<dd><a href="/groups/group/{{ resource.group.name }}/activity/">{{ group }}</a> </dd>
<dd><a href="{% url 'group_activity' resource.group.name %}">{{ group }}</a> </dd>
{% endif %}

{% if resource.doi %}
Expand Down
3 changes: 2 additions & 1 deletion geonode/base/templates/base/batch_permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<div class="page-header">
<h2 class="page-title">{% trans "Set Permissions" %}</h2>
</div>
<form action="/{{ model|lower }}s/permissions/batch/" method="post">

<form action="{% url model|lower|add:'s_batch_permissions' %}" method="post">
{% csrf_token %}
{{ form|as_bootstrap }}
<div>
Expand Down
24 changes: 16 additions & 8 deletions geonode/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from django.core.exceptions import PermissionDenied
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse

# Geonode dependencies
from geonode.maps.models import Map
Expand Down Expand Up @@ -65,6 +66,16 @@
logger = logging.getLogger(__name__)


def get_url_for_app_model(model, model_class):
return reverse(f'admin:{model_class._meta.app_label}_{model}_changelist')
# was: return f'/admin/{model_class._meta.app_label}/{model}/'


def get_url_for_model(model):
return reverse(f'admin:{model.lower()}s_{model.lower()}_changelist')
# was: f'/admin/{model.lower()}s/{model.lower()}/'


def user_and_group_permission(request, model):
if not request.user.is_superuser:
raise PermissionDenied
Expand All @@ -79,8 +90,7 @@ def user_and_group_permission(request, model):
ids = request.POST.get("ids")
if "cancel" in request.POST or not ids:
return HttpResponseRedirect(
f'/admin/{model_class._meta.app_label}/{model}/'
)
get_url_for_app_model(model, model_class))

if request.method == 'POST':
form = UserAndGroupPermissionsForm(request.POST)
Expand Down Expand Up @@ -111,8 +121,7 @@ def user_and_group_permission(request, model):
(permissions_names, resources_names, users_usernames, groups_names, delete_flag))

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

form = UserAndGroupPermissionsForm({
'permission_type': ('r', ),
Expand Down Expand Up @@ -142,8 +151,7 @@ def batch_modify(request, model):

if "cancel" in request.POST or not ids:
return HttpResponseRedirect(
f'/admin/{model.lower()}s/{model.lower()}/'
)
get_url_for_model(model))

if request.method == 'POST':
form = BatchEditForm(request.POST)
Expand Down Expand Up @@ -184,8 +192,8 @@ def get_or_create(keyword):
keywords_through.objects.bulk_create(new_keywords, ignore_conflicts=True)

return HttpResponseRedirect(
f'/admin/{model.lower()}s/{model.lower()}/'
)
get_url_for_model(model))

return render(
request,
template,
Expand Down
2 changes: 1 addition & 1 deletion geonode/layers/templates/layers/layer_change_poc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% load i18n %}

{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans "Home" %}</a> &rsaquo; {% trans "Change point of contact" %}</div>{% endblock %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="{% url 'home' %}">{% trans "Home" %}</a> &rsaquo; {% trans "Change point of contact" %}</div>{% endblock %}

{% block title %}{% trans 'Change point of contact' %}{% endblock %}

Expand Down
6 changes: 3 additions & 3 deletions geonode/layers/templates/layers/layer_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ <h5 class="modal-title" id="myModalLabel">
{% 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">
Expand Down Expand Up @@ -690,7 +690,7 @@ <h4>{% trans "Styles" %}</h4>
{% if resource.storetype == "remote" %}
<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>
Expand Down
5 changes: 3 additions & 2 deletions geonode/layers/templates/layers/layer_style_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
<div class="page-header">
<h2>{% trans "Manage Styles" %}</h2>
</div>
<h4>{% blocktrans with layer.alternate as layer_title %}
Manage Available Styles for <a href="/layers/{{ layer_title }}">{{ layer_title }}</a>
{% url 'layer_detail' layer.alternate as layer_url %}
<h4>{% blocktrans with layer_title=layer.alternate %}
Manage Available Styles for <a href="{{ layer_url }}">{{ layer_title }}</a>
{% endblocktrans %}</h4>
<form action="{% url "layer_style_manage" layer.service_typename %}" method="POST">
<div class="row grid-spacer">
Expand Down
13 changes: 5 additions & 8 deletions geonode/layers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@
from geonode.resource.utils import update_resource

from geonode.base.auth import get_or_create_token
from geonode.base.forms import (
CategoryForm,
TKeywordForm,
BatchPermissionsForm,
ThesaurusAvailableForm)
from geonode.base.views import batch_modify
from geonode.base.forms import CategoryForm, TKeywordForm, BatchPermissionsForm, ThesaurusAvailableForm
from geonode.base.views import batch_modify, get_url_for_model
from geonode.base.models import (
Thesaurus,
TopicCategory)
Expand Down Expand Up @@ -1225,6 +1221,7 @@ def layer_change_poc(request, ids, template='layers/layer_change_poc.html'):
# Process the data in form.cleaned_data
# ...
# Redirect after POST
# Pls fix following url, it seems not bound
return HttpResponseRedirect('/admin/maps/layer')
else:
form = PocForm() # An unbound form
Expand Down Expand Up @@ -1596,7 +1593,7 @@ def batch_permissions(request, model):

if "cancel" in request.POST or not ids:
return HttpResponseRedirect(
f'/admin/{model.lower()}s/{model.lower()}/'
get_url_for_model(model)
)

if request.method == 'POST':
Expand Down Expand Up @@ -1631,7 +1628,7 @@ def batch_permissions(request, model):
except set_permissions.OperationalError as exc:
celery_logger.exception('Sending task raised: %r', exc)
return HttpResponseRedirect(
f'/admin/{model.lower()}s/{model.lower()}/'
get_url_for_model(model)
)
return render(
request,
Expand Down
Binary file modified geonode/locale/af/LC_MESSAGES/django.mo
Binary file not shown.
22 changes: 11 additions & 11 deletions geonode/locale/af/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2832,12 +2832,12 @@ msgstr "Bestuur Styles"
#, python-format
msgid ""
"\n"
" Manage Available Styles for <a href=\"/layers/%(layer_title)s\">"
" Manage Available Styles for <a href=\"{{ layer_url }}\">"
"%(layer_title)s</a>\n"
" "
msgstr ""
"\n"
"Bestuur beskikbaar style vir <a href=\"/layers/%(layer_title)s\">"
"Bestuur beskikbaar style vir <a href=\"{{ layer_url }}\">"
"%(layer_title)s</a>"

#, fuzzy
Expand Down Expand Up @@ -5722,13 +5722,13 @@ msgid ""
"p>\n"
"\n"
" <h4 id=\"browsing-data\">Browsing Layers</h4>\n"
" <p>The <a href=\"/layers\">Layers</a> tab allows you to browse data "
" <p>The <a href=\"{{ url_layer_browse }}\">Layers</a> tab allows you to browse data "
"uploaded to this GeoNode.</p>\n"
" <p>All data can be downloaded in a variety of formats, for use in other "
"applications.</p>\n"
"\n"
" <h4 id=\"developer-access\">Developer Access</h4>\n"
" <p>The <a href=\"/developer\"> Developer</a> page is the place for "
" <p>The <a href=\"{{ url_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 "
Expand All @@ -5737,9 +5737,9 @@ msgid ""
" <h4 id=\"browsing-maps\">Browsing Maps</h4>\n"
" <p>The GeoNode allows users to create and share maps with one another.</"
"p>\n"
" <p>The <a href=\"/maps\">Maps</a> tab is a gateway to map exploration on "
" <p>The <a href=\"{{ url_maps_browse }}\">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 "
"<strong>create a map</strong>, which will open the <a href=\"{{ url_maps_new }}\">Map "
"Composer</a>.</p>\n"
" <h5>Google Earth Mode</h5>\n"
" <p>Any map viewed in the interactive map editor can be seen in 3D mode "
Expand All @@ -5748,9 +5748,9 @@ msgid ""
"Google Earth plugin installed you will be prompted to install it.</p>\n"
"\n"
" <h4 id=\"creating-a-map\">Creating a Map</h4>\n"
" <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>\n"
" <p>This will take you to the <a href=\"/maps/new\">Map Composer</a> with "
" <p>To create a new map go to the <a href=\"{{ url_maps_browse }}\">Contributed Maps</a> "
"tab and click the <a href=\"{{ url_maps_new }}\">create your own map</a> link.</p>\n"
" <p>This will take you to the <a href=\"{{ url_maps_new }}\">Map Composer</a> with "
"a base layer loaded.</p>\n"
" <p>To add data layers from the GeoNode click on the green plus button "
"located below the layers tab on the left hand side of the screen. This will "
Expand Down Expand Up @@ -5784,7 +5784,7 @@ msgid ""
" </ol>\n"
" <p>This will put an interactive widget showing you map in your web page "
"or blog post.</p>\n"
" <p>Note that the <a href=\"/maps/new\">Map Composer</a> also has a "
" <p>Note that the <a href=\"{{ url_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>\n"
Expand All @@ -5800,7 +5800,7 @@ msgid ""
" <li>Save the map.</li>\n"
" </ol>\n"
" <p>You will be able to see your new map when you search for it from the "
"<a href=\"/maps\">Maps</a> tab.</p>\n"
"<a href=\"{{ url_maps_browse }}\">Maps</a> tab.</p>\n"
" "
msgstr ""

Expand Down
20 changes: 10 additions & 10 deletions geonode/locale/al/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ msgstr ""
#, python-format
msgid ""
"\n"
" Manage Available Styles for <a href=\"/layers/%(layer_title)s\">"
" Manage Available Styles for <a href=\"{{ layer_url }}\">"
"%(layer_title)s</a>\n"
" "
msgstr ""
Expand Down Expand Up @@ -4809,13 +4809,13 @@ msgid ""
"p>\n"
"\n"
" <h4 id=\"browsing-data\">Browsing Layers</h4>\n"
" <p>The <a href=\"/layers\">Layers</a> tab allows you to browse data "
" <p>The <a href=\"{{ url_layer_browse }}\">Layers</a> tab allows you to browse data "
"uploaded to this GeoNode.</p>\n"
" <p>All data can be downloaded in a variety of formats, for use in other "
"applications.</p>\n"
"\n"
" <h4 id=\"developer-access\">Developer Access</h4>\n"
" <p>The <a href=\"/developer\"> Developer</a> page is the place for "
" <p>The <a href=\"{{ url_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 "
Expand All @@ -4824,9 +4824,9 @@ msgid ""
" <h4 id=\"browsing-maps\">Browsing Maps</h4>\n"
" <p>The GeoNode allows users to create and share maps with one another.</"
"p>\n"
" <p>The <a href=\"/maps\">Maps</a> tab is a gateway to map exploration on "
" <p>The <a href=\"{{ url_maps_browse }}\">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 "
"<strong>create a map</strong>, which will open the <a href=\"{{ url_maps_new }}\">Map "
"Composer</a>.</p>\n"
" <h5>Google Earth Mode</h5>\n"
" <p>Any map viewed in the interactive map editor can be seen in 3D mode "
Expand All @@ -4835,9 +4835,9 @@ msgid ""
"Google Earth plugin installed you will be prompted to install it.</p>\n"
"\n"
" <h4 id=\"creating-a-map\">Creating a Map</h4>\n"
" <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>\n"
" <p>This will take you to the <a href=\"/maps/new\">Map Composer</a> with "
" <p>To create a new map go to the <a href=\"{{ url_maps_browse }}\">Contributed Maps</a> "
"tab and click the <a href=\"{{ url_maps_new }}\">create your own map</a> link.</p>\n"
" <p>This will take you to the <a href=\"{{ url_maps_new }}\">Map Composer</a> with "
"a base layer loaded.</p>\n"
" <p>To add data layers from the GeoNode click on the green plus button "
"located below the layers tab on the left hand side of the screen. This will "
Expand Down Expand Up @@ -4871,7 +4871,7 @@ msgid ""
" </ol>\n"
" <p>This will put an interactive widget showing you map in your web page "
"or blog post.</p>\n"
" <p>Note that the <a href=\"/maps/new\">Map Composer</a> also has a "
" <p>Note that the <a href=\"{{ url_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>\n"
Expand All @@ -4887,7 +4887,7 @@ msgid ""
" <li>Save the map.</li>\n"
" </ol>\n"
" <p>You will be able to see your new map when you search for it from the "
"<a href=\"/maps\">Maps</a> tab.</p>\n"
"<a href=\"{{ url_maps_browse }}\">Maps</a> tab.</p>\n"
" "
msgstr ""

Expand Down
20 changes: 10 additions & 10 deletions geonode/locale/am/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ msgstr ""
#, python-format
msgid ""
"\n"
" Manage Available Styles for <a href=\"/layers/%(layer_title)s\">"
" Manage Available Styles for <a href=\"{{ layer_url }}\">"
"%(layer_title)s</a>\n"
" "
msgstr ""
Expand Down Expand Up @@ -5085,13 +5085,13 @@ msgid ""
"p>\n"
"\n"
" <h4 id=\"browsing-data\">Browsing Layers</h4>\n"
" <p>The <a href=\"/layers\">Layers</a> tab allows you to browse data "
" <p>The <a href=\"{{ url_layer_browse }}\">Layers</a> tab allows you to browse data "
"uploaded to this GeoNode.</p>\n"
" <p>All data can be downloaded in a variety of formats, for use in other "
"applications.</p>\n"
"\n"
" <h4 id=\"developer-access\">Developer Access</h4>\n"
" <p>The <a href=\"/developer\"> Developer</a> page is the place for "
" <p>The <a href=\"{{ url_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 "
Expand All @@ -5100,9 +5100,9 @@ msgid ""
" <h4 id=\"browsing-maps\">Browsing Maps</h4>\n"
" <p>The GeoNode allows users to create and share maps with one another.</"
"p>\n"
" <p>The <a href=\"/maps\">Maps</a> tab is a gateway to map exploration on "
" <p>The <a href=\"{{ url_maps_browse }}\">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 "
"<strong>create a map</strong>, which will open the <a href=\"{{ url_maps_new }}\">Map "
"Composer</a>.</p>\n"
" <h5>Google Earth Mode</h5>\n"
" <p>Any map viewed in the interactive map editor can be seen in 3D mode "
Expand All @@ -5111,9 +5111,9 @@ msgid ""
"Google Earth plugin installed you will be prompted to install it.</p>\n"
"\n"
" <h4 id=\"creating-a-map\">Creating a Map</h4>\n"
" <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>\n"
" <p>This will take you to the <a href=\"/maps/new\">Map Composer</a> with "
" <p>To create a new map go to the <a href=\"{{ url_maps_browse }}\">Contributed Maps</a> "
"tab and click the <a href=\"{{ url_maps_new }}\">create your own map</a> link.</p>\n"
" <p>This will take you to the <a href=\"{{ url_maps_new }}\">Map Composer</a> with "
"a base layer loaded.</p>\n"
" <p>To add data layers from the GeoNode click on the green plus button "
"located below the layers tab on the left hand side of the screen. This will "
Expand Down Expand Up @@ -5147,7 +5147,7 @@ msgid ""
" </ol>\n"
" <p>This will put an interactive widget showing you map in your web page "
"or blog post.</p>\n"
" <p>Note that the <a href=\"/maps/new\">Map Composer</a> also has a "
" <p>Note that the <a href=\"{{ url_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>\n"
Expand All @@ -5163,7 +5163,7 @@ msgid ""
" <li>Save the map.</li>\n"
" </ol>\n"
" <p>You will be able to see your new map when you search for it from the "
"<a href=\"/maps\">Maps</a> tab.</p>\n"
"<a href=\"{{ url_maps_browse }}\">Maps</a> tab.</p>\n"
" "
msgstr ""

Expand Down
Binary file modified geonode/locale/ar/LC_MESSAGES/django.mo
Binary file not shown.
Loading