Skip to content

Commit

Permalink
Merge pull request #1633 from Akashsah2003/latest_staging
Browse files Browse the repository at this point in the history
feat(AC2): Added support for elective preregistration and corrected preregistration process
  • Loading branch information
dvjsharma authored Oct 22, 2024
2 parents a6438bc + d4da4bd commit 9b31585
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 51 deletions.
6 changes: 3 additions & 3 deletions FusionIIIT/applications/academic_procedures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,14 +1474,14 @@ def auto_pre_registration(request):
course_slot_id = course_slot_id_for_model,
priority = priority_of_current_course
)
f =FinalRegistration(student_id=current_user ,course_slot_id=course_slot_id_for_model , course_id=course_id_for_model ,semester_id=sem_id)
final_reg_curr.append(f)
# f =FinalRegistration(student_id=current_user ,course_slot_id=course_slot_id_for_model , course_id=course_id_for_model ,semester_id=sem_id)
# final_reg_curr.append(f)
reg_curr.append(p)
existing_entries.add(current_combination)
try:

InitialRegistration.objects.bulk_create(reg_curr)
FinalRegistration.objects.bulk_create(final_reg_curr)
# FinalRegistration.objects.bulk_create(final_reg_curr)
registration_check = StudentRegistrationChecks(
student_id = current_user,
pre_registration_flag = True,
Expand Down
144 changes: 96 additions & 48 deletions FusionIIIT/templates/academic_procedures/auto_pre_registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<th>Course Code</th>
<th>Course Name</th>
<th>Credits</th>
<th>Priority</th>
</tr>
</thead>
<tbody>
Expand All @@ -121,6 +122,12 @@
<br>
{% endfor %}
</td>
<td>
{% for course in courses %}
{{course.priority}}
<br>
{% endfor %}
</td>

</tr>
{% endfor %}
Expand All @@ -144,6 +151,7 @@
<th>Slot type</th>
<th>Semester</th>
<th>Credits</th>
<th>Priority</th>
<th>Select</th>
</tr>
</thead>
Expand All @@ -152,34 +160,57 @@
<input type="text" hidden="true" id="mincr" value="{{curr_sem.curriculum.min_credit}}">
{% for course_slot in next_sem_registration_courses %}
{% if course_slot.type == "Swayam" %}
{% with "x"|ljust:swayam_courses_count as dummy_range %}
{% for _ in dummy_range %}
<input type="text" name='course_slot' value='{{ course_slot.id }}' hidden="True"
data-value2='{{course_slot.type}}'>
<tr>
<td>{{ forloop.counter0|add:forloop.parentloop.counter0|add:"+1" }}.</td>
<td>{{course_slot.name}}</td>
<td>{{course_slot.type}}</td>
<td>{{next_sem.semester_no}}
<input type="text" name='semester' value='{{ next_sem.id }}' hidden="True">
</td>
<td id="credit_values_course" class="credit_values">{{course_slot.courses.all.0.credit}} </td>
<td>
<div style="margin-top: 5px;margin-bottom:5px;">
<select class="ui dropdown choicesBox" required="True" name="course_priority-{{course_slot.id}}">
<option value="NULL">Choices</option>
{% for course in course_slot.courses.all %}
<option value='{{1}}-{{course.id}}' class="Prechoices"
data-value2="{{course.credit}}">
{{course.code}}-{{ course.name }}</option>
{% endfor %}
</select>
</div>
</td>
</tr>
<input type="text" name="ct" value="{{forloop.counter}}" hidden="True">
{% endfor %}
{% endwith %}
<input type="text" name='course_slot' value='{{ course_slot.id }}' hidden="True"
data-value2='{{course_slot.type}}'>
<tr>
<td>{{ forloop.counter }}.</td>
<td>{{course_slot.name}}</td>
<td>{{course_slot.type}}</td>
<td>{{next_sem.semester_no}}
<input type="text" name='semester' value='{{ next_sem.id }}' hidden="True">
</td>
<td id="credit_values_course" class="credit_values">{{course_slot.courses.all.0.credit}} </td>
<td>
<div style="margin-top: 5px;margin-bottom:5px;">
<select class="ui dropdown choicesBox" required="True" name="course_priority-{{course_slot.id}}">
<option value="NULL">Choices</option>
{% for course in course_slot.courses.all %}
<option value='{{1}}-{{course.id}}' class="Prechoices"
data-value2="{{course.credit}}">
{{course.code}}-{{ course.name }}</option>
{% endfor %}
</select>
</div>
</td>
</tr>
<input type="text" name="ct" value="{{forloop.counter}}" hidden="True">
{% elif course_slot.type == "Optional Elective" %}
{% for course in course_slot.courses.all %}
<input type="text" name='course_slot' value='{{ course_slot.id }}' hidden="True"
data-value2='{{course_slot.type}}'>
<tr>
<td>{{ forloop.parentloop.counter }}.</td>
<td>{{ course_slot.name }}</td>
<td>{{ course_slot.type }}</td>
<td>{{ next_sem.semester_no }}
<input type="text" name='semester' value='{{ next_sem.id }}' hidden="True">
</td>
<td id="credit_values_course" class="credit_values">{{ course.credit }} </td>
<td id="priority" class="priority">{{ forloop.counter }} </td>
<td>
<div style="margin-top: 5px;margin-bottom:5px;">
<select class="ui dropdown choicesBox" required="True" name="course_priority-{{ course_slot.id }}">
<option value="NULL">Choices</option>
{% for course1 in course_slot.courses.all %}
<option value='{{ forloop.parentloop.counter }}-{{ course1.id }}' class="Prechoices" data-value2="{{ course1.credit }}">
{{ course1.code }}-{{ course1.name }}
</option>
{% endfor %}
</select>
</div>
</td>
</tr>
{% endfor %}
{% else %}

<input type="text" name='course_slot' value='{{ course_slot.id }}' hidden="True"
Expand Down Expand Up @@ -269,23 +300,18 @@
let course_priority = document.getElementsByName("course_priority-" + course_slot_id);
let unique_choices = new Set();
for (let j = 0; j < course_priority.length; j++) {
// console.log("course_priority-" + course_slot_id , course_priority[j].value )
if ((!course_slot_type.startsWith("Optional") && !course_slot_type.startsWith("Swayam") )&& course_priority[j].value == "NULL") {
// // console.log("course_priority-" + course_slot_id , course_priority[j].value )
if ((!(course_slot_type.startsWith("Optional") && course_slot_type != "Optional Elective") && !course_slot_type.startsWith("Swayam") )&& course_priority[j].value == "NULL") {
alert("Please select all choices for " + parseInt(i + 1) + " " + course_slot_type + " slot");
return false;
}
let selected_course = course_priority[j].value.split("-");
unique_choices.add(selected_course[1]);
if (course_priority[0].value != "NULL" && course_priority[j].value.split("-")[0] == '1' ) {
count = count + parseInt(credits[i].innerHTML);
}
}

if (course_priority[0].value != "NULL" ) {
count = count + parseInt(credits[i].innerHTML);
}

if (unique_choices.size != course_priority.length && course_slot_type != "Swayam" ) {
alert("Please select unique courses for " + parseInt(i + 1) + " " + course_slot_type + " slot");
return false;
}
}

// alert("Total Credits for Registered Courses :" + count);
Expand All @@ -297,6 +323,7 @@
} else {
event.preventDefault();
var friendForm = $(this);
console.log(friendForm.serialize());
var posting = $.post(friendForm.attr('action'), friendForm.serialize());
// if success
posting.done(function (data) {
Expand Down Expand Up @@ -394,9 +421,10 @@
}
var dropdown = event.target.closest('.ui.dropdown.choicesBox');
if (dropdown) {
var selectElement = dropdown.querySelector('select');
var optionCount = dropdown.querySelector('select').options.length;
if (optionCount > 1) {
var selectedOption = dropdown.querySelector('select').value;
var selectedOption = selectElement.value;
// console.log(dropdown)
if (selectedOption !== "NULL") {
var selectedCourseName = dropdown.querySelector('select option:checked').text;
Expand All @@ -405,17 +433,37 @@
var courseSlotId = dropdown.querySelector('select').getAttribute("name").split('-')[1];
if (confirm("Are you sure you want to register for " + selectedCourseName + "?")) {
// handleDropdownChangePreRegistrationEvent = false;
addCourse(dropdown , courseSlotId, function(response) {
if(response.message === 'Course not added because seats are full!'){
// console.log(selectedOptionElement)
selectedOptionElement.remove();
}else{
// console.log("credits : " + credit);
credit += selectedCourseCredit;
dropdown.classList.add("disabled-dropdown");
// alert(response.message);
// addCourse(dropdown , courseSlotId, function(response) {
// if(response.message === 'Course not added because seats are full!'){
// // console.log(selectedOptionElement)
// selectedOptionElement.remove();
// }else{
// // console.log("credits : " + credit);
// credit += selectedCourseCredit;
// dropdown.classList.add("disabled-dropdown");
// // alert(response.message);
// }
// });
var suffix = selectedOption.split('-')[1];
var prefix = selectedOption.split('-')[0];
console.log(suffix);
var allSelects = document.querySelectorAll('select[name="' + selectElement.getAttribute("name") + '"]');
// console.log(allSelects);
allSelects.forEach(function (currentSelectElement) {
// Skip the current dropdown where the selection was made
if (currentSelectElement !== selectElement) {
var optionToDisable = currentSelectElement.querySelector('option[value$="-' + suffix + '"]');
console.log(currentSelectElement, optionToDisable);
if (optionToDisable) {
optionToDisable.remove();
}
}
});
if (prefix == '1') {
credit += selectedCourseCredit;
// console.log(credit);
}
dropdown.classList.add("disabled-dropdown");
} else {
// Reset the dropdown to its initial state if user cancels
dropdown.querySelector('select').selectedIndex = 0;
Expand Down

0 comments on commit 9b31585

Please sign in to comment.