diff --git a/REUSE.toml b/REUSE.toml index 910cfafb0..4c49b6fbc 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -846,7 +846,7 @@ SPDX-FileCopyrightText = [ ] [[annotations]] -path = "login/templates/login/partials/user_partial_tables.html" +path = "login/templates/login/partials/group_component_invite_user.html" precedence = "override" SPDX-License-Identifier = "AGPL-3.0-or-later" SPDX-FileCopyrightText = [ @@ -854,11 +854,11 @@ SPDX-FileCopyrightText = [ ] [[annotations]] -path = "login/templates/login/partials/group_component_invite_user.html" +path = "login/templates/login/partials/tables_sections.html" precedence = "override" SPDX-License-Identifier = "AGPL-3.0-or-later" SPDX-FileCopyrightText = [ - "2024 Jonas Huber © Reiner Lemoine Institut", + "2025 Vismaya Jochem © Reiner Lemoine Institut", ] [[annotations]] diff --git a/login/templates/login/partials/tables_sections.html b/login/templates/login/partials/tables_sections.html new file mode 100644 index 000000000..82eeb5d3a --- /dev/null +++ b/login/templates/login/partials/tables_sections.html @@ -0,0 +1,397 @@ + +
+

Published tables

+ {% if published_tables_page %} +
+
+ {% for table in published_tables_page %} + {% with license_status=table.validate_open_data_license %} +
+
+
+
+ {% for topic in table.topics.all %} +
+ + + + + {{ topic.name }} +
+ {% endfor %} + {% if license_status.status %} +
+ + + + License +
+ {% else %} +
+ + + + License check failed +
+ {% endif %} +
+
+ +
+
+ + {% comment %} + {% if table.is_reviewed %} +
+ + + + Reviewed +
+
+ + + +
+ {% else %} +
+ Not reviewed +
+ {% endif %} + {% endcomment %} + +
+ + +
+ {% if not license_status.status %} +
+
+ + + + +
+
+ Potential publishing without an open license. +
+
+

+ +

+
+ License check failed because of: + {{ license_status.error }} +
+
+ Please use a SPDX license identifier. +
+
+ Please revisit your metadata and check the license + information. Do not publish data that does not hold an + open license. +
+
+
+ {% endif %} +
+
+ {% endwith %} + {% endfor %} +
+
+ + {% else %} + You have never published a table. + {% endif %} +
+ +
+

Draft tables

+ {% if draft_tables_page.object_list %} +
+
+ {% for table in draft_tables_page %} + {% with license_status=table.validate_open_data_license %} +
+
+
+
+ {% for topic in table.topics.all %} +
+ + + + + {{ topic.name }} +
+ {% endfor %} + {% if license_status.status %} +
+ + + + License +
+ {% else %} +
+ + + + License check failed +
+ {% endif %} +
+
+ {% if license_status.status %} + + {% else %} + + {% endif %} + +
+
+ + {% comment %} + {% if table.is_reviewed %} +
+ + + + Reviewed +
+
+
+ + +
+ {% else %} +
+ Not reviewed +
+ {% endif %} + {% endcomment %} + +
+ + +
+ {% if not license_status.status %} +
+
+ + + + +
+
+ {{ table.license_status.error }} +
+ +
+ {% endif %} +
+
+ {% endwith %} + {% endfor %} +
+
+ + {% else %} + +
+
+
+ No table has been uploaded yet! +
+
+ + + + + +
+ + +
+
+ +{% endif %} +
diff --git a/login/templates/login/partials/user_partial_tables.html b/login/templates/login/partials/user_partial_tables.html deleted file mode 100644 index 1f49f7d87..000000000 --- a/login/templates/login/partials/user_partial_tables.html +++ /dev/null @@ -1,73 +0,0 @@ -{% load compress %} -{% load django_bootstrap5 %} -{% load static %} -{% if profile_user == request.user %} -
-
-
-

Published

-
-
- {% for table in published_tables %} -
-
-
-
{{ table.name }}
- View Table -
-
-
- {% endfor %} -
-
-

Draft

-
-
- {% for table in draft_tables %} -
-
-
-
{{ table.name }}
- View Table - {% if table.is_reviewed and not table.is_publish %} - - - {% endif %} -
-
-
- {% endfor %} -
-
- -
-
-
-{% endif %} -{% comment "@Daryna what is this used for?" %} - -{% endcomment %} - diff --git a/login/templates/login/user_tables.html b/login/templates/login/user_tables.html index 374cb5629..51fe24072 100644 --- a/login/templates/login/user_tables.html +++ b/login/templates/login/user_tables.html @@ -5,402 +5,27 @@ {% block main-content-body %} {% if profile_user == request.user %} {% include "login/user_nav.html" %} - -
-

Published tables

- {% if published_tables_page %} -
-
- {% for table in published_tables_page %} - {% with license_status=table.validate_open_data_license %} -
-
-
-
- {% for topic in table.topics.all %} -
- - - - - {{ topic.name }} -
- {% endfor %} - {% if license_status.status %} -
- - - - License -
- {% else %} -
- - - - License check failed -
- {% endif %} -
-
- -
-
- - {% comment %} - {% if table.is_reviewed %} -
- - - - Reviewed -
-
- - - -
- {% else %} -
- Not reviewed -
- {% endif %} - {% endcomment %} - -
- - -
- {% if not license_status.status %} -
-
- - - - -
-
- Potential publishing without an open license. -
-
-

- -

-
- License check failed because of: - {{ license_status.error }} -
-
- Please use a SPDX license identifier. -
-
- Please revisit your metadata and check the license - information. Do not publish data that does not hold an - open license. -
-
-
- {% endif %} -
-
- {% endwith %} - {% endfor %} -
-
- - {% else %} - You have never published a table. - {% endif %} -
- -
-

Draft tables

- {% if draft_tables_page.object_list %} -
-
- {% for table in draft_tables_page %} - {% with license_status=table.validate_open_data_license %} -
-
-
-
- {% for topic in table.topics.all %} -
- - - - - {{ topic.name }} -
- {% endfor %} - {% if license_status.status %} -
- - - - License -
- {% else %} -
- - - - License check failed -
- {% endif %} -
-
- {% if license_status.status %} - - {% else %} - - {% endif %} - -
-
- - {% comment %} - {% if table.is_reviewed %} -
- - - - Reviewed -
-
-
- - -
- {% else %} -
- Not reviewed -
- {% endif %} - {% endcomment %} - -
- - -
- {% if not license_status.status %} -
-
- - - - -
-
- {{ table.license_status.error }} -
- -
- {% endif %} -
-
- {% endwith %} - {% endfor %} -
-
- - {% else %} - -
-
-
- No table has been uploaded yet! -
-
- - - - - -
- - -
-
- {% endif %} -
+ + +
+ {% include "login/partials/tables_sections.html" %} +
{% endif %} @@ -474,8 +99,8 @@

Draft tables

// Refresh the page after any htmx request ... keep until partials are // implemented for the draft & published tables document.addEventListener("htmx:afterRequest", function (event) { - if (event.detail.successful) { - window.location.reload(); + if (event.detail.successful && event.detail.elt.id !== 'table-search') { + window.location.reload(); } }); diff --git a/login/views.py b/login/views.py index 99203b38d..8876721c3 100644 --- a/login/views.py +++ b/login/views.py @@ -22,7 +22,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.core.exceptions import PermissionDenied from django.core.paginator import Paginator -from django.db.models import F +from django.db.models import F, Q from django.http import ( HttpResponse, HttpResponseForbidden, @@ -58,10 +58,11 @@ class TablesView(View): - @method_decorator(never_cache) - def get(self, request, user_id): - user = get_object_or_404(OepUser, pk=user_id) + + def _get_filtered_tables(self, user, search_query=""): + """Return filtered querysets for draft and published tables.""" tables_set = user.get_tables_queryset(min_permission_level=WRITE_PERM) + draft_tables = tables_set.filter(is_publish=False).order_by( F("date_updated").desc(nulls_last=True), "human_readable_name" ) @@ -69,11 +70,28 @@ def get(self, request, user_id): F("date_updated").desc(nulls_last=True), "human_readable_name" ) + if search_query: + + q_filter = Q(name__icontains=search_query) | Q( + human_readable_name__icontains=search_query + ) + draft_tables = draft_tables.filter(q_filter) + published_tables = published_tables.filter(q_filter) + + return draft_tables, published_tables + + @method_decorator(never_cache) + def get(self, request, user_id): + user = get_object_or_404(OepUser, pk=user_id) + search_query = request.GET.get("search", "").strip() + has_search_param = "search" in request.GET + + draft_tables, published_tables = self._get_filtered_tables(user, search_query) + # Paginate tables published_paginator = Paginator(published_tables, ITEMS_PER_PAGE) draft_paginator = Paginator(draft_tables, ITEMS_PER_PAGE) - # Check if the request contains a page published_page = request.GET.get("published_page", 1) published_page_obj = published_paginator.get_page(published_page) @@ -87,12 +105,15 @@ def get(self, request, user_id): "topics": [t.name for t in Topic.objects.all()], "draft_page": draft_page, "published_page": published_page, + "search_query": search_query, } - # TODO: Fix this is_ajax as it is outdated according to django documentation ... - # provide better api endpoint for http requests via HTMX - if "HX-Request" in request.headers: - return render(request, "login/partials/user_partial_tables.html", context) + if "HX-Request" in request.headers and not has_search_param: + return render( + request, + "login/partials/tables_sections.html", + context, + ) else: return render(request, "login/user_tables.html", context) diff --git a/script/reuse/.reuse/dep5 b/script/reuse/.reuse/dep5 index d2b1c8d32..670a36e6e 100644 --- a/script/reuse/.reuse/dep5 +++ b/script/reuse/.reuse/dep5 @@ -502,10 +502,6 @@ Files: login/templates/login/partials/group_component_form_edit.html Copyright: Jonas Huber License: MIT -Files: login/templates/login/partials/user_partial_tables.html -Copyright: Jonas Huber -License: MIT - Files: login/templates/login/partials/group_component_invite_user.html Copyright: Jonas Huber License: MIT diff --git a/versions/changelogs/current.md b/versions/changelogs/current.md index 599d6500c..5045b37fe 100644 --- a/versions/changelogs/current.md +++ b/versions/changelogs/current.md @@ -10,9 +10,15 @@ SPDX-License-Identifier: CC0-1.0 ## Changes -## Features +- Create tables_sections.html, delete user_partial_tables + [(#2248)](https://github.com/OpenEnergyPlatform/oeplatform/pull/2248) -## Bugs +### Features + +- Build search field to search in the user's tables + [(#2248)](https://github.com/OpenEnergyPlatform/oeplatform/pull/2248) + +### Bugs ## Documentation updates