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
4 changes: 2 additions & 2 deletions FusionIIIT/applications/department/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def faculty_view(request):
upload_announcement=upload_announcement,
department = department,
ann_date=ann_date)
# department_notif(usrnm, recipients , message)
department_notif(usrnm, recipients , message)

context = browse_announcements()
return render(request, 'department/dep_request.html', {"user_designation":user_info.user_type,
Expand Down Expand Up @@ -223,7 +223,7 @@ def staff_view(request):
upload_announcement=upload_announcement,
department = department,
ann_date=ann_date)
# department_notif(usrnm, recipients , message)
department_notif(usrnm, recipients , message)

context = browse_announcements()
return render(request, 'department/dep_request.html', {"user_designation":user_info.user_type,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2024-03-15 21:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('globals', '0014_auto_20240312_1930'),
]

operations = [
migrations.AlterField(
model_name='extrainfo',
name='user_status',
field=models.CharField(choices=[('NEW', 'NEW'), ('PRESENT', 'PRESENT')], default='PRESENT', max_length=50),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2024-03-15 21:57

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.AlterField(
model_name='extrainfo',
name='user_status',
field=models.CharField(choices=[('PRESENT', 'PRESENT'), ('NEW', 'NEW')], default='PRESENT', max_length=50),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.1.5 on 2024-03-15 21:53

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('globals', '0015_auto_20240315_2100'),
('globals', '0018_merge_20240315_1500'),
]

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

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('globals', '0019_merge_20240315_2153'),
]

operations = [
migrations.AlterField(
model_name='extrainfo',
name='user_status',
field=models.CharField(choices=[('PRESENT', 'PRESENT'), ('NEW', 'NEW')], default='PRESENT', max_length=50),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2024-03-15 21:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('hostel_management', '0015_merge_20240220_1917'),
]

operations = [
migrations.AddField(
model_name='hostelleave',
name='remark',
field=models.TextField(blank=True, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.1.5 on 2024-03-15 21:53

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('hostel_management', '0018_hostelhistory'),
('hostel_management', '0016_hostelleave_remark'),
]

operations = [
]
1 change: 1 addition & 0 deletions FusionIIIT/applications/hostel_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class HostelLeave(models.Model):
start_date = models.DateField(default=timezone.now)
end_date = models.DateField()
status = models.CharField(max_length=20, default='pending')
remark = models.TextField(blank=True, null=True)


def __str__(self):
Expand Down
56 changes: 52 additions & 4 deletions FusionIIIT/applications/hostel_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from rest_framework.exceptions import APIException



from django.shortcuts import render, redirect

from .models import HostelLeave
Expand All @@ -34,6 +35,7 @@
from rest_framework import status



from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
# from .models import HostelStudentAttendance
Expand Down Expand Up @@ -73,6 +75,7 @@
from django.shortcuts import get_object_or_404, redirect, render
from django.db import transaction
from .forms import HallForm
from notification.views import hostel_notifications


def is_superuser(user):
Expand Down Expand Up @@ -706,15 +709,27 @@ def create_hostel_leave(request):
reason = data.get('reason')
start_date = data.get('start_date', timezone.now())
end_date = data.get('end_date')


# Create HostelLeave object and save to the database
leave = HostelLeave.objects.create(
student_name=student_name,
roll_num=roll_num,
reason=reason,
start_date=start_date,
end_date=end_date
end_date=end_date,

)
caretakers = HallCaretaker.objects.all()
sender = request.user
type = "leave_request"
for caretaker in caretakers:
try:
# Send notification
hostel_notifications(sender, caretaker.staff.id.user, type)
except Exception as e:
# Handle notification sending error
print(f"Error sending notification to caretaker {caretaker.staff.user.username}: {e}")

return JsonResponse({'message': 'HostelLeave created successfully'}, status=status.HTTP_201_CREATED)

Expand Down Expand Up @@ -865,7 +880,6 @@ def post(self, request, *args, **kwargs):

# Retrieve the previous caretaker for the hall, if any
prev_hall_caretaker = HallCaretaker.objects.filter(hall=hall).first()
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
# print(prev_hall_caretaker.staff.id)
# Delete any previous assignments of the caretaker in HallCaretaker table
HallCaretaker.objects.filter(staff=caretaker_staff).delete()
Expand Down Expand Up @@ -1018,7 +1032,6 @@ 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)
Expand Down Expand Up @@ -1541,6 +1554,14 @@ def request_guest_room(request):
arrival_date=arrival_date, arrival_time=arrival_time, departure_date=departure_date, departure_time=departure_time, nationality=nationality)
newBooking.save()
messages.success(request, "Room request submitted successfully!")


# Get the caretaker for the selected hall
hall_caretaker = HallCaretaker.objects.get(hall=hall)
caretaker = hall_caretaker.staff.id.user
# Send notification to caretaker
hostel_notifications(sender=request.user, recipient=caretaker, type='guestRoom_request')

return HttpResponseRedirect(reverse("hostelmanagement:hostel_view"))
else:
messages.error(request, "Something went wrong")
Expand Down Expand Up @@ -1576,13 +1597,19 @@ def update_guest_room(request):
guest_room_request.save()
messages.success(request, "Request accepted successfully!")

hostel_notifications(sender=request.user,recipient=guest_room_request.intender,type='guestRoom_accept')


elif 'reject_request' in request.POST:
guest_room_request = GuestRoomBooking.objects.get(
pk=request.POST['reject_request'])
guest_room_request.status = 'Rejected'
guest_room_request.save()

messages.success(request, "Request rejected successfully!")

hostel_notifications(sender=request.user,recipient=guest_room_request.intender,type='guestRoom_reject')

else:
messages.error(request, "Invalid request!")
return HttpResponseRedirect(reverse("hostelmanagement:hostel_view"))
Expand All @@ -1597,8 +1624,18 @@ def update_leave_status(request):
try:
leave = HostelLeave.objects.get(id=leave_id)
leave.status = status
leave.remark = request.POST.get('remark')
leave.save()
return JsonResponse({'status': status, 'message': 'Leave status updated successfully.'})

# Send notification to the student
sender = request.user # Assuming request.user is the caretaker

student_id = leave.roll_num # Assuming student is a foreign key field in HostelLeave model
recipient = User.objects.get(username=student_id)
type = "leave_accept" if status == "Approved" else "leave_reject"
hostel_notifications(sender, recipient, type)

return JsonResponse({'status': status,'remarks':leave.remark,'message': 'Leave status updated successfully.'})
except HostelLeave.DoesNotExist:
return JsonResponse({'status': 'error', 'message': 'Leave not found.'}, status=404)
else:
Expand Down Expand Up @@ -1663,6 +1700,17 @@ def post(self, request):
reason=reason,
hall_id=hall_id
)
# Sending notification to the student about the imposed fine



recipient = User.objects.get(username=student_id)

sender = request.user

type = "fine_imposed"
hostel_notifications(sender, recipient, type)

return HttpResponse({'message': 'Fine imposed successfully.'}, status=status.HTTP_201_CREATED)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework import serializers
from notifications.models import Notification
class NotificationSerializer(serializers.ModelSerializer):
class Meta:
model = Notification
fields = '__all__'
53 changes: 53 additions & 0 deletions FusionIIIT/applications/notifications_extension/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# urls.py
from django.urls import path
from .views import (
LeaveModuleNotificationAPIView,
PlacementCellNotificationAPIView,
AcademicsModuleNotificationAPIView,
OfficeModuleNotificationAPIView,
CentralMessNotificationAPIView,
VisitorsHostelNotificationAPIView,
HealthcareCenterNotificationAPIView,
FileTrackingNotificationAPIView,
ScholarshipPortalNotificationAPIView,
ComplaintSystemNotificationAPIView,
OfficeDeanPnDNotificationAPIView,
OfficeDeanSNotificationAPIView,
GymkhanaVotingNotificationAPIView,
GymkhanaSessionNotificationAPIView,
GymkhanaEventNotificationAPIView,
AssistantshipClaimNotificationAPIView,
DepartmentNotificationAPIView,
OfficeDeanRSPCNotificationAPIView,
ResearchProceduresNotificationAPIView,
HostelModuleNotificationAPIView,
MarkAsRead,
Delete,
NotificationsList,
)

urlpatterns = [
path('notifications/', NotificationsList.as_view(), name='notifications' ),
path('delete/', Delete.as_view(),name='delete'),
path('mark_as_read/', MarkAsRead.as_view(),name='mark_as_read'),
path('leave_module_notification/', LeaveModuleNotificationAPIView.as_view(), name='leave_module_notification'),
path('placement_cell_notification/', PlacementCellNotificationAPIView.as_view(), name='placement_cell_notification'),
path('academics_module_notification/', AcademicsModuleNotificationAPIView.as_view(), name='academics_module_notification'),
path('office_module_notification/', OfficeModuleNotificationAPIView.as_view(), name='office_module_notification'),
path('central_mess_notification/', CentralMessNotificationAPIView.as_view(), name='central_mess_notification'),
path('visitors_hostel_notification/', VisitorsHostelNotificationAPIView.as_view(), name='visitors_hostel_notification'),
path('healthcare_center_notification/', HealthcareCenterNotificationAPIView.as_view(), name='healthcare_center_notification'),
path('file_tracking_notification/', FileTrackingNotificationAPIView.as_view(), name='file_tracking_notification'),
path('scholarship_portal_notification/', ScholarshipPortalNotificationAPIView.as_view(), name='scholarship_portal_notification'),
path('complaint_system_notification/', ComplaintSystemNotificationAPIView.as_view(), name='complaint_system_notification'),
path('office_dean_PnD_notification/', OfficeDeanPnDNotificationAPIView.as_view(), name='office_dean_PnD_notification'),
path('office_dean_S_notification/', OfficeDeanSNotificationAPIView.as_view(), name='office_dean_S_notification'),
path('gymkhana_voting/', GymkhanaVotingNotificationAPIView.as_view(), name='gymkhana_voting'),
path('gymkhana_session/', GymkhanaSessionNotificationAPIView.as_view(), name='gymkhana_session'),
path('gymkhana_event/', GymkhanaEventNotificationAPIView.as_view(), name='gymkhana_event'),
path('assistantship_claim/', AssistantshipClaimNotificationAPIView.as_view(), name='assistantship_claim'),
path('department_notification/', DepartmentNotificationAPIView.as_view(), name='department_notification'),
path('office_dean_RSPC_notification/', OfficeDeanRSPCNotificationAPIView.as_view(), name='office_dean_RSPC_notification'),
path('research_procedures_notification/', ResearchProceduresNotificationAPIView.as_view(), name='research_procedures_notification'),
path('hostel_notifications/', HostelModuleNotificationAPIView.as_view(), name='hostel_notifications'),
]
Loading