def get(self, request, **kwargs): """Authentication optional, list of applications.""" applications = public_applications() #Concatenate 'visible' if request.user and type(request.user) != AnonymousUser: my_apps = visible_applications(request.user) applications.extend(my_apps) params = request.QUERY_PARAMS applications = _filter_applications(applications, request.user, params) page = params.get('page') if page or len(applications) == 0: paginator = Paginator(applications, 20, allow_empty_first_page=True) else: # return all results. paginator = Paginator(applications, len(applications), allow_empty_first_page=True) try: app_page = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. app_page = paginator.page(1) except EmptyPage: # Page is out of range. # deliver last page of results. app_page = paginator.page(paginator.num_pages) serialized_data = PaginatedApplicationSerializer( app_page, context={'request': request}).data response = Response(serialized_data) response['Cache-Control'] = 'no-cache' return response
def get_queryset(self): applications = public_applications() if self.request.user and type(self.request.user) != AnonymousUser: my_apps = visible_applications(self.request.user) applications.extend(my_apps) return _filter_applications(applications, self.request.user, self.request.query_params)
def get(self, request, **kwargs): """Authentication optional, list of applications.""" request_user = kwargs.get('request_user') applications = public_applications() #Concatenate 'visible' if request.user and type(request.user) != AnonymousUser: my_apps = visible_applications(request.user) applications.extend(my_apps) serialized_data = ApplicationSerializer(applications, context={'user':request.user}, many=True).data response = Response(serialized_data) return response
def get(self, request, **kwargs): """Authentication optional, list of applications.""" request_user = kwargs.get('request_user') applications = public_applications() #Concatenate 'visible' if request.user and type(request.user) != AnonymousUser: my_apps = visible_applications(request.user) applications.extend(my_apps) serialized_data = ApplicationSerializer(applications, context={ 'user': request.user }, many=True).data response = Response(serialized_data) return response
def get(self, request, **kwargs): """Authentication optional, list of applications.""" applications = public_applications() #Concatenate 'visible' if request.user and type(request.user) != AnonymousUser: my_apps = visible_applications(request.user) applications.extend(my_apps) params = request.QUERY_PARAMS applications = _filter_applications(applications, request.user, params) page = params.get('page') if page or len(applications) == 0: paginator = Paginator(applications, 20, allow_empty_first_page=True) else: # return all results. paginator = Paginator(applications, len(applications), allow_empty_first_page=True) try: app_page = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. app_page = paginator.page(1) except EmptyPage: # Page is out of range. # deliver last page of results. app_page = paginator.page(paginator.num_pages) serialized_data = PaginatedApplicationSerializer(app_page, context={ 'request': request }).data response = Response(serialized_data) response['Cache-Control'] = 'no-cache' return response