コード例 #1
0
ファイル: stark.py プロジェクト: k4xxx/stark
 def get_page_html(self, request, data_list):
     page = request.GET.get('page', 1)
     page_obj = Pagination(page,
                           len(data_list),
                           self.config.get_list_url(),
                           request.GET,
                           per_page_num=5)
     new_data_list = data_list[page_obj.start:page_obj.end]
     page_html = page_obj.page_html()
     return new_data_list, page_html
コード例 #2
0
ファイル: views.py プロジェクト: k4xxx/nnblog
    def get(self,request,bottom_url,**kwargs):
        # 从url中获取bottom_url参数,根据获取的bottom_url查找对应站点
        blog = models.Blog.objects.filter(bottom_url=bottom_url).first()
        if not blog:
            return render(request, 'error.html', {'error_info': '没有对应的个人博客!'})
        # 然后根据站点查找对应的用户名
        user = models.UserInfo.objects.filter(blog=blog).first()

        # 置顶的博客
        sticky_article_list = None
        # 要展示的博客
        article_list = None
        # 分页查看时网页后缀
        page_url = None
        # 根据**kwargs的值来判断用户进的是哪个页面(分类、时间归档、或者搜索),然后查询相对于的博客列表传递过去
        if not kwargs:
        # 如果kwargs没有接收值,那么说明是进入站点首页
            article_list = models.Article.objects.filter(user=user,is_post=True).order_by('-pk')
            sticky_article_list = article_list.filter(is_stick=1,is_post=True)
            page_url = bottom_url
        else:
            view = kwargs.get('view')
            condition = kwargs.get('condition')

            if view == 'category':
                article_list = models.Article.objects.filter(user=user,category__title=condition,is_post=True)
            elif view == 'search':
                article_list = models.Article.objects.filter(Q(title__contains=condition)|Q(articledetail__content__contains=condition)).filter(is_post=True)

            elif view == 'archive':
                year,month = condition.split('-')
                article_list = models.Article.objects.filter(is_post=True,user=user,create_time__year=year,create_time__month=month)

            page_url = '/{}/articles/{}/{}'.format(bottom_url, view, condition)

        # 分页展示
        page = request.GET.get('page',1)
        page_obj = Pagination(article_list.count(),page,page_url)
        if article_list:
            article_list = article_list[page_obj.start:page_obj.end]
        page_html = page_obj.page_html()
        data = {
            'blog':blog,
            'user':user,
            'bottom_url':bottom_url,
            'article_list':article_list,
            'sticky_article_list':sticky_article_list,
            'page_html':page_html,
        }
        return render(request,'home.html',data)
コード例 #3
0
ファイル: views.py プロジェクト: beriuta/history
 def get(self, request):
     url_prefix = request.path_info
     print(request.get_full_path())
     print(request.GET)
     qd = request.GET.copy(
     )  # <QueryDict: {'query': ['了']}> 查找的'了',所以query获取的就是登陆者所查找的内容
     # qd._mutable = True  # 让QueryDict对象可修改
     # print(request.GET.urlencode())  # 把检索参数都编码成URL
     current_page = request.GET.get('page', 1)
     if '/my_customer/' in request.path_info:
         # 获取私户信息,Customer类中查找consultant这个字段属于是当前销售用户的客户
         query_set = Customer.objects.filter(
             consultant=request.user)  # 获取此时登录的销售用户的名称
     else:
         # 获取公户的所有信息
         query_set = Customer.objects.filter(
             consultant__isnull=True)  # 把consultant这个字段为空的都提取出来
     # 根据模糊检索的条件对query_set再做过滤
     # 找到name,qq,qq_name字段包含QuerySet_value的那些数据就是搜索的结果
     q = self._get_query_q(['name', 'qq', 'qq_name'])
     query_set = query_set.filter(q)
     # query_set = Customer.objects.all()
     # total_count = query_set.count()   # SQL语句的效率高
     # 生成一个分页实例
     page_obj = Pagination(current_page,
                           query_set.count(),
                           url_prefix,
                           qd,
                           per_page=2)
     print(page_obj.start, page_obj.end)
     # 取到当前页面的数据
     data = query_set[page_obj.start:page_obj.end]
     # 2.返回之前的页面
     # 获取当前请求的带Query参数的URL
     url = request.get_full_path()
     # 生成一个空的QueryDict对象
     query_params = QueryDict(mutable=True)
     # 添加一个next键值对
     query_params['next'] = url
     # 利用QueryDict内置的方法编码成URL
     next_url = query_params.urlencode()
     # 取到分页的HTML代码
     page_html = page_obj.page_html()
     return render(request, 'customer_list.html', {
         'customer_list': data,
         'next_url': next_url,
         'page_html': page_html
     })
コード例 #4
0
ファイル: views.py プロジェクト: k4xxx/nnblog
    def get(self,request,view):
        user = request.user
        blog = user.blog
        bottom_url = blog.bottom_url
        # 分页展示的页面url
        page_url = 'manage/{}'.format(view)

        page = request.GET.get('page', 1)
        page_obj = None
        data_list = None
        # 数据
        try:
            # 如果数据库暂时没有数据,切片会报错
            if view == 'article':
                article_list = models.Article.objects.filter(user=user,is_post=True).order_by('-pk')
                page_obj = Pagination(article_list.count(), page, page_url)
                data_list = article_list[page_obj.start:page_obj.end]
            elif view == 'drafts':
                drafts_list = models.Article.objects.filter(user=user,is_post=False).order_by('-pk')
                page_obj = Pagination(drafts_list.count(), page, page_url)
                data_list = drafts_list[page_obj.start:page_obj.end]
            elif view == 'category':
                category_list = models.Category.objects.filter(blog=blog)
                page_obj = Pagination(category_list.count(), page, page_url,12)
                data_list = category_list[page_obj.start:page_obj.end]
            else:
                link_list = models.FriendlyLink.objects.filter(blog=blog)
                page_obj = Pagination(link_list.count(), page, page_url)
                data_list = link_list[page_obj.start:page_obj.end]
        except AssertionError:
            data_list = []
        # 分页
        page_html = page_obj.page_html()

        data = {
            'user':user,
            'blog':blog,
            'bottom_url':bottom_url,
            'page_html':page_html,
            'data_list':data_list,
        }
        return render(request,'manage/{}-manage.html'.format(view),data)
コード例 #5
0
ファイル: views.py プロジェクト: xiaoyi110/cmd
 def get(self, request):
     url_prefix = request.path_info
     qd = request.GET.copy()  # <QueryDict: {'query': ['了']}>
     # qd._mutable = True  # 让QueryDict对象可修改
     current_page = request.GET.get('page', 1)
     if request.path_info == reverse('my_customer'):
         # 获取私户信息
         query_set = Customer.objects.filter(
             consultant=request.user)  # request.user-->当前登录的人
     else:
         # 获取所有公户信息
         query_set = Customer.objects.filter(consultant__isnull=True)
     # 根据模糊检索的条件对query_set再做过滤.
     # 找到name, qq, qq_name字段包含query_value的哪些数据就是搜索的结果
     q = self._get_query_q(['name', 'qq', 'qq_name'])
     query_set = query_set.filter(q)
     page_obj = Pagination(current_page,
                           query_set.count(),
                           url_prefix,
                           qd,
                           per_page=3)
     data = query_set[page_obj.start:page_obj.end]
     # 2.0 返回之前的页面
     # 2.1 获取当前请求的带query参数的URL
     url = request.get_full_path()
     # 2.2 生成一个空的QueryDict对象
     query_params = QueryDict(mutable=True)
     # 2.3 添加一个next键值对
     query_params['next'] = url
     # 2.4 利用QueryDict内置方法编码成URL
     next_url = query_params.urlencode()
     # 在页面上展示出来
     return render(
         request, 'customer_list.html', {
             'customer_list': data,
             'next_url': next_url,
             'page_html': page_obj.page_html()
         })