def training_blog(cls, request): """Get Training Blog.""" queryset = BlogEntry.objects.filter( blog_url=settings.TRAINING_BLOG_URL) queryset = query_search(request, 3, queryset, ['title', 'content']) queryset = query_from_num(request, 20, queryset) return Response(BlogEntrySerializer(queryset, many=True).data)
def placement_blog(cls, request): """Get Placement Blog.""" queryset = BlogEntry.objects.filter(blog_url=settings.PLACEMENTS_URL) queryset = query_search(request, 3, queryset, ['title', 'content']) queryset = query_from_num(request, 20, queryset) return Response(BlogEntrySerializer(queryset, many=True).data)
def training_blog(cls, request): """Get Training Blog.""" from_i, num = query_from_num(request, 20) return Response( BlogEntrySerializer(BlogEntry.objects.filter( blog_url=settings.TRAINING_BLOG_URL)[from_i:from_i + num], many=True).data)
def placement_blog(cls, request): """Get Placement Blog.""" from_i, num = query_from_num(request, 20) return Response( BlogEntrySerializer(BlogEntry.objects.filter( blog_url=settings.PLACEMENTS_URL)[from_i:from_i + num], many=True).data)
def list(self, request): """Get a list of non-deleted complaints. To filter by current user, add a query parameter {?filter}""" # Get the list of complaints excluding objects marked deleted complaints = self.queryset.prefetch_related( 'subscriptions', 'users_up_voted').exclude(status='Deleted') # Check if the user specific filter is present if 'filter' in request.GET and request.user.is_authenticated: complaints = complaints.filter(created_by=request.user.profile) # Filter for a particular word search if 'search' in request.GET: val = request.query_params.get('search') complaints = complaints.filter(description__icontains=val) # For multiple tags and single tags if 'tags' in request.GET: val = request.query_params.getlist('tags') clauses = (Q(tags__tag_uri__icontains=p) for p in val) query = reduce(operator.or_, clauses) complaints = complaints.filter(query) # Paginate the complaint page using the helper function complaints = query_from_num(request, 10, complaints) # Serialize and return serialized = ComplaintSerializer(complaints, context={ 'request': request }, many=True).data for complaint_object, serialized_object in zip(complaints, serialized): is_sub = request.user.is_authenticated and request.user.profile in complaint_object.subscriptions.all( ) serialized_object['is_subscribed'] = is_sub upvoted = request.user.is_authenticated and request.user.profile in complaint_object.users_up_voted.all( ) serialized_object['upvoted'] = upvoted return Response(serialized)
def news_feed(request): """Get News feed.""" # Paging parameters from_i, num = query_from_num(request, 30) # Filter for body body = request.GET.get('body') if body is not None: queryset = NewsEntry.objects.filter(body__id=body) else: queryset = NewsEntry.objects.all() # Get sliced news items return Response( NewsEntrySerializer(queryset[from_i:from_i + num], many=True, context={ 'request': request }).data)
def news_feed(request): """Get News feed.""" # Filter for body body = request.GET.get('body') if body is not None: queryset = NewsEntry.objects.filter(body__id=body) else: queryset = NewsEntry.objects.all() # Paging and search queryset = query_search(request, 3, queryset, ['title', 'content']) queryset = query_from_num(request, 20, queryset) # Eagerly load data queryset = NewsEntrySerializer.setup_eager_loading(queryset) # Get sliced news items return Response( NewsEntrySerializer(queryset, many=True, context={ 'request': request }).data)
def news_feed(request): """Get News feed.""" from_i, num = query_from_num(request, 30) return Response(NewsEntrySerializer( NewsEntry.objects.all()[from_i : from_i + num], many=True, context={'request': request}).data)