Skip to content

Commit

Permalink
Merge pull request #33 from Iamankit45/testcase1
Browse files Browse the repository at this point in the history
student details,room allottment functionality change
  • Loading branch information
anujpatel03 authored Apr 10, 2024
2 parents 0606bb6 + 161efc9 commit 48d0584
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ node_modules/
FusionIIIT/static/
package-lock.json


**/**/migrations/*
.DS_Store

6 changes: 3 additions & 3 deletions FusionIIIT/applications/hostel_management/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
path('student/<str:username>/name/', views.get_student_name, name='find_name'),


path('edit-student/<int:student_id>/', views.edit_student, name='edit_student'),


path('edit-student/<str:student_id>/', views.EditStudentView.as_view(), name='edit_student'),
path('remove-student/<str:student_id>/', views.RemoveStudentView.as_view(), name='remove-student'),

]
75 changes: 63 additions & 12 deletions FusionIIIT/applications/hostel_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ def hostel_view(request, context={}):
hostel_students_details = []
students = Student.objects.filter(hall_no=hall_number)

a_room=[]
t_rooms = HallRoom.objects.filter(hall=hall_num)
for room in t_rooms:
if (room.room_cap > room.room_occupied):
a_room.append(room)

print(a_room)
# Retrieve additional information for each student
for student in students:
student_info = {}
Expand All @@ -326,7 +333,12 @@ def hostel_view(request, context={}):

hostel_students_details.append(student_info)

# Sort the hostel_students_details list by roll number
hostel_students_details = sorted(hostel_students_details, key=lambda x: x['student_id'])


context['hostel_students_details'] = hostel_students_details
context['av_room'] = a_room

if request.user.id in Faculty.objects.values_list('id__user', flat=True):
staff_student_info = request.user.extrainfo.id
Expand Down Expand Up @@ -1146,6 +1158,8 @@ def post(self, request, *args, **kwargs):
print ("Error creating history",e)

self.update_student_hall_allotment(hall, hall.assigned_batch)
print("batch assigned successssssssssssssssssss")
messages.success(request, 'batch assigned succesfully')

return JsonResponse({'status': 'success', 'message': 'Batch assigned successfully'}, status=200)

Expand Down Expand Up @@ -2051,18 +2065,55 @@ def delete(self, request, fine_id):



def edit_student(request, student_id):
student = get_object_or_404(Student, id=student_id)

class EditStudentView(View):
template_name = 'hostelmanagement/edit_student.html'

if request.method == 'POST':
# Process the form submission to update student details
# For example:
student.first_name = request.POST.get('first_name')
student.last_name = request.POST.get('last_name')
# Update other fields as needed
def get(self, request, student_id):
student = Student.objects.get(id=student_id)

context = {'student': student}
return render(request, self.template_name, context)

def post(self, request, student_id):
student = Student.objects.get(id=student_id)

# Update student details
student.id.user.first_name = request.POST.get('first_name')
student.id.user.last_name = request.POST.get('last_name')
student.programme = request.POST.get('programme')
student.batch = request.POST.get('batch')
student.hall_no = request.POST.get('hall_number')
student.room_no = request.POST.get('room_number')
student.specialization = request.POST.get('specialization')

student.save()
# Redirect to a page showing the updated details or any other desired page
return redirect('student_details') # Redirect to the student details page

# Update phone number and address from ExtraInfo model
student.id.phone_no = request.POST.get('phone_number')
student.id.address = request.POST.get('address')
student.id.save()
student.save()
messages.success(request, 'Student details updated successfully.')
return redirect("hostelmanagement:hostel_view")

# If it's a GET request, render the edit student details form
return render(request, 'update_student_details.html', {'student': student})
class RemoveStudentView(View):
def post(self, request, student_id):
try:
student = Student.objects.get(id=student_id)
student.hall_no = 0
student.save()
messages.success(request, 'Student removed successfully.')
return redirect("hostelmanagement:hostel_view")
return JsonResponse({'status': 'success', 'message': 'Student removed successfully'})
except Student.DoesNotExist:
return JsonResponse({'status': 'error', 'message': 'Student not found'}, status=404)
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)}, status=500)

def dispatch(self, request, *args, **kwargs):
if request.method != 'POST':
return JsonResponse({'status': 'error', 'message': 'Method Not Allowed'}, status=405)
return super().dispatch(request, *args, **kwargs)


10 changes: 5 additions & 5 deletions FusionIIIT/templates/hostelmanagement/add_student.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ <h3 align="center"> Student Room Allotment Application Form </h3><br><br>
{% comment %} <input value="" class="ui large input" name="roll_no" required onkeypress="return isNumberKey(event)"> {% endcomment %}
<select class="ui search fluid dropdown" name="roll_no" required>
<option value="">Select</option>
{% for i, students in halls_student.items %}
{% for st in students %}
<option value="{{st.id.user.username}}">{{st.id.user.username}}</option>
{% endfor %}
{% for stu in hostel_students_details %}

<option value="{{ stu.student_id }}">{{ stu.student_id }}</option>

{%endfor%}
</select>
</div>
Expand All @@ -27,7 +27,7 @@ <h3 align="center"> Student Room Allotment Application Form </h3><br><br>
<select class="ui search fluid dropdown" name="hall_room_no" required>
<option value="">Select</option>

{% for room in room_avail%}
{% for room in av_room%}
<option value="{{room.hall}}-{{room.block_no}}-{{room.room_no}}">{{room.hall.hall_id}}-{{room.block_no}}-{{room.room_no}}</option>
{% endfor %}
</select>
Expand Down
179 changes: 179 additions & 0 deletions FusionIIIT/templates/hostelmanagement/edit_student.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{% extends 'globals/base.html' %}
{% load static %}

{% block title %}
Hostel
{% endblock %}


{% block body %}
{% block navBar %}
{% include 'dashboard/navbar.html' %}
{% endblock %}
{% block content %}
<div class="ui stackable doubling grid">
<div class="column"></div>
<div class="three wide column">
<div class="row">
{% block userCard %}
{% include 'globals/usercard.html' %}
{% endblock %}
</div>
<!-- <div class="ui divider"></div> -->
</div>
<div class="eight wide column">
<div class="row">


<h2>Edit Student Details</h2>
<form method="post" class="ui form" action="{% url 'hostelmanagement:edit_student' student.id.id %}">
{% csrf_token %}
<label for="roll_number">Roll Number</label>
<input type="text" id="roll_number" name="roll_number" value="{{student.id.id}}"><br>
<span id="roll_error" style="color: red;"></span><br>

<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="first_name" value="{{ student.id.user.first_name }}"><br>
<span id="first_name_error" style="color: red;"></span><br>

<label for="programme">Programme:</label>
<input type="text" id="programme" name="programme" value="{{ student.programme }}"><br>
<span id="programme_error" style="color: red;"></span><br>

<label for="batch">Batch:</label>
<input type="text" id="batch" name="batch" value="{{ student.batch }}"><br>
<span id="batch_error" style="color: red;"></span><br>

<label for="hall_number">Hall Number:</label>
<input type="text" id="hall_number" name="hall_number" value="{{ student.hall_no }}"><br>

<label for="room_number">Room Number:</label>
<input type="text" id="room_number" name="room_number" value="{{ student.room_no }}"><br>

<label for="specialization">Specialization:</label>
<input type="text" id="specialization" name="specialization" value="{{ student.specialization }}"><br>

<label for="phone_number">Contact Number:</label>
<input type="text" id="phone_number" name="phone_number" value="{{ student.id.phone_no }}"><br>
<!-- Add an element to display the error message -->
<span id="phone_error" style="color: red;"></span><br>


<label for="address">Address:</label>
<input type="text" id="address" name="address" value="{{ student.id.address }}"><br>

<br>
<button type="submit" class="ui button primary" id="saveChangesBtn">Save Changes</button>
<a href="{% url 'hostelmanagement:hostel_view' %}" class="ui button">Back to Homepage</a>

</form>
<br>
</div>
</div>

</div>
{% endblock %}

<script>
document.addEventListener('DOMContentLoaded', function () {
// Get form and button elements
const form = document.querySelector('.ui.form');
const saveChangesBtn = document.getElementById('saveChangesBtn');

// Function to validate phone number
function validatePhoneNumber() {
var phoneNumber = document.getElementById('phone_number').value;
var phoneError = document.getElementById('phone_error');

// Check if phone number is exactly 10 digits
if (phoneNumber.length !== 10) {
phoneError.innerText = 'Phone number must be exactly 10 digits.';
return false; // Prevent form submission
} else {
phoneError.innerText = ''; // Clear error message
return true; // Allow form submission
}
}

// Function to validate roll number
function validateRollNumber() {
var rollNumber = document.getElementById('roll_number').value;
var rollError = document.getElementById('roll_error');

// Check if roll number is empty
if (rollNumber.trim() === '') {
rollError.innerText = 'Roll number cannot be empty.';
return false; // Prevent form submission
} else {
rollError.innerText = ''; // Clear error message
return true; // Allow form submission
}
}

// Function to validate first name
function validateFirstName() {
var firstName = document.getElementById('first_name').value;
var firstNameError = document.getElementById('first_name_error');

// Check if first name is empty
if (firstName.trim() === '') {
firstNameError.innerText = 'First name cannot be empty.';
return false; // Prevent form submission
} else {
firstNameError.innerText = ''; // Clear error message
return true; // Allow form submission
}
}

// Function to validate batch
function validateBatch() {
var batch = document.getElementById('batch').value;
var batchError = document.getElementById('batch_error');

// Check if batch is empty
if (batch.trim() === '') {
batchError.innerText = 'Batch cannot be empty.';
return false; // Prevent form submission
} else {
batchError.innerText = ''; // Clear error message
return true; // Allow form submission
}
}

// Function to validate programme
function validateProgramme() {
var programme = document.getElementById('programme').value;
var programmeError = document.getElementById('programme_error');

// Check if programme is empty
if (programme.trim() === '') {
programmeError.innerText = 'Programme cannot be empty.';
return false; // Prevent form submission
} else {
programmeError.innerText = ''; // Clear error message
return true; // Allow form submission
}
}

// Event listener for form submission
form.addEventListener('submit', function(event) {
// Prevent default form submission
event.preventDefault();

// Call the validation functions
var isValidPhoneNumber = validatePhoneNumber();
var isValidRollNumber = validateRollNumber();
var isValidFirstName = validateFirstName();
var isValidBatch = validateBatch();
var isValidProgramme = validateProgramme();

// If all fields are valid, submit the form
if (isValidPhoneNumber && isValidRollNumber && isValidFirstName && isValidBatch && isValidProgramme) {
form.submit();
}
});
});
</script>


{% endblock %}
Loading

0 comments on commit 48d0584

Please sign in to comment.