From 68366421bfa077b4329b219a43a137dad0ac016a Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 7 Dec 2023 18:43:38 +0100 Subject: [PATCH] Added sorting and pagination to the user dashboard table --- idhub/templates/idhub/user/dashboard.html | 23 +++-------------------- idhub/user/tables.py | 13 +++++++++++++ idhub/user/views.py | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 idhub/user/tables.py diff --git a/idhub/templates/idhub/user/dashboard.html b/idhub/templates/idhub/user/dashboard.html index c13f776..22777ee 100644 --- a/idhub/templates/idhub/user/dashboard.html +++ b/idhub/templates/idhub/user/dashboard.html @@ -1,29 +1,12 @@ {% extends "idhub/base.html" %} {% load i18n %} +{% load render_table from django_tables2 %} {% block content %}

{{ subtitle }}

-
- - - - - - - - - - {% for ev in user.events.all %} - - - - - - {% endfor %} - -
{{ ev.get_type_name }}{{ ev.message }}{{ ev.created }}
-
+{% render_table table %} + {% endblock %} diff --git a/idhub/user/tables.py b/idhub/user/tables.py new file mode 100644 index 0000000..0331bd6 --- /dev/null +++ b/idhub/user/tables.py @@ -0,0 +1,13 @@ +import django_tables2 as tables +from idhub.models import Event + + +class DashboardTable(tables.Table): + type = tables.Column(verbose_name="Event") + message = tables.Column(verbose_name="Description") + created = tables.Column(verbose_name="Date") + + class Meta: + model = Event + template_name = "idhub/custom_table.html" + fields = ("type", "message", "created") diff --git a/idhub/user/views.py b/idhub/user/views.py index e6e28dc..042bc10 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -12,10 +12,14 @@ from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy from django.http import HttpResponse from django.contrib import messages +from django_tables2 import SingleTableView +from idhub.user.tables import ( + DashboardTable, +) from idhub.user.forms import ( - ProfileForm, - RequestCredentialForm, - DemandAuthorizationForm + ProfileForm, + RequestCredentialForm, + CredentialPresentationForm ) from idhub.mixins import UserView from idhub.models import DID, VerificableCredential, Event @@ -31,13 +35,20 @@ class MyWallet(UserView): section = "MyWallet" -class DashboardView(UserView, TemplateView): +class DashboardView(UserView, SingleTableView): template_name = "idhub/user/dashboard.html" + table_class = DashboardTable title = _('Dashboard') subtitle = _('Events') icon = 'bi bi-bell' section = "Home" + def get_queryset(self, **kwargs): + queryset = Event.objects.select_related('user').filter( + user=self.request.user) + + return queryset + class ProfileView(MyProfile, UpdateView): template_name = "idhub/user/profile.html"