Пример #1
0
 def read(self, request, message_id=None, talk_id=None, start=None, count=None):
     """List all messages for a talk, or a specific message.
     
     """
     if message_id == "count":
         try:
             return self.lib.list_messages(request.user, talk_id).count()
         except exceptions.InvalidUser:
             return rc.FORBIDDEN
     elif message_id is not None:
         try:
             message = Message.objects.get(id=talk_id)
             user = request.user
             if message.talk.from_user.id != user.id and message.talk.trip.user.id != user.id:
                 return rc.NOT_HERE
             else:
                 return message
         except (Message.DoesNotExist):
             return rc.NOT_HERE
     else:
         try:
             items = self.lib.list_messages(request.user, talk_id)
             return paginate_items(items, start, count, request, self.count)
         except exceptions.TalkDoesNotExist:
             return rc.NOT_HERE
Пример #2
0
 def read(self, request, trip_id=None, start=None, count=None):
     if trip_id == 'count_mine':
         return self.lib.list_trips_by_user(request.user).count()
     if trip_id == 'mine':
         items = self.lib.list_trips_by_user(request.user)
         return paginate_items(items, start, count, request, self.count)
     return self.anonymous.read(AnonymousTripsHandler(), request, trip_id, start, count)
Пример #3
0
 def read(self, request, trip_id=None, start=None, count=None):
     if trip_id == 'count_mine':
         return self.lib.list_trips_by_user(request.user).count()
     if trip_id == 'mine':
         items = self.lib.list_trips_by_user(request.user)
         return paginate_items(items, start, count, request, self.count)
     return self.anonymous.read(AnonymousTripsHandler(), request, trip_id, start, count)
Пример #4
0
 def read(self,
          request,
          message_id=None,
          talk_id=None,
          start=None,
          count=None):
     """List all messages for a talk, or a specific message.
     
     """
     if message_id == "count":
         try:
             return self.lib.list_messages(request.user, talk_id).count()
         except exceptions.InvalidUser:
             return rc.FORBIDDEN
     elif message_id is not None:
         try:
             message = Message.objects.get(id=talk_id)
             user = request.user
             if (message.talk.from_user.id != user.id
                     and message.talk.trip.user.id != user.id):
                 return rc.NOT_HERE
             else:
                 return message
         except (Message.DoesNotExist):
             return rc.NOT_HERE
     else:
         try:
             items = self.lib.list_messages(request.user, talk_id)
             return paginate_items(items, start, count, request, self.count)
         except exceptions.TalkDoesNotExist:
             return rc.NOT_HERE
Пример #5
0
 def read(self, request, trip_id=None, start=None, count=None):
     if trip_id == 'count':
         return self.lib.list_trips().count()
     elif trip_id:
         return self.lib.get_trip(trip_id)
     else:
         items = self.lib.list_trips()
     return paginate_items(items, start, count, request, self.count)
Пример #6
0
 def read(self, request, trip_id=None, start=None, count=None):
     if trip_id == 'count':
         return self.lib.list_trips().count()
     elif trip_id:
         return self.lib.get_trip(trip_id)
     else:
         items = self.lib.list_trips()
     return paginate_items(items, start, count, request, self.count)
Пример #7
0
    def read(self, request, talk_id=None, start=None, count=None):
        """List all talks for the authenticated user
        
        """
        if 'trip_id' in request.GET:
            # get the trip
            talks = Talk.objects.filter(Q(trip__id=request.GET['trip_id']) 
                & (Q(trip__user__id=request.user.id) | 
                        Q(from_user__id=request.user.id)))
            return talks

        if talk_id == 'count':
            return self.lib.list_talks(request.user).count()
        elif talk_id is not None:
            talk = Talk.objects.get(id=talk_id)
            user = request.user
            if (talk.from_user.id != user.id and talk.trip.user.id != user.id):
                return rc.FORBIDDEN
            return talk;
        else:
            items = self.lib.list_talks(request.user)
            return paginate_items(items, start, count, request, self.count)
Пример #8
0
    def read(self, request, talk_id=None, start=None, count=None):
        """List all talks for the authenticated user
        
        """
        if 'trip_id' in request.GET:
            # get the trip
            talks = Talk.objects.filter(
                Q(trip__id=request.GET['trip_id'])
                & (Q(trip__user__id=request.user.id)
                   | Q(from_user__id=request.user.id)))
            return talks

        if talk_id == 'count':
            return self.lib.list_talks(request.user).count()
        elif talk_id is not None:
            talk = Talk.objects.get(id=talk_id)
            user = request.user
            if (talk.from_user.id != user.id and talk.trip.user.id != user.id):
                return rc.FORBIDDEN
            return talk
        else:
            items = self.lib.list_talks(request.user)
            return paginate_items(items, start, count, request, self.count)