#45 Redirect after asset deletion
This commit is contained in:
parent
b42be489dc
commit
04fe93c7bb
@ -1,3 +1,5 @@
|
||||
from django.shortcuts import redirect
|
||||
|
||||
def get_all_subclasses(cls):
|
||||
'''
|
||||
Gets all subclasses recursively, does not contain
|
||||
@ -9,3 +11,15 @@ def get_all_subclasses(cls):
|
||||
subclass_list.append(subclass)
|
||||
subclass_list += get_all_subclasses(subclass)
|
||||
return subclass_list
|
||||
|
||||
def redirect_referer_or(request, url='/'):
|
||||
'''
|
||||
Returns a django redirect to the requests referer,
|
||||
if there is no referer the redirect will poin to the given url
|
||||
Default url is /
|
||||
'''
|
||||
referer = request.META.get('HTTP_REFERER')
|
||||
if referer is not None:
|
||||
return redirect(referer)
|
||||
else:
|
||||
return redirect(url)
|
@ -14,6 +14,7 @@ from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from lostplaces.models import Place
|
||||
from lostplaces.common import redirect_referer_or
|
||||
|
||||
class IsAuthenticatedMixin(LoginRequiredMixin, View):
|
||||
'''
|
||||
@ -108,4 +109,4 @@ class PlaceAssetDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SingleOb
|
||||
place_id = self.get_object().place.id
|
||||
self.get_object().delete()
|
||||
messages.success(self.request, self.success_message)
|
||||
return redirect(reverse_lazy('place_detail', kwargs={'pk': place_id}))
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place_id}))
|
||||
|
@ -19,6 +19,7 @@ from lostplaces.models import Place, PlaceImage
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin, IsPlaceSubmitterMixin
|
||||
from lostplaces.views.place_image_views import MultiplePlaceImageUploadMixin
|
||||
from lostplaces.forms import PlaceForm, PlaceImageForm, TagSubmitForm
|
||||
from lostplaces.common import redirect_referer_or
|
||||
|
||||
from taggit.models import Tag
|
||||
|
||||
@ -135,13 +136,7 @@ class PlaceFavoriteView(IsAuthenticatedMixin, View):
|
||||
request.user.explorer.favorite_places.add(place)
|
||||
request.user.explorer.save()
|
||||
|
||||
referer = request.META.get('HTTP_REFERER')
|
||||
if referer is not None:
|
||||
return redirect(referer)
|
||||
else:
|
||||
return redirect(
|
||||
reverse_lazy('place_detail', kwargs={'pk': place.pk})
|
||||
)
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))
|
||||
|
||||
class PlaceUnfavoriteView(IsAuthenticatedMixin, View):
|
||||
|
||||
@ -151,10 +146,4 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View):
|
||||
request.user.explorer.favorite_places.remove(place)
|
||||
request.user.explorer.save()
|
||||
|
||||
referer = request.META.get('HTTP_REFERER')
|
||||
if referer is not None:
|
||||
return redirect(referer)
|
||||
else:
|
||||
return redirect(
|
||||
reverse_lazy('place_detail', kwargs={'pk': place.pk})
|
||||
)
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))
|
@ -14,6 +14,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from lostplaces.forms import ExplorerCreationForm, TagSubmitForm
|
||||
from lostplaces.models import Place, PhotoAlbum
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin
|
||||
from lostplaces.common import redirect_referer_or
|
||||
|
||||
from lostplaces.views.base_views import (
|
||||
PlaceAssetCreateView,
|
||||
@ -79,7 +80,8 @@ class PlaceTagDeleteView(IsAuthenticatedMixin, View):
|
||||
place = get_object_or_404(Place, pk=tagged_id)
|
||||
tag = get_object_or_404(Tag, pk=tag_id)
|
||||
place.tags.remove(tag)
|
||||
return redirect(reverse_lazy('place_detail', kwargs={'pk': tagged_id}))
|
||||
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': tagged_id}))
|
||||
|
||||
def FlatView(request, slug):
|
||||
if request.LANGUAGE_CODE == 'de':
|
||||
|
Loading…
Reference in New Issue
Block a user