Compare commits
No commits in common. "84b01f3a9a362d3c6aa44ff83e984d9b62e585f2" and "b60733529954753875eb0773c0dbe0fd05bb538d" have entirely different histories.
84b01f3a9a
...
b607335299
@ -85,13 +85,6 @@ class Explorer(models.Model):
|
|||||||
def get_places_eligible_to_see(self):
|
def get_places_eligible_to_see(self):
|
||||||
return Place.objects.all().filter(level__lte=self.level)
|
return Place.objects.all().filter(level__lte=self.level)
|
||||||
|
|
||||||
def is_eligible_to_see(self, place):
|
|
||||||
return (
|
|
||||||
self.user.is_superuser or
|
|
||||||
place.submitted_by == self or
|
|
||||||
place in self.get_places_eligible_to_see()
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user.username
|
return self.user.username
|
||||||
|
|
||||||
|
@ -27,8 +27,7 @@ class IsAuthenticatedMixin(LoginRequiredMixin, View):
|
|||||||
permission_denied_message = _('Please login to proceed')
|
permission_denied_message = _('Please login to proceed')
|
||||||
|
|
||||||
def handle_no_permission(self):
|
def handle_no_permission(self):
|
||||||
if not self.request.user.is_authenticated:
|
messages.error(self.request, self.permission_denied_message)
|
||||||
messages.error(self.request, self.permission_denied_message)
|
|
||||||
return super().handle_no_permission()
|
return super().handle_no_permission()
|
||||||
|
|
||||||
class IsPlaceSubmitterMixin(UserPassesTestMixin, View):
|
class IsPlaceSubmitterMixin(UserPassesTestMixin, View):
|
||||||
@ -62,23 +61,6 @@ class IsPlaceSubmitterMixin(UserPassesTestMixin, View):
|
|||||||
messages.error(self.request, self.place_submitter_error_message)
|
messages.error(self.request, self.place_submitter_error_message)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class IsEligibleToSeePlaceMixin(UserPassesTestMixin):
|
|
||||||
not_eligible_to_see_message = None
|
|
||||||
|
|
||||||
def get_place(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_func(self):
|
|
||||||
if not hasattr(self.request, 'user'):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if self.request.user.explorer.is_eligible_to_see(self.get_place()):
|
|
||||||
return True
|
|
||||||
|
|
||||||
if self.not_eligible_to_see_message:
|
|
||||||
messages.error(self.request, self.not_eligible_to_see_message)
|
|
||||||
return False
|
|
||||||
|
|
||||||
class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView):
|
class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
Abstract View for creating a place asset (i.e. PlaceImage)
|
Abstract View for creating a place asset (i.e. PlaceImage)
|
||||||
|
@ -18,8 +18,7 @@ from lostplaces.models import Place, PlaceImage
|
|||||||
from lostplaces.views.base_views import (
|
from lostplaces.views.base_views import (
|
||||||
IsAuthenticatedMixin,
|
IsAuthenticatedMixin,
|
||||||
IsPlaceSubmitterMixin,
|
IsPlaceSubmitterMixin,
|
||||||
LevelCapPlaceListView,
|
LevelCapPlaceListView
|
||||||
IsEligibleToSeePlaceMixin
|
|
||||||
)
|
)
|
||||||
from lostplaces.views.place_image_views import MultiplePlaceImageUploadMixin
|
from lostplaces.views.place_image_views import MultiplePlaceImageUploadMixin
|
||||||
from lostplaces.forms import PlaceForm, PlaceImageForm, TagSubmitForm
|
from lostplaces.forms import PlaceForm, PlaceImageForm, TagSubmitForm
|
||||||
@ -40,15 +39,9 @@ class PlaceListView(IsAuthenticatedMixin, LevelCapPlaceListView):
|
|||||||
}
|
}
|
||||||
return context
|
return context
|
||||||
|
|
||||||
class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
class PlaceDetailView(IsAuthenticatedMixin, View):
|
||||||
not_eligible_to_see_message = _('You\'r not allowed to see this place')
|
|
||||||
|
|
||||||
def get_place(self):
|
|
||||||
return get_object_or_404(Place, pk=self.kwargs['pk'])
|
|
||||||
|
|
||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
place = self.get_place()
|
place = get_object_or_404(Place, pk=pk)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'place': place,
|
'place': place,
|
||||||
'mapping_config': {
|
'mapping_config': {
|
||||||
@ -138,14 +131,10 @@ class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):
|
|||||||
def get_place(self):
|
def get_place(self):
|
||||||
return self.get_object()
|
return self.get_object()
|
||||||
|
|
||||||
class PlaceFavoriteView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
class PlaceFavoriteView(IsAuthenticatedMixin, View):
|
||||||
not_eligible_to_see_message = _('You\'r not allowed to favorite this place')
|
|
||||||
|
|
||||||
def get_place(self):
|
|
||||||
return get_object_or_404(Place, pk=self.kwargs['place_id'])
|
|
||||||
|
|
||||||
def get(self, request, place_id):
|
def get(self, request, place_id):
|
||||||
place = self.get_place()
|
place = get_object_or_404(Place, id=place_id)
|
||||||
if request.user is not None:
|
if request.user is not None:
|
||||||
request.user.explorer.favorite_places.add(place)
|
request.user.explorer.favorite_places.add(place)
|
||||||
request.user.explorer.save()
|
request.user.explorer.save()
|
||||||
@ -162,14 +151,10 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View):
|
|||||||
|
|
||||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))
|
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))
|
||||||
|
|
||||||
class PlaceVisitCreateView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
|
class PlaceVisitCreateView(IsAuthenticatedMixin, View):
|
||||||
not_eligible_to_see_message = _('You\'r not allowed to visit this place :P (Now please stop trying out URL\'s)')
|
|
||||||
|
|
||||||
def get_place(self):
|
|
||||||
return get_object_or_404(Place, pk=self.kwargs['place_id'])
|
|
||||||
|
|
||||||
def get(self, request, place_id):
|
def get(self, request, place_id):
|
||||||
place = self.get_place()
|
place = get_object_or_404(Place, id=place_id)
|
||||||
if request.user is not None:
|
if request.user is not None:
|
||||||
request.user.explorer.visited_places.add(place)
|
request.user.explorer.visited_places.add(place)
|
||||||
request.user.explorer.save()
|
request.user.explorer.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user