Added sorting and pagination to the user dashboard table

This commit is contained in:
Elijah 2023-12-07 18:43:38 +01:00
parent 8316e6d5a0
commit 68366421bf
3 changed files with 31 additions and 24 deletions

View File

@ -1,29 +1,12 @@
{% extends "idhub/base.html" %} {% extends "idhub/base.html" %}
{% load i18n %} {% load i18n %}
{% load render_table from django_tables2 %}
{% block content %} {% block content %}
<h3> <h3>
<i class="{{ icon }}"></i> <i class="{{ icon }}"></i>
{{ subtitle }} {{ subtitle }}
</h3> </h3>
<div class="table-responsive"> {% render_table table %}
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Type' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Date' %}</button></th>
</tr>
</thead>
<tbody>
{% for ev in user.events.all %}
<tr>
<td>{{ ev.get_type_name }}</td>
<td>{{ ev.message }}</td>
<td>{{ ev.created }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %} {% endblock %}

13
idhub/user/tables.py Normal file
View File

@ -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")

View File

@ -12,10 +12,14 @@ from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.http import HttpResponse from django.http import HttpResponse
from django.contrib import messages from django.contrib import messages
from django_tables2 import SingleTableView
from idhub.user.tables import (
DashboardTable,
)
from idhub.user.forms import ( from idhub.user.forms import (
ProfileForm, ProfileForm,
RequestCredentialForm, RequestCredentialForm,
DemandAuthorizationForm CredentialPresentationForm
) )
from idhub.mixins import UserView from idhub.mixins import UserView
from idhub.models import DID, VerificableCredential, Event from idhub.models import DID, VerificableCredential, Event
@ -31,13 +35,20 @@ class MyWallet(UserView):
section = "MyWallet" section = "MyWallet"
class DashboardView(UserView, TemplateView): class DashboardView(UserView, SingleTableView):
template_name = "idhub/user/dashboard.html" template_name = "idhub/user/dashboard.html"
table_class = DashboardTable
title = _('Dashboard') title = _('Dashboard')
subtitle = _('Events') subtitle = _('Events')
icon = 'bi bi-bell' icon = 'bi bi-bell'
section = "Home" section = "Home"
def get_queryset(self, **kwargs):
queryset = Event.objects.select_related('user').filter(
user=self.request.user)
return queryset
class ProfileView(MyProfile, UpdateView): class ProfileView(MyProfile, UpdateView):
template_name = "idhub/user/profile.html" template_name = "idhub/user/profile.html"