diff --git a/docs/config/settings.md b/docs/config/settings.md
index f9995078..9c8c0666 100644
--- a/docs/config/settings.md
+++ b/docs/config/settings.md
@@ -218,6 +218,13 @@ ready for production use (no backup, etc.)
Link to show on the header under the "Feedback and help" label.
+#### UMAP_HOME_FEED
+
+Which feed to display on the home page. Three valid values:
+- `"latest"`, which shows the latest maps (default)
+- `"highlighted"`, which shows the maps that have been starred by a staff member
+- `None`, which does not show any map on the home page
+
#### UMAP_MAPS_PER_PAGE
How many maps to show in maps list, like search or home page.
diff --git a/umap/settings/base.py b/umap/settings/base.py
index 7437f416..76b1ad15 100644
--- a/umap/settings/base.py
+++ b/umap/settings/base.py
@@ -249,6 +249,7 @@ DATABASES = {"default": env.db(default="postgis://localhost:5432/umap")}
UMAP_DEFAULT_SHARE_STATUS = None
UMAP_DEFAULT_EDIT_STATUS = None
UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False
+UMAP_HOME_FEED = "latest"
UMAP_READONLY = env("UMAP_READONLY", default=False)
UMAP_GZIP = True
diff --git a/umap/templates/umap/home.html b/umap/templates/umap/home.html
index cfd9fce0..47b2b880 100644
--- a/umap/templates/umap/home.html
+++ b/umap/templates/umap/home.html
@@ -10,7 +10,9 @@
{% endif %}
-
{% blocktrans %}Get inspired, browse maps{% endblocktrans %}
-
{% include "umap/map_list.html" %}
+ {% if maps %}
+
{% blocktrans %}Get inspired, browse maps{% endblocktrans %}
+
{% include "umap/map_list.html" %}
+ {% endif %}
{% endblock maincontent %}
diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py
index 1c865357..7055cd5d 100644
--- a/umap/tests/test_views.py
+++ b/umap/tests/test_views.py
@@ -10,6 +10,7 @@ from django.urls import reverse
from django.utils.timezone import make_aware
from umap import VERSION
+from umap.models import Map, Star
from umap.views import validate_url
from .base import MapFactory, UserFactory
@@ -391,3 +392,51 @@ def test_webmanifest(client):
},
]
}
+
+
+@pytest.mark.django_db
+def test_home_feed(client, settings, user, tilelayer):
+ settings.UMAP_HOME_FEED = "latest"
+ staff = UserFactory(username="Staff", is_staff=True)
+ starred = MapFactory(
+ owner=user, name="A public map starred by staff", share_status=Map.PUBLIC
+ )
+ MapFactory(
+ owner=user, name="A public map not starred by staff", share_status=Map.PUBLIC
+ )
+ non_staff = MapFactory(
+ owner=user, name="A public map starred by non staff", share_status=Map.PUBLIC
+ )
+ private = MapFactory(
+ owner=user, name="A private map starred by staff", share_status=Map.PRIVATE
+ )
+ reserved = MapFactory(
+ owner=user, name="A reserved map starred by staff", share_status=Map.OPEN
+ )
+ Star.objects.create(by=staff, map=starred)
+ Star.objects.create(by=staff, map=private)
+ Star.objects.create(by=staff, map=reserved)
+ Star.objects.create(by=user, map=non_staff)
+ response = client.get(reverse("home"))
+ content = response.content.decode()
+ assert "A public map starred by staff" in content
+ assert "A public map not starred by staff" in content
+ assert "A public map starred by non staff" in content
+ assert "A private map starred by staff" not in content
+ assert "A reserved map starred by staff" not in content
+ settings.UMAP_HOME_FEED = "highlighted"
+ response = client.get(reverse("home"))
+ content = response.content.decode()
+ assert "A public map starred by staff" in content
+ assert "A public map not starred by staff" not in content
+ assert "A public map starred by non staff" not in content
+ assert "A private map starred by staff" not in content
+ assert "A reserved map starred by staff" not in content
+ settings.UMAP_HOME_FEED = None
+ response = client.get(reverse("home"))
+ content = response.content.decode()
+ assert "A public map starred by staff" not in content
+ assert "A public map not starred by staff" not in content
+ assert "A public map starred by non staff" not in content
+ assert "A private map starred by staff" not in content
+ assert "A reserved map starred by staff" not in content
diff --git a/umap/views.py b/umap/views.py
index 1032bdf0..4f4aff50 100644
--- a/umap/views.py
+++ b/umap/views.py
@@ -119,13 +119,26 @@ class PublicMapsMixin(object):
maps = qs.order_by("-modified_at")
return maps
+ def get_highlighted_maps(self):
+ staff = User.objects.filter(is_staff=True)
+ stars = Star.objects.filter(by__in=staff).values("map")
+ qs = Map.public.filter(pk__in=stars)
+ maps = qs.order_by("-modified_at")
+ return maps
+
class Home(PaginatorMixin, TemplateView, PublicMapsMixin):
template_name = "umap/home.html"
list_template_name = "umap/map_list.html"
def get_context_data(self, **kwargs):
- maps = self.get_public_maps()
+ if settings.UMAP_HOME_FEED is None:
+ maps = []
+ elif settings.UMAP_HOME_FEED == "highlighted":
+ maps = self.get_highlighted_maps()
+ else:
+ maps = self.get_public_maps()
+ maps = self.paginate(maps, settings.UMAP_MAPS_PER_PAGE)
demo_map = None
if hasattr(settings, "UMAP_DEMO_PK"):
@@ -141,8 +154,6 @@ class Home(PaginatorMixin, TemplateView, PublicMapsMixin):
except Map.DoesNotExist:
pass
- maps = self.paginate(maps, settings.UMAP_MAPS_PER_PAGE)
-
return {
"maps": maps,
"demo_map": demo_map,