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
9 changes: 5 additions & 4 deletions FusionIIIT/applications/globals/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

url(r'^auth/login/', views.login, name='login-api'),
url(r'^auth/logout/', views.logout, name='logout-api'),
url(r'^auth/me', views.auth_view, name='auth-api'),
url(r'^update-role/', views.update_last_selected_role, name='update_last_selected_role'),
# generic profile endpoint
#code of corresponding view is modifiedtemporary because of mismatched designations
url(r'^profile/(?P<username>.+)/', views.profile, name='profile-api'),
Expand All @@ -14,9 +16,8 @@
url(r'^profile_update/', views.profile_update, name='update-profile-api'),
url(r'^profile_delete/(?P<id>[0-9]+)/', views.profile_delete, name='delete-profile-api'),

url(r'^dashboard/',views.dashboard,name='dashboard-api'),
url(r'^notification/',views.notification,name='notification'),
url(r'^notification/read',views.NotificationRead,name='notifications-read')


url(r'^notificationread',views.NotificationRead,name='notifications-read'),
url(r'^notificationdelete',views.delete_notification,name='notifications-delete'),
url(r'^notificationunread',views.NotificationUnread,name='notifications-unread')
]
99 changes: 83 additions & 16 deletions FusionIIIT/applications/globals/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from . import serializers
from applications.globals.models import (ExtraInfo, Feedback, HoldsDesignation,
Issue, IssueImage, DepartmentInfo)
Issue, IssueImage, DepartmentInfo, ModuleAccess)
from .utils import get_and_authenticate_user
from notifications.models import Notification

Expand Down Expand Up @@ -71,47 +71,71 @@ def logout(request):
return Response(data=resp, status=status.HTTP_200_OK)

@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def dashboard(request):
@permission_classes([AllowAny])
def auth_view(request):
user=request.user

name = request.user.first_name +"_"+ request.user.last_name

extra_info = get_object_or_404(ExtraInfo, user=user)
last_selected_role = extra_info.last_selected_role

designation_list = list(HoldsDesignation.objects.all().filter(working = request.user).values_list('designation'))
designation_id = [designation for designations in designation_list for designation in designations]
designation_info = []
for id in designation_id :
name_ = get_object_or_404(Designation, id = id)
designation_info.append(str(name_.name))

notifications=serializers.NotificationSerializer(request.user.notifications.all(),many=True).data
club_details= coordinator_club(request)
accessible_modules = {}

for designation in designation_info:
module_access = ModuleAccess.objects.filter(designation=designation).first()
if module_access:
filtered_modules = {}

field_names = [field.name for field in ModuleAccess._meta.get_fields() if field.name not in ['id', 'designation']]

for field_name in field_names:
filtered_modules[field_name] = getattr(module_access, field_name)

accessible_modules[designation] = filtered_modules

resp={
'notifications':notifications,
'desgination_info' : designation_info,
'club_details' : club_details
'designation_info' : designation_info,
'name': name,
'accessible_modules': accessible_modules,
'last_selected_role': last_selected_role
}

return Response(data=resp,status=status.HTTP_200_OK)

@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def notification(request):

print(request)
notifications=serializers.NotificationSerializer(request.user.notifications.all(),many=True).data
print("get")
print(notifications)

resp={
'notifications':notifications,
}

return Response(data=resp,status=status.HTTP_200_OK)

@api_view(['PATCH'])
@permission_classes([IsAuthenticated])
def update_last_selected_role(request):
new_role = request.data.get('last_selected_role')

if new_role is None:
return Response({'error': 'last_selected_role is required'}, status=status.HTTP_400_BAD_REQUEST)

extra_info = get_object_or_404(ExtraInfo, user=request.user)

extra_info.last_selected_role = new_role
extra_info.save()

return Response({'message': 'last_selected_role updated successfully'}, status=status.HTTP_200_OK)

@api_view(['GET'])
def profile(request, username=None):
user = get_object_or_404(User, username=username) if username else request.user
Expand Down Expand Up @@ -306,4 +330,47 @@ def NotificationRead(request):
response ={
'error':'Failed, notification is not marked as seen.'
}
return Response(response,status=status.HTTP_404_NOT_FOUND)
return Response(response,status=status.HTTP_404_NOT_FOUND)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def NotificationUnread(request):
try:
notifId = int(request.data['id'])
user = request.user
notification = get_object_or_404(Notification, recipient=user, id=notifId)
if not notification.unread:
notification.unread = True
notification.save()
response = {
'message': 'Notification successfully marked as unread.'
}
return Response(response, status=status.HTTP_200_OK)
except:
response = {
'error': 'Failed to mark the notification as unread.'
}
return Response(response, status=status.HTTP_404_NOT_FOUND)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def delete_notification(request):
try:
notifId = int(request.data['id'])
notification = get_object_or_404(Notification, recipient=request.user, id=notifId)

notification.deleted = True
notification.save()

response = {
'message': 'Notification marked as deleted.'
}
return Response(response, status=status.HTTP_200_OK)
except Exception as e:
response = {
'error': 'Failed to mark the notification as deleted.',
'details': str(e)
}
return Response(response, status=status.HTTP_400_BAD_REQUEST)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 3.1.5 on 2024-10-07 23:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('globals', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='ModuleAccess',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('designation', models.CharField(max_length=155)),
('program_and_curriculum', models.BooleanField(default=False)),
('course_registration', models.BooleanField(default=False)),
('course_management', models.BooleanField(default=False)),
('other_academics', models.BooleanField(default=False)),
('spacs', models.BooleanField(default=False)),
('department', models.BooleanField(default=False)),
('examinations', models.BooleanField(default=False)),
('hr', models.BooleanField(default=False)),
('iwd', models.BooleanField(default=False)),
('complaint_management', models.BooleanField(default=False)),
('fts', models.BooleanField(default=False)),
('purchase_and_store', models.BooleanField(default=False)),
('rspc', models.BooleanField(default=False)),
('hostel_management', models.BooleanField(default=False)),
('mess_management', models.BooleanField(default=False)),
('gymkhana', models.BooleanField(default=False)),
('placement_cell', models.BooleanField(default=False)),
('visitor_hostel', models.BooleanField(default=False)),
('phc', models.BooleanField(default=False)),
],
),
migrations.AddField(
model_name='extrainfo',
name='last_selected_role',
field=models.CharField(blank=True, max_length=20, null=True),
),
]
1 change: 1 addition & 0 deletions FusionIIIT/applications/globals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class ExtraInfo(models.Model):
null=True, blank=True, upload_to='globals/profile_pictures')
about_me = models.TextField(default='NA', max_length=1000, blank=True)
date_modified = models.DateTimeField('date_updated', blank=True, null=True)
last_selected_role = models.CharField(max_length=20, null=True, blank=True)

@property
def age(self):
Expand Down
Loading