From 07f77d9db97e81ed3a3dfe50b842900c575d7a40 Mon Sep 17 00:00:00 2001 From: TareqMonwer Date: Mon, 4 Nov 2024 23:20:16 +0600 Subject: [PATCH] update counselor dashboard --- .../students/views/report_views.py | 18 +++++------------- .../students/views/students_views.py | 17 ++++++++--------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/django_school_management/students/views/report_views.py b/django_school_management/students/views/report_views.py index 8342c86..e5a6830 100644 --- a/django_school_management/students/views/report_views.py +++ b/django_school_management/students/views/report_views.py @@ -1,3 +1,4 @@ +import calendar import datetime from django.db.models.functions import ExtractMonth @@ -65,21 +66,12 @@ 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 @@ -87,7 +79,7 @@ def counsel_monthly_report(request, response_type='html', date_param=None): 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 @@ -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(), @@ -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) diff --git a/django_school_management/students/views/students_views.py b/django_school_management/students/views/students_views.py index f872968..be750d6 100644 --- a/django_school_management/students/views/students_views.py +++ b/django_school_management/students/views/students_views.py @@ -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 = [ @@ -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,