diff --git a/umap/templates/umap/user_dashboard.html b/umap/templates/umap/user_dashboard.html
new file mode 100644
index 00000000..d8d4df2d
--- /dev/null
+++ b/umap/templates/umap/user_dashboard.html
@@ -0,0 +1,20 @@
+{% extends "umap/content.html" %}
+{% load i18n %}
+{% block maincontent %}
+ {% trans "Search my maps" as placeholder %}
+
+
{% blocktrans %}My dashboard{% endblocktrans %}
+ {% include "umap/search_bar.html" with action=request.get_full_path placeholder=placeholder %}
+
+
+
+ {% if maps %}
+ {% include "umap/map_table.html" %}
+ {% else %}
+
+ {% endif %}
+
+
+{% endblock maincontent %}
diff --git a/umap/urls.py b/umap/urls.py
index f770425a..10e111dc 100644
--- a/umap/urls.py
+++ b/umap/urls.py
@@ -98,6 +98,11 @@ i18n_urls += decorated_patterns(
views.ToggleMapStarStatus.as_view(),
name="map_star",
),
+ re_path(
+ r"^me$",
+ views.user_dashboard,
+ name="user_dashboard",
+ ),
)
map_urls = [
re_path(
diff --git a/umap/views.py b/umap/views.py
index 9a956961..da8eccf8 100644
--- a/umap/views.py
+++ b/umap/views.py
@@ -96,7 +96,6 @@ class PaginatorMixin(object):
class PublicMapsMixin(object):
-
def get_public_maps(self):
qs = Map.public
if (
@@ -216,26 +215,32 @@ class UserStars(UserMaps):
user_stars = UserStars.as_view()
-class Search(TemplateView, PublicMapsMixin, PaginatorMixin):
- template_name = "umap/search.html"
- list_template_name = "umap/map_list.html"
-
- def get_context_data(self, **kwargs):
+class SearchMixin:
+ def get_search_queryset(self, **kwargs):
q = self.request.GET.get("q")
- qs_count = 0
- results = []
if q:
vector = SearchVector("name", config=settings.UMAP_SEARCH_CONFIGURATION)
query = SearchQuery(
q, config=settings.UMAP_SEARCH_CONFIGURATION, search_type="websearch"
)
- qs = Map.objects.annotate(search=vector).filter(search=query)
+ return Map.objects.annotate(search=vector).filter(search=query)
+
+
+class Search(TemplateView, PublicMapsMixin, PaginatorMixin, SearchMixin):
+ template_name = "umap/search.html"
+ list_template_name = "umap/map_list.html"
+
+ def get_context_data(self, **kwargs):
+ qs = self.get_search_queryset()
+ qs_count = 0
+ results = []
+ if qs:
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})
+ results = self.get_public_maps()[: settings.UMAP_MAPS_PER_SEARCH]
+ kwargs.update({"maps": results, "count": qs_count})
return kwargs
def get_template_names(self):
@@ -255,6 +260,28 @@ class Search(TemplateView, PublicMapsMixin, PaginatorMixin):
search = Search.as_view()
+class UserDashboard(DetailView, PaginatorMixin, SearchMixin):
+ model = User
+ template_name = "umap/user_dashboard.html"
+
+ def get_object(self):
+ return self.get_queryset().get(pk=self.request.user.pk)
+
+ def get_maps(self):
+ qs = self.get_search_queryset() or Map.objects.all()
+ qs = qs.filter(Q(owner=self.object) | Q(editors=self.object))
+ return qs.order_by("-modified_at")
+
+ def get_context_data(self, **kwargs):
+ kwargs.update(
+ {"maps": self.paginate(self.get_maps(), settings.UMAP_MAPS_PER_PAGE_OWNER)}
+ )
+ return super().get_context_data(**kwargs)
+
+
+user_dashboard = UserDashboard.as_view()
+
+
class MapsShowCase(View):
def get(self, *args, **kwargs):
maps = Map.public.filter(center__distance_gt=(DEFAULT_CENTER, D(km=1)))
@@ -436,7 +463,7 @@ class MapDetailMixin:
properties["user"] = {
"id": user.pk,
"name": str(user),
- "url": user.get_url(),
+ "url": reverse("user_dashboard"),
}
map_settings = self.get_geojson()
if "properties" not in map_settings: