Introduce UMAP_HOME_FEED to control which maps are shown on the home page
For now we have only three modes: - latest, which is the default and shows the last updated maps - highlighted, which shows only the map that have been starred by a least one staff member - None, which does not show any map
This commit is contained in:
parent
3e63768fc0
commit
9f377da1b2
5 changed files with 75 additions and 5 deletions
|
@ -218,6 +218,13 @@ ready for production use (no backup, etc.)
|
||||||
|
|
||||||
Link to show on the header under the "Feedback and help" label.
|
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
|
#### UMAP_MAPS_PER_PAGE
|
||||||
|
|
||||||
How many maps to show in maps list, like search or home page.
|
How many maps to show in maps list, like search or home page.
|
||||||
|
|
|
@ -249,6 +249,7 @@ DATABASES = {"default": env.db(default="postgis://localhost:5432/umap")}
|
||||||
UMAP_DEFAULT_SHARE_STATUS = None
|
UMAP_DEFAULT_SHARE_STATUS = None
|
||||||
UMAP_DEFAULT_EDIT_STATUS = None
|
UMAP_DEFAULT_EDIT_STATUS = None
|
||||||
UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False
|
UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False
|
||||||
|
UMAP_HOME_FEED = "latest"
|
||||||
|
|
||||||
UMAP_READONLY = env("UMAP_READONLY", default=False)
|
UMAP_READONLY = env("UMAP_READONLY", default=False)
|
||||||
UMAP_GZIP = True
|
UMAP_GZIP = True
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
|
{% if maps %}
|
||||||
<h2 class="section">{% blocktrans %}Get inspired, browse maps{% endblocktrans %}</h2>
|
<h2 class="section">{% blocktrans %}Get inspired, browse maps{% endblocktrans %}</h2>
|
||||||
<div class="map_list row">{% include "umap/map_list.html" %}</div>
|
<div class="map_list row">{% include "umap/map_list.html" %}</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock maincontent %}
|
{% endblock maincontent %}
|
||||||
|
|
|
@ -10,6 +10,7 @@ from django.urls import reverse
|
||||||
from django.utils.timezone import make_aware
|
from django.utils.timezone import make_aware
|
||||||
|
|
||||||
from umap import VERSION
|
from umap import VERSION
|
||||||
|
from umap.models import Map, Star
|
||||||
from umap.views import validate_url
|
from umap.views import validate_url
|
||||||
|
|
||||||
from .base import MapFactory, UserFactory
|
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
|
||||||
|
|
|
@ -119,13 +119,26 @@ class PublicMapsMixin(object):
|
||||||
maps = qs.order_by("-modified_at")
|
maps = qs.order_by("-modified_at")
|
||||||
return maps
|
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):
|
class Home(PaginatorMixin, TemplateView, PublicMapsMixin):
|
||||||
template_name = "umap/home.html"
|
template_name = "umap/home.html"
|
||||||
list_template_name = "umap/map_list.html"
|
list_template_name = "umap/map_list.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
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.get_public_maps()
|
||||||
|
maps = self.paginate(maps, settings.UMAP_MAPS_PER_PAGE)
|
||||||
|
|
||||||
demo_map = None
|
demo_map = None
|
||||||
if hasattr(settings, "UMAP_DEMO_PK"):
|
if hasattr(settings, "UMAP_DEMO_PK"):
|
||||||
|
@ -141,8 +154,6 @@ class Home(PaginatorMixin, TemplateView, PublicMapsMixin):
|
||||||
except Map.DoesNotExist:
|
except Map.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
maps = self.paginate(maps, settings.UMAP_MAPS_PER_PAGE)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"maps": maps,
|
"maps": maps,
|
||||||
"demo_map": demo_map,
|
"demo_map": demo_map,
|
||||||
|
|
Loading…
Reference in a new issue