From 014a47d5b7fe4d4f1e4bac2ef557b6859849d8df Mon Sep 17 00:00:00 2001 From: grvup Date: Sun, 20 Oct 2024 11:46:16 +0530 Subject: [PATCH 1/3] Required changes in forms.py --- .../programme_curriculum/forms.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/FusionIIIT/applications/programme_curriculum/forms.py b/FusionIIIT/applications/programme_curriculum/forms.py index 394828004..d6c8a53e0 100644 --- a/FusionIIIT/applications/programme_curriculum/forms.py +++ b/FusionIIIT/applications/programme_curriculum/forms.py @@ -8,7 +8,7 @@ from django.contrib.auth.models import User from applications.globals.models import (DepartmentInfo, Designation,ExtraInfo, Faculty, HoldsDesignation) from applications.filetracking.sdk.methods import * - +from django.db.models import Q class ProgrammeForm(ModelForm): class Meta: @@ -38,6 +38,20 @@ class Meta: 'programmes': 'Link Programmes to this Disciplines', 'acronym' : 'Enter Acronym' } + def __init__(self, *args, **kwargs): + super(DisciplineForm, self).__init__(*args, **kwargs) + + # Get the current discipline instance + discipline = kwargs.get('instance', None) + + if discipline: + # Show programmes that are either unlinked or linked to the current discipline + self.fields['programmes'].queryset = Programme.objects.filter( + Q(discipline__isnull=True) | Q(discipline=discipline) + ) + else: + # Show only programmes that are unlinked (no discipline assigned) + self.fields['programmes'].queryset = Programme.objects.filter(discipline__isnull=True) class CurriculumForm(ModelForm): @@ -203,6 +217,18 @@ class Meta: 'year' : 'Batch Year', 'curriculum' : 'Select Curriculum For Batch Students', } + def __init__(self, *args, **kwargs): + super(BatchForm, self).__init__(*args, **kwargs) + + # Get the list of curriculum ids that are already assigned to batches (excluding NULL values) + assigned_curriculum_ids = Batch.objects.filter(curriculum__isnull=False).values_list('curriculum', flat=True) + + # Exclude curriculums already in use + available_curriculums = Curriculum.objects.exclude(id__in=assigned_curriculum_ids) + + # Add an empty option (blank choice) at the start of the curriculum choices + self.fields['curriculum'].queryset = available_curriculums + self.fields['curriculum'].empty_label = "Select Curriculum" # This adds a blank option with a label class CourseSlotForm(ModelForm): From 415d2fd32e61565b4417ec5c258e1cceb98f1c73 Mon Sep 17 00:00:00 2001 From: Darpan Mehta Date: Sun, 20 Oct 2024 11:48:41 +0530 Subject: [PATCH 2/3] Required changes in views and template files --- .../programme_curriculum/views.py | 30 ++++++++------ .../admin_view_semesters_of_a_curriculum.html | 40 ++++++++++++++----- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/FusionIIIT/applications/programme_curriculum/views.py b/FusionIIIT/applications/programme_curriculum/views.py index 4ea51e609..602bbc866 100644 --- a/FusionIIIT/applications/programme_curriculum/views.py +++ b/FusionIIIT/applications/programme_curriculum/views.py @@ -225,6 +225,7 @@ def view_a_courseslot(request, courseslot_id): elif 'hod' in request.session['currentDesignationSelected'].lower(): url+='faculty/' course_slot = get_object_or_404(CourseSlot, Q(id=courseslot_id)) + notifs = request.user.notifications.all() return render(request, url+'view_a_courseslot.html', {'course_slot': course_slot,'notifications': notifs,}) @@ -438,7 +439,7 @@ def admin_view_semesters_of_a_curriculum(request, curriculum_id): transpose_semester_slots = list(zip(*semester_slots)) - all_batches = Batch.objects.filter(running_batch=True).exclude(curriculum=curriculum_id).order_by('year') + all_batches = Batch.objects.filter(running_batch=True, curriculum__isnull=True).order_by('year') return render(request, 'programme_curriculum/acad_admin/admin_view_semesters_of_a_curriculum.html', {'curriculum': curriculum, 'semesters': semesters, 'semester_slots': transpose_semester_slots, 'semester_credits': semester_credits, 'all_batches':all_batches}) @@ -924,29 +925,32 @@ def delete_courseslot(request, courseslot_id): return render(request, 'programme_curriculum/view_a_courseslot.html', {'course_slot': courseslot}) +# views.py def add_batch_form(request): - - user_details = ExtraInfo.objects.get(user = request.user) - des = HoldsDesignation.objects.all().filter(user = request.user).first() - if request.session['currentDesignationSelected']== "student" or request.session['currentDesignationSelected']== "Associate Professor" or request.session['currentDesignationSelected']== "Professor" or request.session['currentDesignationSelected']== "Assistant Professor" : + user_details = ExtraInfo.objects.get(user=request.user) + des = HoldsDesignation.objects.all().filter(user=request.user).first() + + if request.session['currentDesignationSelected'] in ["student", "Associate Professor", "Professor", "Assistant Professor"]: return HttpResponseRedirect('/programme_curriculum/programmes/') - elif str(request.user) == "acadadmin" : + elif str(request.user) == "acadadmin": pass elif 'hod' in request.session['currentDesignationSelected'].lower(): return HttpResponseRedirect('/programme_curriculum/programmes/') - - curriculum_id = request.GET.get('curriculum_id', -1) - form = BatchForm(initial={'curriculum': curriculum_id}) - submitbutton= request.POST.get('Submit') + + # Explicitly setting curriculum to None or '' to prevent any default value + form = BatchForm(initial={'curriculum': None}) + + submitbutton = request.POST.get('Submit') if submitbutton: if request.method == 'POST': form = BatchForm(request.POST) if form.is_valid(): form.save() - messages.success(request, "Added Batch successful") + messages.success(request, "Added Batch successfully") return HttpResponseRedirect('/programme_curriculum/admin_batches/') - return render(request, 'programme_curriculum/acad_admin/add_batch_form.html',{'form':form, 'submitbutton': submitbutton}) - + + return render(request, 'programme_curriculum/acad_admin/add_batch_form.html', {'form': form, 'submitbutton': submitbutton}) + def edit_batch_form(request, batch_id): diff --git a/FusionIIIT/templates/programme_curriculum/acad_admin/admin_view_semesters_of_a_curriculum.html b/FusionIIIT/templates/programme_curriculum/acad_admin/admin_view_semesters_of_a_curriculum.html index 35f30d2d7..e41901709 100644 --- a/FusionIIIT/templates/programme_curriculum/acad_admin/admin_view_semesters_of_a_curriculum.html +++ b/FusionIIIT/templates/programme_curriculum/acad_admin/admin_view_semesters_of_a_curriculum.html @@ -25,7 +25,7 @@

{{ curriculum }}

Batches:     {% for batch in curriculum.batches.all %} - {{ batch }},     + {{ batch }} {% endfor %}

@@ -189,14 +189,30 @@

- -
NEW BATCH
- -
+
+ {% if curriculum.batches.count < 1 %} + + +
NEW BATCH
+ +
+ {% else %} + + +
BATCH ALREADY ATTACHED
+ +
+ {% endif %} +
+
@@ -228,6 +244,7 @@

+ {% if curriculum.batches.count < 1 %} + {% else %} + + {% endif %} From 7a9d5f092b08119bf2027283d8ccf0bb71f71645 Mon Sep 17 00:00:00 2001 From: grvup Date: Sun, 20 Oct 2024 12:44:40 +0530 Subject: [PATCH 3/3] changed files in templates --- .../faculty/view_semesters_of_a_curriculum.html | 2 +- .../programme_curriculum/view_semesters_of_a_curriculum.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FusionIIIT/templates/programme_curriculum/faculty/view_semesters_of_a_curriculum.html b/FusionIIIT/templates/programme_curriculum/faculty/view_semesters_of_a_curriculum.html index 2b8f7e5dc..78ab0b10b 100644 --- a/FusionIIIT/templates/programme_curriculum/faculty/view_semesters_of_a_curriculum.html +++ b/FusionIIIT/templates/programme_curriculum/faculty/view_semesters_of_a_curriculum.html @@ -25,7 +25,7 @@

{{ curriculum }}

Batches:     {% for batch in curriculum.batches.all %} - {{ batch }},     + {{ batch }} {% endfor %}

diff --git a/FusionIIIT/templates/programme_curriculum/view_semesters_of_a_curriculum.html b/FusionIIIT/templates/programme_curriculum/view_semesters_of_a_curriculum.html index f6e3bb580..37943388b 100644 --- a/FusionIIIT/templates/programme_curriculum/view_semesters_of_a_curriculum.html +++ b/FusionIIIT/templates/programme_curriculum/view_semesters_of_a_curriculum.html @@ -25,7 +25,7 @@

{{ curriculum }}

Batches:     {% for batch in curriculum.batches.all %} - {{ batch }},     + {{ batch }} {% endfor %}