Ejemplo n.º 1
0
    def get_status(self, obj):
        # https://django-geonyoon.c9users.io/api/user/gun/?limit=5 ---> use like this
        request = self.context.get('request')
        limit = 10
        if request:
            limit_query = request.GET.get('limit')
            try:
                limit = int(limit_query)
            except:
                pass

        qs = obj.status_set.all().order_by("-timestamp")
        data = {
            'uri':
            self.get_uri(obj) + "status/",
            'last':
            StatusInlineUserSerializer(qs.first(),
                                       context={
                                           'request': request
                                       }).data,
            'recent':
            StatusInlineUserSerializer(qs[:limit],
                                       context={
                                           'request': request
                                       },
                                       many=True).data
        }
        return data
Ejemplo n.º 2
0
    def get_status(self, obj):
        request = self.context.get('request')
        limit = 10  # default limit
        if request:
            limit_query = request.GET.get('limit')
            try:
                limit = int(limit_query)
            except:
                pass

        qs = obj.status_set.all().order_by("-timestamp")  # [:10]
        data = {
            'uri':
            self.get_uri(obj) + "status/",
            'last':
            StatusInlineUserSerializer(qs.first(),
                                       context={
                                           'request': request
                                       }).data,
            # 'recent': StatusInlineUserSerializer(qs[:10], many=True).data
            'recent':
            StatusInlineUserSerializer(qs[:limit],
                                       context={
                                           'request': request
                                       },
                                       many=True).data
        }
        return data
Ejemplo n.º 3
0
    def get_status(self, obj):
        request = self.context.get('request')
        limit = 5

        if request:
            #endpoint: /?limit=<int>
            limit_query = request.GET.get('limit')
            try:
                limit = int(limit_query)
            except:
                pass

        qs = obj.status_set.all().order_by(
            '-timestamp')  #[:5] # Status.objects.filter(user=obj)
        data = {
            'uri':
            self.get_uri(obj) + 'status/',
            'last':
            StatusInlineUserSerializer(qs.first(),
                                       context={
                                           'request': request
                                       }).data,
            'recent_' + str(limit):
            StatusInlineUserSerializer(qs[:limit],
                                       many=True,
                                       context={
                                           'request': request
                                       }).data,
        }
        return data
Ejemplo n.º 4
0
 def get_status(self, obj):
     request = self.context['request']
     limit = 10
     if request:
         limit_query = request.GET.get('limit')
         try:
             limit = int(limit_query)
         except:
             pass
     qs = obj.status_set.all().order_by('-timestamp')
     data = {
         'uri':
         self.get_uri(obj),
         'last':
         StatusInlineUserSerializer(qs.first(),
                                    context={
                                        'request': request
                                    }).data,
         'recent_10':
         StatusInlineUserSerializer(qs[:limit],
                                    context={
                                        'request': request
                                    },
                                    many=True).data,
     }
     return data
Ejemplo n.º 5
0
 def get_status(self, obj):
     request = self.context.get('request')
     qs = obj.status_set.all().order_by('-timestamp')
     data = {
         'uri': self.get_uri(obj) + 'status/',
         'last': StatusInlineUserSerializer(qs.first(), context={'request': request}).data,
         'recent': StatusInlineUserSerializer(qs[:10], many=True, context={'request': request}).data
     }
     return data
Ejemplo n.º 6
0
	def get_status(self,obj):
		request = self.context.get('request') 
		qs = obj.status_set.all().order_by("-timestamp")[:10]
		data  = {
           'uri': self.get_uri(obj) + "status/",
           'last' : StatusInlineUserSerializer(qs.first()).data ,
           'recent' : StatusInlineUserSerializer(qs[:10],many=True).data
		}
		return data

	# def get_recent_status(self,obj):
	# 	qs = obj.status_set.all().order_by("-timestamp")[:10]
	# 	return StatusInlineUserSerializer(qs,many=True).data
Ejemplo n.º 7
0
 def get_resent_status(self, obj, request):
     qs = obj.status_set.all().order_by('-timestamp')
     return StatusInlineUserSerializer(qs,
                                       many=True,
                                       context={
                                           'request': request
                                       }).data
Ejemplo n.º 8
0
    def get_status(self, obj):
        request = self.context.get('request')
        limit = 4
        if request:
            limit_query = request.GET.get('limit')
            try:
                limit = int(limit_query)
            except:
                pass
        qs = obj.status_set.all().order_by("-timestamp")
        data = {
            'uri': self.get_uri(obj) + "status/",
            'last': StatusInlineUserSerializer(qs.first()).data,
            'recent': StatusInlineUserSerializer(qs[:limit], many=True).data
        }
        return data


## To test the limiting stuff see: http://127.0.0.1:8000/api/user/pragati/?limit=3
Ejemplo n.º 9
0
	def get_recent_status_list(self, obj):
		request = self.context.get('request')
		limit = 5
		if request:
			limit_query = request.GET.get("limit")
			try:
				limit = int(limit_query)
			except:
				pass	
		qs = obj.status_set.all().order_by("-timestamp")[:limit]# Status.objects.all(user=object)
		return StatusInlineUserSerializer(qs, many=True, context={"request":request}).data
Ejemplo n.º 10
0
 def get_status(self, obj):
     qs = obj.status_set.all().order_by('-timestamp')
     request = self.context.get('request')
     limit = 10
     # print(request.GET.get('limit'))
     if request.GET.get('limit'):
         limit = int(request.GET.get('limit'))
     data = {
         'uri':
         self.get_uri(obj) + "status/",
         'last':
         StatusInlineUserSerializer(qs.first(),
                                    context={
                                        'request': request
                                    }).data,
         'recent':
         StatusInlineUserSerializer(qs[:limit],
                                    context={
                                        'request': request
                                    },
                                    many=True).data,
     }
     return data
Ejemplo n.º 11
0
class UserDetailSerializer(serializers.ModelSerializer):
    uri = serializers.SerializerMethodField(read_only=True)
    status = serializers.SerializerMethodField(read_only=True)
    # statuses = serializers.HyperlinkedRelatedField(
    #     source='status_set',
    #     many=True,
    #     read_only=True,
    #     lookup_field='id',
    #     view_name='api-status:detail',
    # )
    statuses = StatusInlineUserSerializer(source='status_set', many=True, read_only=True)
    class Meta:
        model = User
        fields = [
            'id',
            'statuses',
            'username',
            'uri',
            'status',
        ]

    def get_uri(self, obj):
        request = self.context.get('request')
        return api_reverse("api-user:detail", kwargs={"username": obj.username}, request=request)

    def get_status(self, obj):
        request = self.context.get('request')
        limit = 10
        if request:
            limit_query = request.GET.get('limit')
            try:
                limit = int(limit_query)
            except:
                pass

        qs = obj.status_set.all().order_by("-timestamp")
        data = {
            'uri': self.get_uri(obj) + "status/",
            'last': StatusInlineUserSerializer(qs.first(), context={'request': request}).data,
            'recent': StatusInlineUserSerializer(qs[:10], many=True, context={'request': request}).data,
        }
        return data
Ejemplo n.º 12
0
class UserDetailSerializer(serializers.ModelSerializer):
    uri = serializers.SerializerMethodField(read_only=True)
    status = serializers.SerializerMethodField(read_only=True)
    # status_uri = serializers.SerializerMethodField(read_only=True)
    # recent_status_list = serializers.SerializerMethodField(read_only=True)
    statuses = serializers.HyperlinkedRelatedField(
        source='status_set',  # Status.objects.filter(user=user)
        # queryset=Status.objects.all()[:5],  # limit no of status to show
        many=True,
        read_only=True,
        lookup_field='id',
        view_name='api-status:detail',
    )
    statuses_inline = StatusInlineUserSerializer(source='status_set',
                                                 many=True,
                                                 read_only=True)

    class Meta:
        model = User
        fields = [
            'id',
            'username',
            'uri',
            'status',
            'statuses',
            'statuses_inline',
            # 'status_uri',
            # 'recent_status_list'
        ]

    def get_uri(self, obj):
        # return "/api/users/{id}/".format(id=obj.id)
        # return api_reverse("<namespace>:<view_name>",
        #                    kwargs={"username": obj.username})
        request = self.context.get('request')
        return api_reverse("api-user:detail",
                           kwargs={"username": obj.username},
                           request=request)

    def get_status(self, obj):
        request = self.context.get('request')
        limit = 10  # default limit
        if request:
            limit_query = request.GET.get('limit')
            try:
                limit = int(limit_query)
            except:
                pass

        qs = obj.status_set.all().order_by("-timestamp")  # [:10]
        data = {
            'uri':
            self.get_uri(obj) + "status/",
            'last':
            StatusInlineUserSerializer(qs.first(),
                                       context={
                                           'request': request
                                       }).data,
            # 'recent': StatusInlineUserSerializer(qs[:10], many=True).data
            'recent':
            StatusInlineUserSerializer(qs[:limit],
                                       context={
                                           'request': request
                                       },
                                       many=True).data
        }
        return data
Ejemplo n.º 13
0
 def get_status_list(self, obj):
     qs = obj.status_set.all().order_by(
         '-timestamp')[:10]  #Status.objects.filter(user=obj)
     return StatusInlineUserSerializer(qs, many=True).data
Ejemplo n.º 14
0
 def get_recent_status(self, obj):
     qs = obj.status_set.all().order_by(
         "-timestamp")[:2]  # Status.objects.filter(user=obj)
     return StatusInlineUserSerializer(qs, many=True).data
Ejemplo n.º 15
0
	def get_last_status(self, obj):
		request = self.context.get('request')
		qs = obj.status_set.all().order_by("-timestamp")# Status.objects.all(user=object)
		return StatusInlineUserSerializer(qs.first(), context={"request":request}).data