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