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

Modified Hostel allocation ,Room allocation ,Added Room Swaps ,Room change #1621

Open
wants to merge 20 commits into
base: latest_staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions FusionIIIT/applications/hostel_management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .templatetags.custom_filters import *
1 change: 1 addition & 0 deletions FusionIIIT/applications/hostel_management/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
admin.site.register(GuestRoom)
admin.site.register(HostelTransactionHistory)
admin.site.register(HostelHistory)
admin.site.register(HostelRoom)

18 changes: 17 additions & 1 deletion FusionIIIT/applications/hostel_management/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ class Meta:
'departure_time',
'nationality',
'room_type'
)
)


class AddNewHallForm(forms.ModelForm):
single_seater = forms.IntegerField(min_value=0, label='Single Seater Rooms')
double_seater = forms.IntegerField(min_value=0, label='Double Seater Rooms')
triple_seater = forms.IntegerField(min_value=0, label='Triple Seater Rooms')

class Meta:
model = Hall
fields = ['hall_id', 'hall_name','single_seater', 'double_seater', 'triple_seater']
help_texts = {
'hall_id': 'Hall ID should be like hall1, hall2, hall3, etc.',
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['hall_id'].help_text = '<span style="color: red;">Hall ID should be like hall1, hall2, hall3, etc.</span>'
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 3.1.5 on 2024-08-01 11:59

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('academic_information', '0001_initial'),
('hostel_management', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='hall',
name='double_seater',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='hall',
name='single_seater',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='hall',
name='triple_seater',
field=models.IntegerField(default=0),
),
migrations.CreateModel(
name='HostelRoom',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('room_type', models.CharField(choices=[('Single Seater', 'Single Seater'), ('Double Seater', 'Double Seater'), ('Triple Seater', 'Triple Seater')], max_length=20)),
('room_number', models.CharField(max_length=20)),
('status', models.CharField(choices=[('available', 'Available'), ('occupied', 'Occupied')], default='available', max_length=10)),
('available_seats', models.IntegerField()),
('hall', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='hostel_management.hall')),
('occupants', models.ManyToManyField(blank=True, to='academic_information.Student')),
],
),
]
29 changes: 28 additions & 1 deletion FusionIIIT/applications/hostel_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class Hall(models.Model):
]

type_of_seater = models.CharField(max_length=50, choices=TYPE_OF_SEATER_CHOICES, default='single')
single_seater=models.IntegerField(default=0)
double_seater=models.IntegerField(default=0)
triple_seater=models.IntegerField(default=0)

def __str__(self):
return self.hall_id

Expand Down Expand Up @@ -368,4 +372,27 @@ class HostelHistory(models.Model):
warden = models.ForeignKey(Faculty, on_delete=models.SET_NULL, null=True, related_name='warden_history')

def __str__(self):
return f"History for {self.hall.hall_name} - {self.timestamp}"
return f"History for {self.hall.hall_name} - {self.timestamp}"


class HostelRoom(models.Model):
ROOM_TYPES = [
('Single Seater', 'Single Seater'),
('Double Seater', 'Double Seater'),
('Triple Seater', 'Triple Seater'),
]

STATUS_CHOICES = [
('available', 'Available'),
('occupied', 'Occupied'),
]

hall = models.ForeignKey(Hall, on_delete=models.CASCADE)
room_type = models.CharField(max_length=20, choices=ROOM_TYPES)
room_number = models.CharField(max_length=20)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='available')
occupants = models.ManyToManyField(Student, blank=True)
available_seats = models.IntegerField()

def __str__(self):
return f"{self.room_number} - {self.get_room_type_display()}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# templatetags/custom_filters.py
from django import template

register = template.Library()

@register.filter
def filter_by_type(rooms, room_type):
return [room for room in rooms if room.room_type == room_type]

@register.filter
def occupied_seats(rooms):
return sum(room.occupants.count() for room in rooms)

@register.filter
def vacant_seats(rooms):
return sum(room.available_seats for room in rooms)
16 changes: 16 additions & 0 deletions FusionIIIT/applications/hostel_management/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,21 @@
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'),

path('addNewHall',views.AddNewHall.as_view(), name='add_new_hall'),
path('hostelDetails/<str:id>/', views.HostelDetails.as_view(), name='hostel_details'),
path('hostelAllotmentPage/', views.hostel_allotment_page, name='hostel_allotment_page'),
path('hostels/', views.fetch_hostels, name='fetch_hostels'),
path('allot-hostel/', views.allot_hostel, name='allot_hostel'),
path('students/', views.fetch_students, name='fetch_students'),

path('allot-rooms/<str:hostel_id>/', views.allot_rooms_to_students, name='allot_rooms'),
path('remove-room-allotments/<str:hostel_id>/', views.remove_room_allotments, name='remove_room_allotments'),
path('remove-hostel-allotment/', views.remove_hostel_allotment, name='remove_hostel_allotment'),

path('hostel/<str:hostel_id>/manual-room-allocation/', views.manual_room_allocation, name='manual_room_allocation'),
path('reassign-room/', views.reassign_student_room, name='reassign_student_room'),
path('swap-rooms/', views.swap_student_rooms, name='swap_student_rooms'),



]
5 changes: 4 additions & 1 deletion FusionIIIT/applications/hostel_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@ def save_worker_report_sheet(excel, sheet, user_id):
# hall_no = HallCaretaker.objects.get(staff__id=user_id).hall
# print(month,year)
# new_report = WorkerReport.objects.create(worker_id=worker_id, hall=hall_no, worker_name=worker_name, month=month, year=year, absent=absent, total_day=working_days, remark="none")
# new_report.save()
# new_report.save()

def sort_students_by_preference(students):
return students.order_by('batch', '-programme')
Loading
Loading