Beispiel #1
0
 def _readunauthorized(self, request, user_nickname):
     '''
     Unauthorized user can't see email address.
     Return 200 on success.
     Return 404 if user doesn't exist.
     '''
     #Use the database to extract a user information. Use the method 
     #database.get_user(user_nickname) to obtain a UserModel
     usermodel = database.get_user(user_nickname)
     #If the database returns None return 404 not Found
     if usermodel is None:
         return Response(status=status.HTTP_404_NOT_FOUND)
     #Get the url of the users resource
     uritousers = reverse("users", request=request)
     
     #Create the response body output. 
     output = {}
     
     user = {'user_nickname':usermodel.user_nickname,
                    'picture':usermodel.picture,
                    'description':str(usermodel.description)}
     users = {'rel':'self', 'href':uritousers}
     output = {"users":users, "user":user}
     
     _commentsurl = reverse("user_comments", (user_nickname,), request=request)
     _tablaturesurl = reverse("user_tablatures", (user_nickname,), request=request)
     
     output['comments'] = {'rel':'self', 'href':_commentsurl}
     output['tablatures'] = {'rel':'self', 'href':_tablaturesurl}
     
     return Response(output, status=status.HTTP_200_OK)
Beispiel #2
0
    def _readauthorized(self, request, user_nickname):
        '''
        Authorized user or admin can see email.
        Return 200 on success.
        '''
        usermodel = database.get_user(user_nickname)
        
        if usermodel is None:
            return Response(status=status.HTTP_404_NOT_FOUND)
        #Get the url of the users resource
        uritousers = reverse("users", request=request)
        #Get the url of this user history resource
        #Create the response body output. 
        output = {}

        users = {'rel':'self', 'href':uritousers}
        output['user'] = usermodel.serialize()
        output['users'] = users
        _commentsurl = reverse("user_comments", (user_nickname,), request=request)
        _tablaturesurl = reverse("user_tablatures", (user_nickname,), request=request)
        
        output['comments'] = {'rel':'self', 'href':_commentsurl}
        output['tablatures'] = {'rel':'self', 'href':_tablaturesurl}
       
            
        return Response(output, status=status.HTTP_200_OK)