Skip to content

Commit 136bba8

Browse files
authored
Merge pull request #22 from Iamankit45/hallHistory
added Hostel history functionality
2 parents 9cf9508 + 1feab6e commit 136bba8

File tree

9 files changed

+216
-3
lines changed

9 files changed

+216
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by Django 3.1.5 on 2024-03-14 22:50
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('globals', '0014_auto_20240312_1930'),
10+
('globals', '0014_auto_20240312_1902'),
11+
('globals', '0015_auto_20240312_2326'),
12+
]
13+
14+
operations = [
15+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.1.5 on 2024-03-14 22:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('globals', '0016_merge_20240314_2250'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='extrainfo',
15+
name='user_status',
16+
field=models.CharField(choices=[('NEW', 'NEW'), ('PRESENT', 'PRESENT')], default='PRESENT', max_length=50),
17+
),
18+
]

FusionIIIT/applications/hostel_management/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
admin.site.register(HostelAllotment)
2121
admin.site.register(GuestRoom)
2222
admin.site.register(HostelTransactionHistory)
23+
admin.site.register(HostelHistory)
2324

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 3.1.5 on 2024-03-14 22:52
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import django.utils.timezone
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('globals', '0017_auto_20240314_2252'),
12+
('hostel_management', '0017_hall_type_of_seater'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='HostelHistory',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
21+
('batch', models.CharField(max_length=50, null=True)),
22+
('caretaker', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='caretaker_history', to='globals.staff')),
23+
('hall', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='hostel_management.hall')),
24+
('warden', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='warden_history', to='globals.faculty')),
25+
],
26+
),
27+
]

FusionIIIT/applications/hostel_management/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,14 @@ class HostelTransactionHistory(models.Model):
345345
timestamp = models.DateTimeField(auto_now_add=True)
346346

347347
def __str__(self):
348-
return f"{self.change_type} change in {self.hall} at {self.timestamp}"
348+
return f"{self.change_type} change in {self.hall} at {self.timestamp}"
349+
350+
class HostelHistory(models.Model):
351+
hall = models.ForeignKey(Hall, on_delete=models.CASCADE)
352+
timestamp = models.DateTimeField(default=timezone.now)
353+
caretaker = models.ForeignKey(Staff, on_delete=models.SET_NULL, null=True, related_name='caretaker_history')
354+
batch = models.CharField(max_length=50, null=True)
355+
warden = models.ForeignKey(Faculty, on_delete=models.SET_NULL, null=True, related_name='warden_history')
356+
357+
def __str__(self):
358+
return f"History for {self.hall.hall_name} - {self.timestamp}"

FusionIIIT/applications/hostel_management/views.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ def hostel_view(request, context={}):
311311
context['student_fines'] = student_fines
312312

313313
hostel_transactions = HostelTransactionHistory.objects.order_by('-timestamp')
314+
315+
# Retrieve all hostel history entries
316+
hostel_history = HostelHistory.objects.order_by('-timestamp')
314317
context = {
315318

316319
'all_hall': all_hall,
@@ -345,6 +348,7 @@ def hostel_view(request, context={}):
345348
'staff_fine_caretaker': staff_fine_caretaker,
346349
'students': students,
347350
'hostel_transactions':hostel_transactions,
351+
'hostel_history':hostel_history,
348352
**context
349353
}
350354

@@ -883,7 +887,8 @@ def post(self, request, *args, **kwargs):
883887
hostel_allotment.assignedCaretaker = caretaker_staff
884888
hostel_allotment.save()
885889

886-
890+
# Retrieve the current warden for the hall
891+
current_warden = HallWarden.objects.filter(hall=hall).first()
887892

888893
print("Before creating HostelTransactionHistory")
889894
try:
@@ -897,6 +902,18 @@ def post(self, request, *args, **kwargs):
897902
except Exception as e:
898903
print("Error creating HostelTransactionHistory:", e)
899904

905+
906+
# Create hostel history
907+
try:
908+
HostelHistory.objects.create(
909+
hall=hall,
910+
caretaker=caretaker_staff,
911+
batch=hall.assigned_batch,
912+
warden=current_warden.faculty if( current_warden and current_warden.faculty) else None
913+
)
914+
print("hostel hostory created succeessfully")
915+
except Exception as e:
916+
print ("Error creating history",e)
900917
return Response({'message': f'Caretaker {caretaker_username} assigned to Hall {hall_id} successfully'}, status=status.HTTP_201_CREATED)
901918

902919
except Hall.DoesNotExist:
@@ -933,6 +950,10 @@ def post(self, request, *args, **kwargs):
933950
for room_allotment in room_allotments:
934951
room_allotment.assignedBatch = hall.assigned_batch
935952
room_allotment.save()
953+
954+
# retrieve the current caretaker and current warden for the hall
955+
current_caretaker =HallCaretaker.objects.filter(hall=hall).first()
956+
current_warden = HallWarden.objects.filter(hall=hall).first()
936957

937958
# Record the transaction history
938959
HostelTransactionHistory.objects.create(
@@ -942,6 +963,20 @@ def post(self, request, *args, **kwargs):
942963
new_value=hall.assigned_batch
943964
)
944965

966+
# Create hostel history
967+
try:
968+
HostelHistory.objects.create(
969+
hall=hall,
970+
caretaker=current_caretaker.staff if (current_caretaker and current_caretaker.staff) else None,
971+
972+
batch=hall.assigned_batch,
973+
warden=current_warden.faculty if( current_warden and current_warden.faculty) else None
974+
975+
)
976+
print("hostel hostory created succeessfully")
977+
except Exception as e:
978+
print ("Error creating history",e)
979+
945980
return JsonResponse({'status': 'success', 'message': 'Batch assigned successfully'}, status=200)
946981

947982
except Hall.DoesNotExist:
@@ -970,7 +1005,7 @@ def post(self, request, *args, **kwargs):
9701005

9711006
# Retrieve the previous caretaker for the hall, if any
9721007
prev_hall_warden = HallWarden.objects.filter(hall=hall).first()
973-
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
1008+
9741009
# Delete any previous assignments of the warden in Hallwarden table
9751010
HallWarden.objects.filter(faculty=warden).delete()
9761011

@@ -983,6 +1018,11 @@ def post(self, request, *args, **kwargs):
9831018
# Assign the new warden to the hall in Hallwarden table
9841019
hall_warden = HallWarden.objects.create(hall=hall, faculty=warden)
9851020

1021+
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
1022+
#current caretker
1023+
current_caretaker =HallCaretaker.objects.filter(hall=hall).first()
1024+
print(current_caretaker)
1025+
9861026
# Update the assigned warden in Hostelallottment table
9871027
hostel_allotments = HostelAllotment.objects.filter(hall=hall)
9881028
for hostel_allotment in hostel_allotments:
@@ -1001,6 +1041,21 @@ def post(self, request, *args, **kwargs):
10011041
except Exception as e:
10021042
print("Error creating HostelTransactionHistory:", e)
10031043

1044+
1045+
# Create hostel history
1046+
try:
1047+
HostelHistory.objects.create(
1048+
hall=hall,
1049+
caretaker=current_caretaker.staff if (current_caretaker and current_caretaker.staff) else None,
1050+
1051+
batch=hall.assigned_batch,
1052+
warden=warden
1053+
)
1054+
print("hostel hostory created succeessfully")
1055+
except Exception as e:
1056+
print ("Error creating history",e)
1057+
1058+
10041059
return Response({'message': f'Warden {warden_id} assigned to Hall {hall_id} successfully'}, status=status.HTTP_201_CREATED)
10051060

10061061
except Hall.DoesNotExist:

FusionIIIT/templates/hostelmanagement/hostel.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@
253253
</a>
254254
{% endif %}
255255

256+
{% if is_superuser %}
257+
<a class="item" data-tab="superUser7">
258+
Hostel History
259+
<i class="right floated chevron right icon"></i>
260+
</a>
261+
{% endif %}
262+
263+
256264
{% if user in hall_caretaker%}
257265
<a class="item" data-tab="inventory1">
258266
Inventory list
@@ -406,6 +414,14 @@
406414
{% endif %}
407415

408416

417+
{% if is_superuser %}
418+
<div class="ui tab segment" data-tab="superUser7">
419+
{% block Hostel_history %}
420+
{% include 'hostelmanagement/hostel_history.html' %}
421+
{% endblock %}
422+
</div>
423+
{% endif %}
424+
409425
{% if is_superuser %}
410426
<div class="ui tab segment" data-tab="superUser5">
411427
{% block View_Hostels %}
@@ -416,6 +432,8 @@
416432

417433

418434

435+
436+
419437

420438
{% if user in hall_caretaker%}
421439
<div class="ui tab segment" data-tab="fine1">
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
{% load static %}
3+
{% block Hostel_history %}
4+
<div class="ui secondary menu">
5+
<div class="ui floating dropdown labeled icon button">
6+
<i class="clipboard icon"></i>
7+
<span class="text">Hostel History</span>
8+
<div class="menu">
9+
{% for hall in all_hall %}
10+
<a class="{% if hall.hall_id == 'vivekananda' %}item active{% else %}item{% endif %}" data-tab={{hall.hall_id}}_hall_history>
11+
{{hall.hall_id}} history
12+
</a>
13+
{% endfor %}
14+
</div>
15+
</div>
16+
</div>
17+
18+
19+
{% for hall in all_hall %}
20+
<div class="{% if hall.hall_id == 'vivekananda' %}ui active tab{% else %}ui tab{% endif %}" data-tab={{hall.hall_id}}_hall_history>
21+
<div class="textLoader" style="max-height: 64vh; overflow-y: auto; overflow-x: hidden;">
22+
{% block {{hall.hall_id}} %}
23+
{% include 'hostelmanagement/hostel_history_data.html' with hall_id=hall.hall_id %}
24+
{% endblock %}
25+
</div>
26+
</div>
27+
{% endfor %}
28+
29+
{% endblock %}
30+
31+
32+
33+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% load custom_tags %}
2+
3+
{% block {{hall.hall_id}} %}
4+
<h1 align="center">{{hall.hall_id}} History</h1>
5+
<table class="ui table" border="1">
6+
<thead>
7+
<tr>
8+
<th>Hall</th>
9+
10+
<th>Batch</th>
11+
<th>Caretaker</th>
12+
<th>Warden</th>
13+
<th>Date</th>
14+
15+
16+
17+
</tr>
18+
</thead>
19+
<tbody>
20+
{% for entry in hostel_history %}
21+
22+
{% if entry.hall == hall %}
23+
<tr>
24+
<td>{{entry.hall}}</td>
25+
26+
<td>{{ entry.batch }}</td>
27+
<td>{{ entry.caretaker }}</td>
28+
<td>{{ entry.warden }}</td>
29+
<td>{{ entry.timestamp|date:"Y-m-d" }}</td>
30+
</tr>
31+
{% endif %}
32+
{% endfor %}
33+
</tbody>
34+
</table>
35+
36+
{% endblock %}

0 commit comments

Comments
 (0)