Skip to content

Commit

Permalink
Add approver dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhprabhakaran3 committed Mar 21, 2024
1 parent 617fd36 commit f0d45e5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
53 changes: 53 additions & 0 deletions corpus/templates/virtual_expo/members/approver_dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% extends "virtual_expo/base.html" %}

{% block title %}
Approver Dashboard
{{ block.super }}
{% endblock %}

{% block content %}
{% include "virtual_expo/header.html" with text="Approver Dashboard" %}
<div class="m-10 p-5 border rounded-lg">
<h1 class="text-4xl font-bold my-2">Approval Requests</h1>
<div class="overflow-x-auto my-2">
<table class="table">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>Report Type</th>
<th>Year</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% if reports %}
{% for report in reports %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ report.title }}</td>
<td>{{ report.report_type }}</td>
<td>{{ report.year }}</td>
<td class="flex flex-row gap-4">
<a href="{% url 'virtual_expo_preview_report' report_id=report.id %}"
class="btn btn-primary">
Preview Report
</a>
<form method="post">
{% csrf_token %}
<input type="hidden" name="report_id" value="{{ report.id }}">
<button type="submit" class="btn btn-secondary px-3 py-1">Mark as Approved</button>
</form>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5" class="text-center">No approval requests yet!</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
{% endblock %}
4 changes: 4 additions & 0 deletions corpus/templates/virtual_expo/members/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ <h1 class=" my-2 text-4xl font-bold">My Reports</h1>
class="btn btn-accent px-3 py-1 rounded-full my-2">
Create a new report
</a>
<a href="{% url 'virtual_expo_members_approver_dashboard' %}"
class="btn btn-secondary px-3 py-1 rounded-full my-2">
Go to Approver Dashboard
</a>
{% if admin %}
<a href="{% url 'virtual_expo_admin_dashboard' %}"
class="btn btn-primary px-3 py-1 rounded-full my-2">
Expand Down
5 changes: 5 additions & 0 deletions corpus/virtual_expo/member_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
views.add_members,
name="virtual_expo_members_add_members",
),
path(
"approver_dashboard/",
views.approver_dashboard,
name="virtual_expo_members_approver_dashboard",
),
]
28 changes: 27 additions & 1 deletion corpus/virtual_expo/member_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

@ensure_exec_membership()
def dashboard(request):
reports = Report.objects.filter(reportmember__member=request.exec_member)
reports = Report.objects.filter(reportmember__member=request.exec_member).order_by(
"-pk"
)
admin_user = request.user.groups.filter(name="virtual_expo_admin").exists()

if request.method == "POST":
Expand Down Expand Up @@ -127,3 +129,27 @@ def add_members(request, report_id):
}

return render(request, "virtual_expo/members/add_members.html", args)


@ensure_exec_membership()
def approver_dashboard(request):
reports = Report.objects.filter(
approver=request.exec_member, approved=False
).order_by("-pk")

if request.method == "POST":
report_id = int(request.POST.get("report_id"))
report = Report.objects.get(pk=report_id)
if report.approver == request.exec_member:
report.approved = True
report.approved_at = timezone.now()
report.save()
messages.success(request, "Report marked as approved!")
return redirect("virtual_expo_members_approver_dashboard")
else:
messages.error(request, "You are not the approver for this report.")
return redirect("virtual_expo_members_approver_dashboard")

args = {"reports": reports}

return render(request, "virtual_expo/members/approver_dashboard.html", args)
2 changes: 1 addition & 1 deletion corpus/virtual_expo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def home(request):


def reports_by_year(request, year):
reports = Report.objects.filter(year=year)
reports = Report.objects.filter(year=year, approved=True).order_by("-pk")

form = ReportFilterForm(request.GET)
if form.is_valid():
Expand Down

0 comments on commit f0d45e5

Please sign in to comment.