From 47dd0e50383d1fefaa4cbf19e54de06965f5bccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 9 Jan 2016 23:03:39 +0100 Subject: [PATCH 1/2] Replace PublicManager by MapManager - old Map.public behaviour replaced by Map.objects.visible(self.request) --- leaflet_storage/managers.py | 10 +++++----- leaflet_storage/models.py | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/leaflet_storage/managers.py b/leaflet_storage/managers.py index c4933b4..6f8586d 100644 --- a/leaflet_storage/managers.py +++ b/leaflet_storage/managers.py @@ -1,8 +1,8 @@ from django.contrib.gis.db import models +from django.db.models import Q +class MapManager(models.GeoManager): + def visible(self, request): + filter = Q(share_status=self.model.PUBLIC) -class PublicManager(models.GeoManager): - - def get_queryset(self): - return super(PublicManager, self).get_queryset().filter( - share_status=self.model.PUBLIC) + return self.filter(filter) diff --git a/leaflet_storage/models.py b/leaflet_storage/models.py index c5f979e..340ea68 100644 --- a/leaflet_storage/models.py +++ b/leaflet_storage/models.py @@ -13,7 +13,7 @@ from django.core.files.base import File from .fields import DictField -from .managers import PublicManager +from .managers import MapManager class NamedModel(models.Model): @@ -139,8 +139,7 @@ class Map(NamedModel): share_status = models.SmallIntegerField(choices=SHARE_STATUS, default=PUBLIC, verbose_name=_("share status")) settings = DictField(blank=True, null=True, verbose_name=_("settings")) - objects = models.GeoManager() - public = PublicManager() + objects = MapManager() def get_absolute_url(self): return reverse("map", kwargs={'slug': self.slug or "map", 'pk': self.pk}) From e1ef0e4456618e249a3c8b64a919edd74e2743b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 11 Jan 2016 22:59:48 +0100 Subject: [PATCH 2/2] MapManager.visible(): also include maps where current user is owner or editor --- leaflet_storage/managers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/leaflet_storage/managers.py b/leaflet_storage/managers.py index 6f8586d..77216f2 100644 --- a/leaflet_storage/managers.py +++ b/leaflet_storage/managers.py @@ -5,4 +5,8 @@ class MapManager(models.GeoManager): def visible(self, request): filter = Q(share_status=self.model.PUBLIC) + if request.user.is_authenticated(): + filter = filter | Q(owner=request.user) + filter = filter | Q(editors=request.user) + return self.filter(filter)