Skip to content

Commit

Permalink
update counselor dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
TareqMonwer committed Nov 4, 2024
1 parent 838a569 commit 07f77d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
18 changes: 5 additions & 13 deletions django_school_management/students/views/report_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import calendar
import datetime

from django.db.models.functions import ExtractMonth
Expand Down Expand Up @@ -65,29 +66,20 @@ def counsel_monthly_report(request, response_type='html', date_param=None):
# to generate last months report.
if date_param:
date = date_param.date()
# Used for filtering qs
report_month = date.month
# Used to return reporting month name
report_month_dt = date
else:
date = datetime.date.today()
first_day_of_month = date.replace(day=1)
# Used to return reporting month name
report_month_dt = first_day_of_month - datetime.timedelta(days=1)
# Used for filtering qs
report_month = report_month_dt.month

total_applications = AdmissionStudent.objects.order_by('-created').filter(
created__year=date.year,
created__month=report_month)
created__month=date.month)

# Online/offline applications
online_applications = total_applications.filter(application_type='1') # 1 is online
offline_applications = total_applications.filter(application_type='2')

total_admission = AdmissionStudent.objects.filter(admitted=True).filter(
created__year=date.year,
created__month=report_month)
created__month=date.month)

# Online/offline admissions
total_admission_online = total_admission.filter(application_type='1') # 1 is online
Expand All @@ -107,7 +99,7 @@ def counsel_monthly_report(request, response_type='html', date_param=None):

ctx = {
'date': datetime.date.today(),
'report_month': report_month_dt.strftime('%B'), # Format full month name (July)
'report_month': date.strftime('%B'), # Format full month name (July)
'total_applications': total_applications.count(),
'total_admissions': total_admission.count(),
'online_applications': online_applications.count(),
Expand All @@ -124,7 +116,7 @@ def counsel_monthly_report(request, response_type='html', date_param=None):
return JsonResponse({'data': ctx})
elif response_type.lower() == 'pdf':
template = get_template('students/reports/counsel_monthly_report.html')
html = template.render(ctx)
template.render(ctx)
pdf = render_to_pdf(
'students/reports/counsel_monthly_report.html', ctx)

Expand Down
17 changes: 8 additions & 9 deletions django_school_management/students/views/students_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,9 @@ def students_dashboard_index(request):
"""
Dashboard for online admission system.
"""
unpaid_registrants = AdmissionStudent.objects.filter(paid=False)
all_applicants = AdmissionStudent.objects.all().order_by('-created')
admitted_students = AdmissionStudent.objects.filter(admitted=True, paid=True)
paid_registrants = AdmissionStudent.objects.filter(paid=True, admitted=False)
rejected_applicants = AdmissionStudent.objects.filter(rejected=True)
offline_applicants = AdmissionStudent.objects.filter(application_type='2')

# List of months since first application registration date
try:
first_application_date = AdmissionStudent.objects.order_by(
'created')[0].created.date()
first_application_date = datetime.strftime(datetime.now() - timedelta(days=365),'%Y-%m-%d' )
last_application_date = date.today()
dates = [str(first_application_date), str(last_application_date)]
months_start, months_end = [
Expand All @@ -56,6 +48,13 @@ def students_dashboard_index(request):
except IndexError:
month_list = []

unpaid_registrants = AdmissionStudent.objects.filter(paid=False)
all_applicants = AdmissionStudent.objects.all().order_by('-created')
admitted_students = AdmissionStudent.objects.filter(admitted=True, paid=True)
paid_registrants = AdmissionStudent.objects.filter(paid=True, admitted=False)
rejected_applicants = AdmissionStudent.objects.filter(rejected=True)
offline_applicants = AdmissionStudent.objects.filter(application_type='2')

context = {
'all_applicants': all_applicants,
'unpaid_registrants': unpaid_registrants,
Expand Down

0 comments on commit 07f77d9

Please sign in to comment.