예제 #1
0
    def get (self, request, tablature_id):
        '''
        Get tablature by id.
        Returns 404 if doesn't exist or 200 on success.
        '''
        #GET return the tablature which tablature id is tablature_id
        #Get the model
        tablaturemodel = database.get_tablature(tablature_id)
        if tablaturemodel is None:
            error = ErrorModel("The tablature "+ tablature_id+
                               " is not in the archive").serialize()
            return Response(error, status=status.HTTP_404_NOT_FOUND)

        #Serialize and modify the result so the sender is linked to its url
        tablature = tablaturemodel.serialize()
        #print tablature
        #Modify the sender so it includes the URL of the sender:
        #From sender:"Axel" => I create sender:{'user_nickname':'Axel','link':{'rel':'self','href'=:'http://tab_archive/users/Axel'}}
        #senderurl = "http://localhost:8000/tab_archive/users/"+tablature['user_nickname']
        if tablature['user_nickname'] is not None:
            senderurl = reverse("user",(tablature['user_nickname'],), request=request)
            tablature['link'] = {'rel':'self','href':senderurl}
        commentsurl = reverse("tablaturecomments", (tablature_id,), request=request)
        tablature["comments"] = {'rel':'self','href':commentsurl}
        return Response(tablature, status=status.HTTP_200_OK)    
예제 #2
0
 def _modifyisauthorized(self, tablature_id, authorization): 
     '''
     Check that user is allowed to modify tablature.
     '''
     tablaturemodel = database.get_tablature(tablature_id)
     user_nickname = tablaturemodel.user_nickname
     if authorization is not None and (authorization.lower() == "admin" or 
                                       authorization.lower() == user_nickname.lower()):
         return True
     return False