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" %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block content %}
<h3>
<i class="{{ icon }}"></i>
{{ subtitle }}
</h3>
<div class="table-responsive">
<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>
{% render_table table %}
{% 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.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"