diff --git a/FusionIIIT/applications/department/views.py b/FusionIIIT/applications/department/views.py index ef7e71c64..f138c77db 100644 --- a/FusionIIIT/applications/department/views.py +++ b/FusionIIIT/applications/department/views.py @@ -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, @@ -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, diff --git a/FusionIIIT/applications/globals/migrations/0015_auto_20240315_2100.py b/FusionIIIT/applications/globals/migrations/0015_auto_20240315_2100.py new file mode 100644 index 000000000..223656449 --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0015_auto_20240315_2100.py @@ -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), + ), + ] diff --git a/FusionIIIT/applications/globals/migrations/0018_auto_20240315_2157.py b/FusionIIIT/applications/globals/migrations/0018_auto_20240315_2157.py new file mode 100644 index 000000000..ea6caf787 --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0018_auto_20240315_2157.py @@ -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), + ), + ] diff --git a/FusionIIIT/applications/globals/migrations/0019_merge_20240315_2153.py b/FusionIIIT/applications/globals/migrations/0019_merge_20240315_2153.py new file mode 100644 index 000000000..742ec09cd --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0019_merge_20240315_2153.py @@ -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 = [ + ] diff --git a/FusionIIIT/applications/globals/migrations/0020_auto_20240315_2158.py b/FusionIIIT/applications/globals/migrations/0020_auto_20240315_2158.py new file mode 100644 index 000000000..d7d37f5d2 --- /dev/null +++ b/FusionIIIT/applications/globals/migrations/0020_auto_20240315_2158.py @@ -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), + ), + ] diff --git a/FusionIIIT/applications/hostel_management/migrations/0016_hostelleave_remark.py b/FusionIIIT/applications/hostel_management/migrations/0016_hostelleave_remark.py new file mode 100644 index 000000000..402af32bf --- /dev/null +++ b/FusionIIIT/applications/hostel_management/migrations/0016_hostelleave_remark.py @@ -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), + ), + ] diff --git a/FusionIIIT/applications/hostel_management/migrations/0019_merge_20240315_2153.py b/FusionIIIT/applications/hostel_management/migrations/0019_merge_20240315_2153.py new file mode 100644 index 000000000..8beebe6f8 --- /dev/null +++ b/FusionIIIT/applications/hostel_management/migrations/0019_merge_20240315_2153.py @@ -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 = [ + ] diff --git a/FusionIIIT/applications/hostel_management/models.py b/FusionIIIT/applications/hostel_management/models.py index df18d5959..1108f573a 100644 --- a/FusionIIIT/applications/hostel_management/models.py +++ b/FusionIIIT/applications/hostel_management/models.py @@ -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): diff --git a/FusionIIIT/applications/hostel_management/views.py b/FusionIIIT/applications/hostel_management/views.py index 48fe23805..1ec972b63 100644 --- a/FusionIIIT/applications/hostel_management/views.py +++ b/FusionIIIT/applications/hostel_management/views.py @@ -19,6 +19,7 @@ from rest_framework.exceptions import APIException + from django.shortcuts import render, redirect from .models import HostelLeave @@ -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 @@ -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): @@ -706,6 +709,7 @@ 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( @@ -713,8 +717,19 @@ def create_hostel_leave(request): 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) @@ -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() @@ -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) @@ -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") @@ -1576,6 +1597,9 @@ 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']) @@ -1583,6 +1607,9 @@ def update_guest_room(request): 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")) @@ -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: @@ -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) diff --git a/FusionIIIT/applications/notifications_extension/api/serializers.py b/FusionIIIT/applications/notifications_extension/api/serializers.py new file mode 100644 index 000000000..899c50e57 --- /dev/null +++ b/FusionIIIT/applications/notifications_extension/api/serializers.py @@ -0,0 +1,6 @@ +from rest_framework import serializers +from notifications.models import Notification +class NotificationSerializer(serializers.ModelSerializer): + class Meta: + model = Notification + fields = '__all__' \ No newline at end of file diff --git a/FusionIIIT/applications/notifications_extension/api/urls.py b/FusionIIIT/applications/notifications_extension/api/urls.py new file mode 100644 index 000000000..62238c007 --- /dev/null +++ b/FusionIIIT/applications/notifications_extension/api/urls.py @@ -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'), +] diff --git a/FusionIIIT/applications/notifications_extension/api/views.py b/FusionIIIT/applications/notifications_extension/api/views.py new file mode 100644 index 000000000..b9147cd07 --- /dev/null +++ b/FusionIIIT/applications/notifications_extension/api/views.py @@ -0,0 +1,371 @@ +# views.py +from rest_framework.views import APIView +from django.contrib.auth import get_user_model +from rest_framework.response import Response +from notifications.utils import slug2id +from django.shortcuts import get_object_or_404 +from rest_framework.generics import ListAPIView +from notifications.models import Notification +from rest_framework import status +from .serializers import NotificationSerializer +from notification.views import (leave_module_notif, + placement_cell_notif, + academics_module_notif, + office_module_notif, + central_mess_notif, + visitors_hostel_notif, + healthcare_center_notif, + file_tracking_notif, + scholarship_portal_notif, + complaint_system_notif, + office_dean_PnD_notif, + office_module_DeanS_notif, + gymkhana_voting, + gymkhana_session, + gymkhana_event, + AssistantshipClaim_notify, + AssistantshipClaim_faculty_notify, + AssistantshipClaim_acad_notify, + AssistantshipClaim_account_notify, + department_notif, + office_module_DeanRSPC_notif, + research_procedures_notif, + hostel_notifications) + +# import user + +class LeaveModuleNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + date = request.data.get('date') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + leave_module_notif(sender, recipient, type, date) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class PlacementCellNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + placement_cell_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class AcademicsModuleNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + academics_module_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class OfficeModuleNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + office_module_notif(sender, recipient) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) +class CentralMessNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + message = request.data.get('message') + + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + + # Trigger the notification function + central_mess_notif(sender, recipient, type, message) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class VisitorsHostelNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + visitors_hostel_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class HealthcareCenterNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + + # Trigger the notification function + healthcare_center_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class FileTrackingNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + title = request.data.get('title') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + file_tracking_notif(sender, recipient, title) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) +class ScholarshipPortalNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + scholarship_portal_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class ComplaintSystemNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + complaint_id = request.data.get('complaint_id') + student = request.data.get('student') + message = request.data.get('message') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + complaint_system_notif(sender, recipient, type, complaint_id, student, message) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class OfficeDeanPnDNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + office_dean_PnD_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class OfficeDeanSNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + office_module_DeanS_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class GymkhanaVotingNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + title = request.data.get('title') + desc = request.data.get('desc') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + gymkhana_voting(sender, recipient, type, title, desc) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class GymkhanaSessionNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + club = request.data.get('club') + desc = request.data.get('desc') + venue = request.data.get('venue') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + gymkhana_session(sender, recipient, type, club, desc, venue) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class GymkhanaEventNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + club = request.data.get('club') + event_name = request.data.get('event_name') + desc = request.data.get('desc') + venue = request.data.get('venue') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + gymkhana_event(sender, recipient, type, club, event_name, desc, venue) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class AssistantshipClaimNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + month = request.data.get('month') + year = request.data.get('year') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + AssistantshipClaim_notify(sender, recipient, month, year) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) +class AssistantshipClaimFacultyNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + AssistantshipClaim_faculty_notify(sender, recipient) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class AssistantshipClaimAcadNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + AssistantshipClaim_acad_notify(sender, recipient) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class AssistantshipClaimAccountNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + stu = request.data.get('stu') + recipient_id = request.data.get('recipient') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + AssistantshipClaim_account_notify(sender, stu, recipient) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class DepartmentNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + department_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) +class OfficeDeanRSPCNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + office_module_DeanRSPC_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class ResearchProceduresNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + research_procedures_notif(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class HostelModuleNotificationAPIView(APIView): + def post(self, request, *args, **kwargs): + # Extract data from the request, you can customize this based on your needs + sender = request.user + recipient_id = request.data.get('recipient') + type = request.data.get('type') + User = get_user_model() + recipient = User.objects.get(pk=recipient_id) + # Trigger the notification function + hostel_notifications(sender, recipient, type) + + return Response({'message': 'Notification sent successfully'}, status=status.HTTP_201_CREATED) + +class MarkAsRead(APIView): + + def put(self,request,**args): + notification_id = self.request.query_params.get('id') + notification = get_object_or_404( + Notification, recipient=request.user, id=notification_id) + + notification.mark_as_read() + + return Response({'message': "Successfully marked as read"}, status=status.HTTP_200_OK) + +class Delete(APIView): + + def delete(self,request, **args): + notification_id = self.request.query_params.get('id') + notification = get_object_or_404( + Notification, recipient=request.user, id=notification_id) + + notification.delete() + + return Response({'message': "Notification deleted succesfully"}, status=status.HTTP_200_OK) + +class NotificationsList(ListAPIView): + # queryset = Notification.objects.all(actor_object_id=) + serializer_class = NotificationSerializer + def get_queryset(self): + return Notification.objects.all().filter(recipient_id=self.request.user.id) \ No newline at end of file diff --git a/FusionIIIT/applications/notifications_extension/urls.py b/FusionIIIT/applications/notifications_extension/urls.py index c5b2da49d..b5690994b 100644 --- a/FusionIIIT/applications/notifications_extension/urls.py +++ b/FusionIIIT/applications/notifications_extension/urls.py @@ -4,8 +4,12 @@ from django.conf.urls import include, url from . import views +# from .api import urls + app_name = 'notifications' urlpatterns = [ pattern(r'^mark-as-read-and-redirect/(?P\d+)/$', views.mark_as_read_and_redirect, name='mark_as_read_and_redirect'), + pattern(r'^delete/(?P\d+)/$', views.delete, name='delete'), + url(r'^api/',include('applications.notifications_extension.api.urls')), ] + urlpatterns diff --git a/FusionIIIT/applications/notifications_extension/views.py b/FusionIIIT/applications/notifications_extension/views.py index fc482ef77..57142f0a6 100644 --- a/FusionIIIT/applications/notifications_extension/views.py +++ b/FusionIIIT/applications/notifications_extension/views.py @@ -3,9 +3,14 @@ from notifications.utils import id2slug, slug2id from django.shortcuts import get_object_or_404, redirect from notifications.models import Notification - - - +import Fusion.settings as FusionIIIT_settings +def delete(request, slug=None): + notification_id = slug2id(slug) + notification = get_object_or_404( + Notification, recipient=request.user, id=notification_id) + notification.delete() + return HttpResponseRedirect('/') + # return HttpResponseRedirect('dashboard/') def mark_as_read_and_redirect(request, slug=None): notification_id = slug2id(slug) notification = get_object_or_404( @@ -14,8 +19,9 @@ def mark_as_read_and_redirect(request, slug=None): # This conditional statement is True only in # case of complaint_module. + # return redirect('notifications:all') - if(notification.data['module'] == 'Complaint System'): + if(notification.data['module'] == 'Complaint System'): complaint_id=notification.description return HttpResponseRedirect(reverse(notification.data['url'],kwargs={'detailcomp_id1':complaint_id})) else: diff --git a/FusionIIIT/notification/views.py b/FusionIIIT/notification/views.py index 0480575b8..eb44d474b 100644 --- a/FusionIIIT/notification/views.py +++ b/FusionIIIT/notification/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render +from requests import Response from notifications.signals import notify # Create your views here. @@ -69,6 +70,7 @@ def central_mess_notif(sender, recipient, type, message=None): sender = sender recipient = recipient verb = '' + if type == 'feedback_submitted': verb = 'Your feedback has been successfully submitted.' elif type == 'menu_change_accepted': @@ -125,8 +127,6 @@ def healthcare_center_notif(sender, recipient, type): if type == 'amb_req': verb = "You have a new ambulance request" - - notify.send(sender=sender, recipient=recipient, url=url, module=module, verb=verb) @@ -336,7 +336,21 @@ def department_notif(sender, recipient, type): sender = sender recipient = recipient verb = type - flag = "department" + flag = "announcement" + + notify.send(sender=sender, + recipient=recipient, + url=url, + module=module, + verb=verb, + flag=flag) +def examination_notif(sender, recipient, type): + url='examination:examination' + module='examination' + sender = sender + recipient = recipient + verb = type + flag = "announcement" notify.send(sender=sender, recipient=recipient, @@ -384,4 +398,28 @@ def research_procedures_notif(sender,recipient,type): elif type == "created": verb = "A new Patent has been Created" + notify.send(sender=sender,recipient=recipient,url=url,module=module,verb=verb) + +def hostel_notifications(sender, recipient, type): + url = 'hostelmanagement:hostel_view' + module = 'Hostel Management' + + sender = sender + recipient = recipient + verb = "" + if type == "leave_accept": + verb = "Your leave request has been Accepted." + elif type == "leave_reject": + verb = "Your leave request has been Rejected." + elif type == "guestRoom_accept": + verb = "Your Guest Room request has been Accepted." + elif type == "guestRoom_reject": + verb = "Your Guest Room request has been Rejected." + elif type == "leave_request": + verb = "You have a new Leave Request." + elif type == "guestRoom_request": + verb = "You have a new Guest Room Request." + elif type == "fine_imposed": + verb = "A fine has been imposed on you." + notify.send(sender=sender,recipient=recipient,url=url,module=module,verb=verb) \ No newline at end of file diff --git a/FusionIIIT/templates/dashboard/alerts.html b/FusionIIIT/templates/dashboard/alerts.html index b63276ecd..34090dd45 100755 --- a/FusionIIIT/templates/dashboard/alerts.html +++ b/FusionIIIT/templates/dashboard/alerts.html @@ -5,7 +5,7 @@
{% for notice in notifications %} {% comment %}A single notification starts here!{% endcomment %} - {% ifnotequal notice.data.flag "department" %} + {% ifnotequal notice.data.flag "announcement" %} {% if notice.unread %}
{% else %} @@ -14,6 +14,9 @@
{{ notice.timesince }} ago @@ -51,10 +54,10 @@ var status = document.getElementById("notif-sp"+id).innerHTML; var url; if(status=="Mark as Unread"){ - url = '{% url 'notifications:mark_as_unread' 0 %}'.replace('0', slug); + url = `{% url 'notifications:mark_as_unread' 0 %}`.replace('0', slug); } else{ - url = '{% url 'notifications:mark_as_read' 0 %}'.replace('0', slug); + url = `{% url 'notifications:mark_as_read' 0 %}`.replace('0', slug); } $.ajax( { diff --git a/FusionIIIT/templates/dashboard/alerts1.html b/FusionIIIT/templates/dashboard/alerts1.html index e2844039f..ae78bdebd 100644 --- a/FusionIIIT/templates/dashboard/alerts1.html +++ b/FusionIIIT/templates/dashboard/alerts1.html @@ -14,6 +14,9 @@
{{ notice.timesince }} ago @@ -27,7 +30,6 @@ {% endifnotequal %}
- {% if notice.unread %}
Mark as Read
@@ -55,10 +57,10 @@ var status = document.getElementById("notif-sp"+id).innerHTML; var url; if(status=="Mark as Unread"){ - url = '{% url 'notifications:mark_as_unread' 0 %}'.replace('0', slug); + url = `{% url 'notifications:mark_as_unread' 0 %}`.replace('0', slug); } else{ - url = '{% url 'notifications:mark_as_read' 0 %}'.replace('0', slug); + url = `{% url 'notifications:mark_as_read' 0 %}`.replace('0', slug); } $.ajax( { diff --git a/FusionIIIT/templates/hostelmanagement/all_leave_data.html b/FusionIIIT/templates/hostelmanagement/all_leave_data.html index 486896342..485a5f912 100644 --- a/FusionIIIT/templates/hostelmanagement/all_leave_data.html +++ b/FusionIIIT/templates/hostelmanagement/all_leave_data.html @@ -1,6 +1,6 @@ {% block leave_requests %} -

All Leave Requests

-
+

All Leave Requests

+
@@ -11,11 +11,11 @@

All Leave Requests

+ {% for leave in all_leaves %} - @@ -23,58 +23,91 @@

All Leave Requests

- + - {% endfor %}
End Date Status ActionsRemark
{{ leave.student_name }} {{ leave.roll_num }} {{ leave.start_date }} {{ leave.end_date }} {{ leave.status }} + + + +
+ {% csrf_token %} + {%if leave.status == 'pending' %} + {%endif%}
{% csrf_token %} - + +
+ + +
{{leave.remark}}
-
- +
+ + + + }); + {% endblock %} \ No newline at end of file diff --git a/FusionIIIT/templates/hostelmanagement/create_leave.html b/FusionIIIT/templates/hostelmanagement/create_leave.html index 99d4fe7bc..1e989c34d 100644 --- a/FusionIIIT/templates/hostelmanagement/create_leave.html +++ b/FusionIIIT/templates/hostelmanagement/create_leave.html @@ -1,65 +1,78 @@ {% block create_leave %} -

Leave Form

-
- {% csrf_token %} -
+

Leave Form

+ + {% csrf_token %} +
-

-
-
+

+
+


-
-
+
+


-
-
+
+
-

-
-
+

+
+
-

-
-
- -
- - + {% endblock %} \ No newline at end of file diff --git a/FusionIIIT/templates/hostelmanagement/my_leaves.html b/FusionIIIT/templates/hostelmanagement/my_leaves.html index 662050e11..6b12edc2d 100644 --- a/FusionIIIT/templates/hostelmanagement/my_leaves.html +++ b/FusionIIIT/templates/hostelmanagement/my_leaves.html @@ -1,6 +1,6 @@ {% block leave_status %} -

My Leaves

-
+

My Leaves

+
@@ -9,6 +9,7 @@

My Leaves

+ @@ -22,24 +23,26 @@

My Leaves

class="{% if leave.status == 'Approved' %}approved-status{% elif leave.status == 'Rejected' %}rejected-status{% elif leave.status == 'pending' %}pending-status{%endif%}"> {{ leave.status }} + {% endfor %}
Start Date End Date StatusRemark
{{ leave.remark }}
-
- -{% endblock %} +
+ +{% endblock %} \ No newline at end of file