From c341c21f7346ed4d86f0ab0c81f7e0492a1dd00a Mon Sep 17 00:00:00 2001 From: grvup Date: Sun, 17 Nov 2024 03:00:38 +0530 Subject: [PATCH 1/2] Fixed academic module access failure by faculty --- .../applications/academic_procedures/views.py | 70 ++++++++++++++++--- .../programme_curriculum/forms.py | 5 +- .../migrations/0004_auto_20241117_0137.py | 18 +++++ .../programme_curriculum/models.py | 1 + .../academic_procedures/academicfac.html | 23 +++--- 5 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 FusionIIIT/applications/programme_curriculum/migrations/0004_auto_20241117_0137.py diff --git a/FusionIIIT/applications/academic_procedures/views.py b/FusionIIIT/applications/academic_procedures/views.py index 0e17ef96d..7f6e83072 100644 --- a/FusionIIIT/applications/academic_procedures/views.py +++ b/FusionIIIT/applications/academic_procedures/views.py @@ -159,15 +159,69 @@ def academic_procedures_faculty(request): approved_assistantship_request_list = ta_approved_assistantship_request_list | thesis_approved_assistantship_request_list mtechseminar_request_list = MTechGraduateSeminarReport.objects.all().filter(Overall_grade = '') phdprogress_request_list = PhDProgressExamination.objects.all().filter(Overall_grade = '') - courses_list = list(CourseInstructor.objects.select_related('course_id', 'batch_id', 'batch_id__discipline').filter(instructor_id__id=fac_id.id).only('course_id__code', 'course_id__name', 'batch_id')) - - assigned_courses = CourseInstructor.objects.select_related('course_id', 'batch_id', 'batch_id__discipline').filter( - instructor_id__id=fac_id.id, # Filter by faculty ID - batch_id__running_batch=True, # Filter by currently running batches - course_id__working_course=True # Filter by currently active courses - ).only('course_id__code', 'course_id__name', 'batch_id') - assigned_courses = list(assigned_courses) + + # courses_list = list(CourseInstructor.objects.select_related('course_id', 'batch_id', 'batch_id__discipline').filter(instructor_id__id=fac_id.id).only('course_id__code', 'course_id__name', 'batch_id')) + # print(fac_id.id) + courses_list = list( + CourseInstructor.objects.filter(instructor_id=fac_id.id) + .values('course_id_id','course_id__code','course_id__version','course_id__name', 'year', 'semester_no') + ) + for course in courses_list: + # Calculate the batch as an integer + course['batch'] = int(course['year'] - (course['semester_no'] // 2)) + + # print(courses_list) + # # courses_list = list( + # CourseInstructor.objects.select_related('course_id', 'instructor_id') + # .filter(instructor_id=fac_id) + # # .only('course_id__code', 'course_id__name', 'course_id') + # ) + + + # assigned_courses = CourseInstructor.objects.select_related('course_id', 'batch_id', 'batch_id__discipline').filter( + # instructor_id__id=fac_id.id, # Filter by faculty ID + # batch_id__running_batch=True, # Filter by currently running batches + # course_id__working_course=True # Filter by currently active courses + # ).only('course_id__code', 'course_id__name', 'batch_id') + + + course_years = ( + CourseInstructor.objects + .select_related('course_id', 'instructor_id') + .filter( + instructor_id=fac_id.id, + course_id__working_course=True + ) + ) + + assigned_courses = [] + excluded_years = set() + + for course_instructor in course_years: + # Calculate target year based on course year and semester + target_year = course_instructor.year - course_instructor.semester_no // 2 + + # Check if all batches for this target year are inactive + batches_for_year = Batch.objects.filter(year=target_year) + if batches_for_year.exists() and not batches_for_year.filter(running_batch=True).exists(): + excluded_years.add(course_instructor.year) + + # Second pass: filter courses based on excluded years + filtered_courses = ( + CourseInstructor.objects + .select_related('course_id', 'instructor_id') + .filter( + instructor_id=fac_id.id, + course_id__working_course=True + ) + .exclude(year__in=excluded_years) + ) + # Ensure unique results in the final list + assigned_courses = list(filtered_courses) + # assigned_courses = list(assigned_courses) + # assigned_courses = [] + # courses_list = [] # print('------------------------------------------------------------------------------------------------------------------' , list(assigned_courses)) r = range(4) return render( diff --git a/FusionIIIT/applications/programme_curriculum/forms.py b/FusionIIIT/applications/programme_curriculum/forms.py index 0ad37cd24..0698d514a 100644 --- a/FusionIIIT/applications/programme_curriculum/forms.py +++ b/FusionIIIT/applications/programme_curriculum/forms.py @@ -9,6 +9,7 @@ from applications.globals.models import (DepartmentInfo, Designation,ExtraInfo, Faculty, HoldsDesignation) from applications.filetracking.sdk.methods import * from django.db.models import Q +from datetime import datetime class ProgrammeForm(ModelForm): class Meta: @@ -386,6 +387,7 @@ def clean(self): return self.cleaned_data class CourseInstructorForm(forms.ModelForm): + next_year = datetime.now().year +1 course_id = forms.ModelChoiceField( queryset=Course.objects.all(), label="Select Course", @@ -399,8 +401,9 @@ class CourseInstructorForm(forms.ModelForm): empty_label="Choose an instructor", widget=forms.Select(attrs={'class': 'ui fluid search selection dropdown'}) ) + year = forms.ChoiceField( - choices=[('', 'Choose a year')] + [(year, year) for year in Batch.objects.values_list('year', flat=True).distinct()], + choices=[('', 'Choose a year')] + [(year, year) for year in Batch.objects.values_list('year', flat=True).distinct()]+[(next_year, next_year)], label="Select Year", widget=forms.Select(attrs={'class': 'ui fluid search selection dropdown'}) ) diff --git a/FusionIIIT/applications/programme_curriculum/migrations/0004_auto_20241117_0137.py b/FusionIIIT/applications/programme_curriculum/migrations/0004_auto_20241117_0137.py new file mode 100644 index 000000000..8a8d84741 --- /dev/null +++ b/FusionIIIT/applications/programme_curriculum/migrations/0004_auto_20241117_0137.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2024-11-17 01:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('programme_curriculum', '0003_auto_20241115_1545'), + ] + + operations = [ + migrations.AlterField( + model_name='courseslot', + name='type', + field=models.CharField(choices=[('Professional Core', 'Professional Core'), ('Professional Elective', 'Professional Elective'), ('Professional Lab', 'Professional Lab'), ('Engineering Science', 'Engineering Science'), ('Natural Science', 'Natural Science'), ('Humanities', 'Humanities'), ('Design', 'Design'), ('Manufacturing', 'Manufacturing'), ('Management Science', 'Management Science'), ('Open Elective', 'Open Elective'), ('Swayam', 'Swayam'), ('Project', 'Project'), ('Optional', 'Optional'), ('Backlog', 'Backlog'), ('Others', 'Others')], max_length=70), + ), + ] diff --git a/FusionIIIT/applications/programme_curriculum/models.py b/FusionIIIT/applications/programme_curriculum/models.py index 941f9c889..498508eb6 100644 --- a/FusionIIIT/applications/programme_curriculum/models.py +++ b/FusionIIIT/applications/programme_curriculum/models.py @@ -35,6 +35,7 @@ ('Swayam', 'Swayam'), ('Project', 'Project'), ('Optional', 'Optional'), + ('Backlog','Backlog'), ('Others', 'Others') ] diff --git a/FusionIIIT/templates/academic_procedures/academicfac.html b/FusionIIIT/templates/academic_procedures/academicfac.html index 51d48685f..31d55b1ac 100644 --- a/FusionIIIT/templates/academic_procedures/academicfac.html +++ b/FusionIIIT/templates/academic_procedures/academicfac.html @@ -81,9 +81,9 @@

Course Version

-

Programme

+

Working Year

-

Branch

+

Semester No

Download Roll List

@@ -97,8 +97,8 @@ {{course.course_id.name }} {{course.course_id.code }} {{course.course_id.version }} - {{course.batch_id.name }} - {{course.batch_id.discipline.name }} + {{course.year }} + {{course.semester_no }} @@ -127,18 +127,19 @@ Course Code Name Of the Courses - Batch + working year + semester no {% for obj in courses_list %} - {{obj.course_id.code}} - {{obj.course_id.name}} - {{ obj.batch_id.name}} {{obj.batch_id.year}}-{{obj.batch_id.discipline.name}} - + {{obj.course_id__code}} + {{obj.course_id__name}} + {{ obj.year}} + {{obj.semester_no}}
EDIT