11"""View module for handling requests about park areas"""
22import logging
3+ from rest_framework .decorators import action
34from rest_framework import serializers , status
45from rest_framework .viewsets import ViewSet
56from rest_framework .response import Response
89from LearningAPI .utils import GithubRequest
910from LearningAPI .models .people import Cohort , NssUserCohort , NssUser
1011from LearningAPI .models .coursework import StudentProject
11- from LearningAPI .models .people .student_personality import StudentPersonality
1212
1313
1414class Profile (ViewSet ):
1515 """Person can see profile information"""
1616
17+ @action (detail = False , methods = ['put' ])
18+ def change (self , request ):
19+ """Handle PUT requests to profile resource
20+
21+ Returns:
22+ Response -- None
23+ """
24+ first = request .data .get ("firstName" , None )
25+ last = request .data .get ("lastName" , None )
26+
27+ if first is not None and last is not None :
28+ request .auth .user .first_name = first
29+ request .auth .user .last_name = last
30+
31+ request .auth .user .save ()
32+
33+ return Response (None , status = status .HTTP_204_NO_CONTENT )
34+
35+ return Response ({'message' : 'You must provide a \' firstName\' and \' lastName\' in the request body' }, status = status .HTTP_400_BAD_REQUEST )
36+
37+
38+
1739 def list (self , request ):
1840 """Handle GET requests to profile resource
1941
2042 Returns:
2143 Response -- JSON representation of user info
2244 """
23- personality = {}
2445 cohort = self .request .query_params .get ('cohort' , None )
2546 mimic = self .request .query_params .get ('mimic' , None )
2647
@@ -74,7 +95,9 @@ def list(self, request):
7495
7596
7697 if not request .auth .user .is_staff or mimic :
98+ # Check to see if the learner has accepted the invitation to join the cohort Github organization
7799 student_cohort = nss_user .assigned_cohorts .first ()
100+
78101 if not student_cohort .is_github_org_member :
79102 # Send a request to the Github API to check the membership status of the user for the cohort Github organization
80103 gh_request = GithubRequest ()
@@ -90,7 +113,13 @@ def list(self, request):
90113 github_org_membership_status = "active"
91114
92115
93- serializer = ProfileSerializer (nss_user , context = {'request' : request , 'github_status' : github_org_membership_status })
116+ serializer = ProfileSerializer (
117+ nss_user ,
118+ context = {
119+ 'request' : request ,
120+ 'github_status' : github_org_membership_status
121+ }
122+ )
94123 return Response (serializer .data , status = status .HTTP_200_OK )
95124 else :
96125 # Create custom JSON response for instructors
0 commit comments