Ejemplo n.º 1
0
    def get(self, request):
        """
        Generate a new favorite if the search in db return nothing.
        If the db return something this favorite is deleted.
        """

        username = request.GET["username"]
        line_number = request.GET["line_number"]

        user = BusinemeUser.objects.get(username=username)
        busline = Busline.objects.get(line_number=line_number)
        try:
            favorite = Favorite.objects.get(user=user, busline=busline)
            favorite.delete()
            json_data = serialize(favorite)
        except Favorite.DoesNotExist:
            message = ReturnMessage()
            new_favorite = Favorite()

            new_favorite.user = user
            new_favorite.busline = busline
            new_favorite.save()
            json_data = message.return_message(STATUS_NOT_FOUND)

        return JsonResponse(json_data, content_type="application/json")
Ejemplo n.º 2
0
    def get_user(self, user_id):
        """Return a user given a id"""

        try:
            user = BusinemeUser.objects.get(pk=user_id)
            json_data = serialize(user)
        except BusinemeUser.DoesNotExist:
            message = ReturnMessage()
            json_data = message.return_message(STATUS_NOT_FOUND)

        return JsonResponse(json_data, content_type='application/json')
Ejemplo n.º 3
0
 def get_busline(self, busline_id):
     """
     Obtains the required busline based in line's number.
     """
     try:
         busline = Busline.objects.get(pk=busline_id)
         json_data = serialize(busline)
     except Busline.DoesNotExist:
         message = ReturnMessage()
         json_data = message.return_message(STATUS_NOT_FOUND)
     return JsonResponse(json_data, content_type="application/json")
Ejemplo n.º 4
0
    def get_user(self, user_id):
        """Return a user given a id"""

        try:
            user = BusinemeUser.objects.get(pk=user_id)
            json_data = serialize(user)
        except BusinemeUser.DoesNotExist:
            message = ReturnMessage()
            json_data = message.return_message(STATUS_NOT_FOUND)

        return JsonResponse(json_data, content_type='application/json')
Ejemplo n.º 5
0
    def get_post(self, post_id):
        """
        Obtains the required terminal based in line's number.
        """

        try:
            post = Post.objects.get(pk=post_id)
            json_data = serialize(post)
        except Post.DoesNotExist:
            message = ReturnMessage()
            json_data = message.return_message(STATUS_NOT_FOUND)
        return JsonResponse(json_data, content_type="application/json")