summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--statistics_app/templates/statistics_app/workshop_public_stats.html25
-rw-r--r--statistics_app/views.py29
2 files changed, 45 insertions, 9 deletions
diff --git a/statistics_app/templates/statistics_app/workshop_public_stats.html b/statistics_app/templates/statistics_app/workshop_public_stats.html
index c6753f8..ad55858 100644
--- a/statistics_app/templates/statistics_app/workshop_public_stats.html
+++ b/statistics_app/templates/statistics_app/workshop_public_stats.html
@@ -8,7 +8,18 @@
<div class="col-md-3">
<form method="GET">
<div class="card">
- <div class="card-header"><h3><u>Filters</u></h3></div>
+ <div class="card-header">
+ <div class="row">
+ <div class="col-md-8">
+ <h3><u>Filters</u></h3>
+ </div>
+ <div class="col-md-4">
+ <a href="{% url 'statistics_app:public' %}" class="btn btn-outline-info">
+ <i class="fa fa-times"></i>&nbsp;Clear
+ </a>
+ </div>
+ </div>
+ </div>
<div class="card-body">
<div>From date: {{form.from_date}}</div>
<div>To date: {{form.to_date}}</div>
@@ -20,15 +31,15 @@
{% endif %}
<br>
<div class="row justify-content-center">
- <div class="col-md-5">
+ <div class="col-md-4">
<button type="submit" class="btn btn-success">
<i class="fa fa-eye"></i>&nbsp;View
</button>
</div>
- <div class="col-md-4">
- <a href="{% url 'statistics_app:public' %}" class="btn btn-info">
- <i class="fa fa-times"></i>&nbsp;Clear
- </a>
+ <div class="col-md-6">
+ <button type="submit" class="btn btn-info" name="download" value="download">
+ <i class="fa fa-download"></i>&nbsp;Download
+ </button>
</div>
</div>
</div>
@@ -69,7 +80,7 @@
<td>{{ forloop.counter0|add:objects.start_index}}</td>
<td>{{ workshop.coordinator.get_full_name | capfirst }}</td>
<td>{{ workshop.coordinator.profile.institute | capfirst }}</td>
- <td>{{ workshop.instructor.get_full_name }}</td>
+ <td>{{ workshop.instructor.get_full_name | capfirst }}</td>
<td>{{ workshop.workshop_type.name }}</td>
<td>{{ workshop.date | date}}</td>
</tr>
diff --git a/statistics_app/views.py b/statistics_app/views.py
index 65b4744..3c9fcae 100644
--- a/statistics_app/views.py
+++ b/statistics_app/views.py
@@ -1,5 +1,6 @@
# Python Imports
import datetime as dt
+import pandas as pd
# Django Imports
from django.template.loader import get_template
@@ -10,10 +11,12 @@ from django.core.paginator import Paginator
from django.shortcuts import render, redirect
from django.urls import reverse
from django.utils import timezone
+from django.http import HttpResponse
# Local Imports
from workshop_app.models import (
- Profile, User, has_profile, Workshop, WorkshopType, Testimonial
+ Profile, User, has_profile, Workshop, WorkshopType, Testimonial,
+ states
)
from teams.models import Team
from .forms import FilterForm
@@ -40,7 +43,9 @@ def workshop_public_stats(request):
workshoptype = request.GET.get('workshop_type')
show_workshops = request.GET.get('show_workshops')
sort = request.GET.get('sort')
- if from_date is not None or to_date is not None:
+ download = request.GET.get('download')
+
+ if from_date and to_date:
form = FilterForm(
start=from_date, end=to_date, state=state, type=workshoptype,
show_workshops=show_workshops, sort=sort
@@ -63,6 +68,26 @@ def workshop_public_stats(request):
workshops = workshops.filter(instructor_id=user.id)
else:
workshops = workshops.filter(coordinator_id=user.id)
+ if download:
+ data = workshops.values(
+ "workshop_type__name", "coordinator__first_name",
+ "coordinator__last_name", "instructor__first_name",
+ "instructor__last_name", "coordinator__profile__state",
+ "date", "status"
+ )
+ df = pd.DataFrame(data)
+ if not df.empty:
+ df.status.replace(
+ [0, 1, 2], ['Pending', 'Success', 'Reject'], inplace=True
+ )
+ codes, states = list(zip(*states))
+ df.coordinator__profile__state.replace(codes, states, inplace=True)
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = f'attachment; filename=statistics.csv'
+ output_file = df.to_csv(response, index=False)
+ return response
+ else:
+ messages.add_message(request, messages.WARNING, "No data found")
ws_states, ws_count = Workshop.objects.get_workshops_by_state(workshops)
ws_type, ws_type_count = Workshop.objects.get_workshops_by_type(workshops)
paginator = Paginator(workshops, 30)