Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest staging #1632

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion FusionIIIT/applications/programme_curriculum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):

Expand Down
30 changes: 17 additions & 13 deletions FusionIIIT/applications/programme_curriculum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,})


Expand Down Expand Up @@ -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})

Expand Down Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 class="header">{{ curriculum }}</h2>
<h4 class="header">
Batches:&nbsp;&nbsp;&nbsp;&nbsp;
{% for batch in curriculum.batches.all %}
{{ batch }},&nbsp;&nbsp;&nbsp;&nbsp;
{{ batch }}
{% endfor %}
</h4>
</td>
Expand Down Expand Up @@ -189,14 +189,30 @@ <h4 class="header">
</div>
<div class="ui divider"></div>
<div class="ui fitted item">
<a class="fluid ui large primary animated button"
href="{% url 'programme_curriculum:add_batch_form' %}?curriculum_id={{ curriculum.id }}"
type="Submit" name="Submit" target="_blank" rel="noopener">
<div class="visible content">NEW BATCH</div>
<div class="hidden content">
<i class="add icon"></i>
</div>
</a>
<div class="ui fitted item">
{% if curriculum.batches.count < 1 %}
<!-- Show the regular NEW BATCH button if no batch is attached -->
<a class="fluid ui large primary animated button"
href="{% url 'programme_curriculum:add_batch_form' %}?curriculum_id={{ curriculum.id }}"
type="submit" name="Submit" target="_blank" rel="noopener">
<div class="visible content">NEW BATCH</div>
<div class="hidden content">
<i class="add icon"></i>
</div>
</a>
{% else %}
<!-- Disable the button and add hover effect for message -->
<a class="fluid ui large primary animated button disabled-tooltip"
href="javascript:void(0);" title="A batch is already attached to this curriculum"
style="cursor: not-allowed;">
<div class="visible content">BATCH ALREADY ATTACHED</div>
<div class="hidden content">
<i class="add icon"></i>
</div>
</a>
{% endif %}
</div>

</div>
<div class="ui fitted item">
<div class="fluid ui large positive animated button">
Expand Down Expand Up @@ -228,6 +244,7 @@ <h4 class="header">
<i class="tag icon"></i>
</div>
</div>
{% if curriculum.batches.count < 1 %}
<div class="ui vertical left menu">
{% if all_batches.count < 1 %}
<div class="item">No other batches avaliable</div>
Expand All @@ -239,6 +256,11 @@ <h4 class="header">
{% endfor %}
{% endif %}
</div>
{% else %}
<div class="ui vertical left menu">
<div class="item">A batch is already attached</div>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 class="header">{{ curriculum }}</h2>
<h4 class="header">
Batches:&nbsp;&nbsp;&nbsp;&nbsp;
{% for batch in curriculum.batches.all %}
{{ batch }},&nbsp;&nbsp;&nbsp;&nbsp;
{{ batch }}
{% endfor %}
</h4>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 class="header">{{ curriculum }}</h2>
<h4 class="header">
Batches:&nbsp;&nbsp;&nbsp;&nbsp;
{% for batch in curriculum.batches.all %}
{{ batch }},&nbsp;&nbsp;&nbsp;&nbsp;
{{ batch }}
{% endfor %}
</h4>
</td>
Expand Down
Loading