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
3 changes: 2 additions & 1 deletion FusionIIIT/applications/globals/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
url(r'^auth/login/', views.login, name='login-api'),
url(r'^auth/logout/', views.logout, name='logout-api'),
# generic profile endpoint
#code of corresponding view is modifiedtemporary because of mismatched designations
url(r'^profile/(?P<username>.+)/', views.profile, name='profile-api'),
# current user profile
url(r'^profile/', views.profile, name='profile-api'),
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')


]
50 changes: 43 additions & 7 deletions FusionIIIT/applications/globals/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@


from . import serializers

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

Expand All @@ -30,10 +31,33 @@ def login(request):
serializer.is_valid(raise_exception=True)
user = get_and_authenticate_user(**serializer.validated_data)
data = serializers.AuthUserSerializer(user).data
print(user.id)
desig = list(HoldsDesignation.objects.select_related('user','working','designation').all().filter(working = user).values_list('designation'))
print(desig)
b = [i for sub in desig for i in sub]
design = HoldsDesignation.objects.select_related('user','designation').filter(working=user)

designation=[]



designation.append(str(user.extrainfo.user_type))
for i in design:
if str(i.designation) != str(user.extrainfo.user_type):
print('-------')
print(i.designation)
print(user.extrainfo.user_type)
print('')
designation.append(str(i.designation))
for i in designation:
print(i)


resp = {
'success' : 'True',
'message' : 'User logged in successfully',
'token' : data['auth_token']
'token' : data['auth_token'],
'designations':designation
}
return Response(data=resp, status=status.HTTP_200_OK)

Expand Down Expand Up @@ -71,14 +95,27 @@ def dashboard(request):

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(['GET'])
def profile(request, username=None):
user = get_object_or_404(User, username=username) if username else request.user
user_detail = serializers.UserSerializer(user).data
profile = serializers.ExtraInfoSerializer(user.extrainfo).data

print(user)

if profile['user_type'] == 'student':
student = user.extrainfo.student
skills = serializers.HasSerializer(student.has_set.all(),many=True).data
Expand All @@ -105,7 +142,6 @@ def profile(request, username=None):
}
return Response(data=resp, status=status.HTTP_200_OK)
elif profile['user_type'] == 'faculty':
print(username)
return redirect('/eis/api/profile/' + (username+'/' if username else ''))

@api_view(['PUT'])
Expand Down Expand Up @@ -259,4 +295,4 @@ 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)