#42 Checking ListView for Levels
This commit is contained in:
parent
b1cd8fd0cc
commit
b607335299
@ -82,6 +82,9 @@ class Explorer(models.Model):
|
||||
choices=EXPLORER_LEVELS
|
||||
)
|
||||
|
||||
def get_places_eligible_to_see(self):
|
||||
return Place.objects.all().filter(level__lte=self.level)
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
from django.views import View
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.views.generic import ListView
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
|
||||
@ -113,3 +114,10 @@ class PlaceAssetDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SingleOb
|
||||
self.get_object().delete()
|
||||
messages.success(self.request, self.success_message)
|
||||
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place_id}))
|
||||
|
||||
|
||||
class LevelCapPlaceListView(ListView):
|
||||
model = Place
|
||||
|
||||
def get_queryset(self):
|
||||
return self.request.user.explorer.get_places_eligible_to_see()
|
@ -6,7 +6,6 @@ from django.db.models.functions import Lower
|
||||
from django.views import View
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.views.generic import ListView
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
@ -16,16 +15,19 @@ from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy, reverse
|
||||
|
||||
from lostplaces.models import Place, PlaceImage
|
||||
from lostplaces.views.base_views import IsAuthenticatedMixin, IsPlaceSubmitterMixin
|
||||
from lostplaces.views.base_views import (
|
||||
IsAuthenticatedMixin,
|
||||
IsPlaceSubmitterMixin,
|
||||
LevelCapPlaceListView
|
||||
)
|
||||
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
|
||||
|
||||
class PlaceListView(IsAuthenticatedMixin, ListView):
|
||||
class PlaceListView(IsAuthenticatedMixin, LevelCapPlaceListView):
|
||||
paginate_by = 5
|
||||
model = Place
|
||||
template_name = 'place/place_list.html'
|
||||
ordering = [Lower('name')]
|
||||
|
||||
|
@ -31,7 +31,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
|
||||
|
||||
class HomeView(IsAuthenticatedMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_list = Place.objects.all().order_by('-submitted_when')[:10]
|
||||
place_list = request.user.explorer.get_places_eligible_to_see()
|
||||
context = {
|
||||
'place_list': place_list,
|
||||
'mapping_config': {
|
||||
|
Loading…
Reference in New Issue
Block a user