Skip to content

Commit

Permalink
[GeoNode#7740] Use URL reversing: py files
Browse files Browse the repository at this point in the history
  • Loading branch information
etj committed Jul 8, 2021
1 parent fdb7854 commit 7d62c29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions geonode/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from django.utils.translation import ugettext as _
from django.core.exceptions import PermissionDenied
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse

from dal import views, autocomplete
from user_messages.models import Message
Expand Down Expand Up @@ -58,6 +59,14 @@
)


def get_url_for_app_model(model, model_class):
return reverse(f'{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'{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 @@ -72,8 +81,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 @@ -104,8 +112,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 @@ -135,8 +142,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 @@ -177,8 +183,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/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ def slugify_zh(text, separator='_'):


def get_legend_url(
instance, style_name, /,
instance, style_name,
service_url=None,
layer_name=None,
version='1.3.0',
Expand Down

0 comments on commit 7d62c29

Please sign in to comment.