Merge pull request #1184 from umap-project/empty-search
Display latest created maps on empty search
This commit is contained in:
commit
a4759763e3
2 changed files with 28 additions and 13 deletions
|
@ -2,9 +2,9 @@
|
|||
{% load i18n %}
|
||||
{% block maincontent %}
|
||||
{% include "umap/search_bar.html" %}
|
||||
{% if q %}
|
||||
<div class="wrapper">
|
||||
<div class="map_list row">
|
||||
{% if q %}
|
||||
{% if maps %}
|
||||
<h2>
|
||||
{% blocktranslate count counter=count %}
|
||||
|
@ -17,7 +17,10 @@
|
|||
{% else %}
|
||||
<h2>{% trans "No map found." %}</h2>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<h2>{% trans "Latest created maps" %}</h2>
|
||||
{% include "umap/map_list.html" with prefix="search_map" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock maincontent %}
|
||||
|
|
|
@ -95,11 +95,9 @@ class PaginatorMixin(object):
|
|||
return qs
|
||||
|
||||
|
||||
class Home(TemplateView, PaginatorMixin):
|
||||
template_name = "umap/home.html"
|
||||
list_template_name = "umap/map_list.html"
|
||||
class PublicMapsMixin(object):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
def get_public_maps(self):
|
||||
qs = Map.public
|
||||
if (
|
||||
settings.UMAP_EXCLUDE_DEFAULT_MAPS
|
||||
|
@ -107,6 +105,17 @@ class Home(TemplateView, PaginatorMixin):
|
|||
):
|
||||
# Unsupported query type for sqlite.
|
||||
qs = qs.filter(center__distance_gt=(DEFAULT_CENTER, D(km=1)))
|
||||
maps = qs.order_by("-modified_at")
|
||||
return maps
|
||||
|
||||
|
||||
class Home(TemplateView, PublicMapsMixin, PaginatorMixin):
|
||||
template_name = "umap/home.html"
|
||||
list_template_name = "umap/map_list.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
maps = self.get_public_maps()
|
||||
|
||||
demo_map = None
|
||||
if hasattr(settings, "UMAP_DEMO_PK"):
|
||||
try:
|
||||
|
@ -114,7 +123,8 @@ class Home(TemplateView, PaginatorMixin):
|
|||
except Map.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
qs = qs.exclude(id=demo_map.pk)
|
||||
maps = maps.exclude(id=demo_map.pk)
|
||||
|
||||
showcase_map = None
|
||||
if hasattr(settings, "UMAP_SHOWCASE_PK"):
|
||||
try:
|
||||
|
@ -122,8 +132,8 @@ class Home(TemplateView, PaginatorMixin):
|
|||
except Map.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
qs = qs.exclude(id=showcase_map.pk)
|
||||
maps = qs.order_by("-modified_at")[:50]
|
||||
maps = maps.exclude(id=showcase_map.pk)
|
||||
|
||||
maps = self.paginate(maps, settings.UMAP_MAPS_PER_PAGE)
|
||||
|
||||
return {
|
||||
|
@ -206,7 +216,7 @@ class UserStars(UserMaps):
|
|||
user_stars = UserStars.as_view()
|
||||
|
||||
|
||||
class Search(TemplateView, PaginatorMixin):
|
||||
class Search(TemplateView, PublicMapsMixin, PaginatorMixin):
|
||||
template_name = "umap/search.html"
|
||||
list_template_name = "umap/map_list.html"
|
||||
|
||||
|
@ -223,6 +233,8 @@ class Search(TemplateView, PaginatorMixin):
|
|||
qs = qs.filter(share_status=Map.PUBLIC).order_by("-modified_at")
|
||||
qs_count = qs.count()
|
||||
results = self.paginate(qs)
|
||||
else:
|
||||
results = self.get_public_maps()[:settings.UMAP_MAPS_PER_SEARCH]
|
||||
kwargs.update({"maps": results, "count": qs_count, "q": q})
|
||||
return kwargs
|
||||
|
||||
|
|
Loading…
Reference in a new issue