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/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..1b420e336 --- /dev/null +++ b/FusionIIIT/applications/notifications_extension/api/urls.py @@ -0,0 +1,51 @@ +# 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, + 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'), +] diff --git a/FusionIIIT/applications/notifications_extension/api/views.py b/FusionIIIT/applications/notifications_extension/api/views.py new file mode 100644 index 000000000..1ed9fe720 --- /dev/null +++ b/FusionIIIT/applications/notifications_extension/api/views.py @@ -0,0 +1,357 @@ +# 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) + +# 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 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<slug>\d+)/$', views.mark_as_read_and_redirect, name='mark_as_read_and_redirect'), + pattern(r'^delete/(?P<slug>\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..cf55aabcb 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,5 @@ 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) \ No newline at end of file + notify.send(sender=sender,recipient=recipient,url=url,module=module,verb=verb) + diff --git a/FusionIIIT/templates/dashboard/alerts.html b/FusionIIIT/templates/dashboard/alerts.html index b63276ecd..42edc5df7 100755 --- a/FusionIIIT/templates/dashboard/alerts.html +++ b/FusionIIIT/templates/dashboard/alerts.html @@ -5,7 +5,7 @@ <div class="ui one cards" style="padding: 2px"> {% for notice in notifications %} {% comment %}A single notification starts here!{% endcomment %} - {% ifnotequal notice.data.flag "department" %} + {% ifnotequal notice.data.flag "announcement" %} {% if notice.unread %} <div class="ui blue card" id="notif{{notice.id}}"> {% else %} @@ -14,6 +14,9 @@ <div class="content"> <div class="header"> <a href="{% url 'notifications:mark_as_read_and_redirect' notice.slug %}"> {{ notice.data.module }} </a> + <div class="ui right floated white button notif-status" style="background:white"> + <a href="{% url 'notifications:delete' notice.slug %}" style="color:black" > ✖</a> + </div> </div> <div class="meta"> {{ notice.timesince }} ago diff --git a/FusionIIIT/templates/dashboard/alerts1.html b/FusionIIIT/templates/dashboard/alerts1.html index e2844039f..442570f29 100644 --- a/FusionIIIT/templates/dashboard/alerts1.html +++ b/FusionIIIT/templates/dashboard/alerts1.html @@ -14,6 +14,9 @@ <div class="content"> <div class="header"> <a href="{% url 'notifications:mark_as_read_and_redirect' notice.slug %}"> {{ notice.data.module }} </a> + <div class="ui right floated white button notif-status" style="background:white"> + <a href="{% url 'notifications:delete' notice.slug %}" style="color:black" > ✖</a> + </div> </div> <div class="meta"> {{ notice.timesince }} ago @@ -27,7 +30,6 @@ {% endifnotequal %} </div> - {% if notice.unread %} <div class="ui right floated blue button notif-status" id="notif-status{{notice.id}}" notif-id="{{notice.id}}" slug="{{notice.slug}}"> <div id="notif-sp{{notice.id}}">Mark as Read</div>