Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 3.1.5 on 2024-03-14 22:50

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('globals', '0014_auto_20240312_1930'),
('globals', '0014_auto_20240312_1902'),
('globals', '0015_auto_20240312_2326'),
]

operations = [
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2024-03-14 22:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('globals', '0016_merge_20240314_2250'),
]

operations = [
migrations.AlterField(
model_name='extrainfo',
name='user_status',
field=models.CharField(choices=[('NEW', 'NEW'), ('PRESENT', 'PRESENT')], default='PRESENT', max_length=50),
),
]
1 change: 1 addition & 0 deletions FusionIIIT/applications/hostel_management/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
admin.site.register(HostelAllotment)
admin.site.register(GuestRoom)
admin.site.register(HostelTransactionHistory)
admin.site.register(HostelHistory)

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.5 on 2024-03-14 22:52

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


class Migration(migrations.Migration):

dependencies = [
('globals', '0017_auto_20240314_2252'),
('hostel_management', '0017_hall_type_of_seater'),
]

operations = [
migrations.CreateModel(
name='HostelHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
('batch', models.CharField(max_length=50, null=True)),
('caretaker', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='caretaker_history', to='globals.staff')),
('hall', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='hostel_management.hall')),
('warden', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='warden_history', to='globals.faculty')),
],
),
]
12 changes: 11 additions & 1 deletion FusionIIIT/applications/hostel_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,14 @@ class HostelTransactionHistory(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"{self.change_type} change in {self.hall} at {self.timestamp}"
return f"{self.change_type} change in {self.hall} at {self.timestamp}"

class HostelHistory(models.Model):
hall = models.ForeignKey(Hall, on_delete=models.CASCADE)
timestamp = models.DateTimeField(default=timezone.now)
caretaker = models.ForeignKey(Staff, on_delete=models.SET_NULL, null=True, related_name='caretaker_history')
batch = models.CharField(max_length=50, null=True)
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}"
59 changes: 57 additions & 2 deletions FusionIIIT/applications/hostel_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ def hostel_view(request, context={}):
context['student_fines'] = student_fines

hostel_transactions = HostelTransactionHistory.objects.order_by('-timestamp')

# Retrieve all hostel history entries
hostel_history = HostelHistory.objects.order_by('-timestamp')
context = {

'all_hall': all_hall,
Expand Down Expand Up @@ -345,6 +348,7 @@ def hostel_view(request, context={}):
'staff_fine_caretaker': staff_fine_caretaker,
'students': students,
'hostel_transactions':hostel_transactions,
'hostel_history':hostel_history,
**context
}

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


# Retrieve the current warden for the hall
current_warden = HallWarden.objects.filter(hall=hall).first()

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


# Create hostel history
try:
HostelHistory.objects.create(
hall=hall,
caretaker=caretaker_staff,
batch=hall.assigned_batch,
warden=current_warden.faculty if( current_warden and current_warden.faculty) else None
)
print("hostel hostory created succeessfully")
except Exception as e:
print ("Error creating history",e)
return Response({'message': f'Caretaker {caretaker_username} assigned to Hall {hall_id} successfully'}, status=status.HTTP_201_CREATED)

except Hall.DoesNotExist:
Expand Down Expand Up @@ -933,6 +950,10 @@ def post(self, request, *args, **kwargs):
for room_allotment in room_allotments:
room_allotment.assignedBatch = hall.assigned_batch
room_allotment.save()

# retrieve the current caretaker and current warden for the hall
current_caretaker =HallCaretaker.objects.filter(hall=hall).first()
current_warden = HallWarden.objects.filter(hall=hall).first()

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

# Create hostel history
try:
HostelHistory.objects.create(
hall=hall,
caretaker=current_caretaker.staff if (current_caretaker and current_caretaker.staff) else None,

batch=hall.assigned_batch,
warden=current_warden.faculty if( current_warden and current_warden.faculty) else None

)
print("hostel hostory created succeessfully")
except Exception as e:
print ("Error creating history",e)

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

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

# Retrieve the previous caretaker for the hall, if any
prev_hall_warden = HallWarden.objects.filter(hall=hall).first()
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

# Delete any previous assignments of the warden in Hallwarden table
HallWarden.objects.filter(faculty=warden).delete()

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

print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
#current caretker
current_caretaker =HallCaretaker.objects.filter(hall=hall).first()
print(current_caretaker)

# Update the assigned warden in Hostelallottment table
hostel_allotments = HostelAllotment.objects.filter(hall=hall)
for hostel_allotment in hostel_allotments:
Expand All @@ -1001,6 +1041,21 @@ def post(self, request, *args, **kwargs):
except Exception as e:
print("Error creating HostelTransactionHistory:", e)


# Create hostel history
try:
HostelHistory.objects.create(
hall=hall,
caretaker=current_caretaker.staff if (current_caretaker and current_caretaker.staff) else None,

batch=hall.assigned_batch,
warden=warden
)
print("hostel hostory created succeessfully")
except Exception as e:
print ("Error creating history",e)


return Response({'message': f'Warden {warden_id} assigned to Hall {hall_id} successfully'}, status=status.HTTP_201_CREATED)

except Hall.DoesNotExist:
Expand Down
18 changes: 18 additions & 0 deletions FusionIIIT/templates/hostelmanagement/hostel.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@
</a>
{% endif %}

{% if is_superuser %}
<a class="item" data-tab="superUser7">
Hostel History
<i class="right floated chevron right icon"></i>
</a>
{% endif %}


{% if user in hall_caretaker%}
<a class="item" data-tab="inventory1">
Inventory list
Expand Down Expand Up @@ -406,6 +414,14 @@
{% endif %}


{% if is_superuser %}
<div class="ui tab segment" data-tab="superUser7">
{% block Hostel_history %}
{% include 'hostelmanagement/hostel_history.html' %}
{% endblock %}
</div>
{% endif %}

{% if is_superuser %}
<div class="ui tab segment" data-tab="superUser5">
{% block View_Hostels %}
Expand All @@ -416,6 +432,8 @@






{% if user in hall_caretaker%}
<div class="ui tab segment" data-tab="fine1">
Expand Down
33 changes: 33 additions & 0 deletions FusionIIIT/templates/hostelmanagement/hostel_history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

{% load static %}
{% block Hostel_history %}
<div class="ui secondary menu">
<div class="ui floating dropdown labeled icon button">
<i class="clipboard icon"></i>
<span class="text">Hostel History</span>
<div class="menu">
{% for hall in all_hall %}
<a class="{% if hall.hall_id == 'vivekananda' %}item active{% else %}item{% endif %}" data-tab={{hall.hall_id}}_hall_history>
{{hall.hall_id}} history
</a>
{% endfor %}
</div>
</div>
</div>


{% for hall in all_hall %}
<div class="{% if hall.hall_id == 'vivekananda' %}ui active tab{% else %}ui tab{% endif %}" data-tab={{hall.hall_id}}_hall_history>
<div class="textLoader" style="max-height: 64vh; overflow-y: auto; overflow-x: hidden;">
{% block {{hall.hall_id}} %}
{% include 'hostelmanagement/hostel_history_data.html' with hall_id=hall.hall_id %}
{% endblock %}
</div>
</div>
{% endfor %}

{% endblock %}




36 changes: 36 additions & 0 deletions FusionIIIT/templates/hostelmanagement/hostel_history_data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% load custom_tags %}

{% block {{hall.hall_id}} %}
<h1 align="center">{{hall.hall_id}} History</h1>
<table class="ui table" border="1">
<thead>
<tr>
<th>Hall</th>

<th>Batch</th>
<th>Caretaker</th>
<th>Warden</th>
<th>Date</th>



</tr>
</thead>
<tbody>
{% for entry in hostel_history %}

{% if entry.hall == hall %}
<tr>
<td>{{entry.hall}}</td>

<td>{{ entry.batch }}</td>
<td>{{ entry.caretaker }}</td>
<td>{{ entry.warden }}</td>
<td>{{ entry.timestamp|date:"Y-m-d" }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>

{% endblock %}