def get_vms_list_context(self, request, vms_queryset, context:dict): # 分页显示 paginator = NumsPaginator(request, vms_queryset, self.NUM_PER_PAGE) page_num = request.GET.get('page', 1) # 获取页码参数,没有参数默认为1 vms_page = paginator.get_page(page_num) page_nav = paginator.get_page_nav(vms_page) context['page_nav'] = page_nav context['vms'] = vms_page context['count'] = paginator.count return context
def get_disks_list_context(self, request, queryset, context: dict): # 分页显示 paginator = NumsPaginator(request, queryset, self.NUM_PER_PAGE) page_num = request.GET.get(paginator.page_query_name, 1) # 获取页码参数,没有参数默认为1 page = paginator.get_page(page_num) page_nav = paginator.get_page_nav(page) context['page_nav'] = page_nav context['vdisks'] = page context['count'] = paginator.count return context
def get(self, request, *args, **kwargs): topic = request.GET.get('topic', None) lang_code = get_language() lang = Article.get_lang_value_by_code(lang_code=lang_code) prefetch = Prefetch('article_set', queryset=Article.objects.filter(lang=lang, enable=True).only( 'id', 'summary', 'title').all(), to_attr='articles') if topic is not None: try: topic = int(topic) if topic not in Publication.TOPIC_INVALID_VALUES: raise ValueError except ValueError: return redirect(to=reverse('article:pub-list')) pub_queryset = Publication.objects.filter( topic=topic, enable=True).prefetch_related(prefetch).all() else: pub_queryset = Publication.objects.filter( enable=True).prefetch_related(prefetch).all() # 分页显示 paginator = NumsPaginator(request, pub_queryset, self.NUM_PER_PAGE) page_num = request.GET.get('page', 1) # 获取页码参数,没有参数默认为1 pubs_page = paginator.get_page(page_num) page_nav = paginator.get_page_nav(pubs_page) context = { 'publications': pubs_page, 'topics': Publication.TOPIC_CHOICES, 'active': topic, 'page_nav': page_nav, 'count': paginator.count } return render(request, 'pub_list.html', context=context)
def get(self, request, *args, **kwargs): service_id = request.GET.get('service') user = request.user if service_id: service = ServiceConfig.objects.filter(id=service_id).first() is_need_vpn = service.is_need_vpn() else: is_need_vpn = False servers_qs = ServerManager().get_user_servers_queryset(user=user, service_id=service_id) # 分页显示 paginator = NumsPaginator(request, servers_qs, self.NUM_PER_PAGE) page_num = request.GET.get(paginator.page_query_name, 1) # 获取页码参数,没有参数默认为1 servers_page = paginator.get_page(page_num) page_nav = paginator.get_page_nav(servers_page) context = { 'active_service': service_id, 'is_need_vpn': is_need_vpn, 'servers': servers_page, 'page_nav': page_nav, 'count': paginator.count } return render(request, 'server_list.html', context=context)