Merge pull request #1531 from umap-project/home-highlighted
Introduce UMAP_HOME_FEED to control which maps are shown on the home page
This commit is contained in:
commit
caeb9d5b44
5 changed files with 75 additions and 5 deletions
|
@ -203,6 +203,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.
|
||||
|
|
|
@ -255,6 +255,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
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
<div class="wrapper">
|
||||
{% if maps %}
|
||||
<h2 class="section">{% blocktrans %}Get inspired, browse maps{% endblocktrans %}</h2>
|
||||
<div class="map_list row">{% include "umap/map_list.html" %}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock maincontent %}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -121,13 +121,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):
|
||||
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"):
|
||||
|
@ -143,8 +156,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,
|
||||
|
|
Loading…
Reference in a new issue