Esempio n. 1
0
def index(request):
    # 获取当前页码
    try:
        page = int(request.GET.get('page', 1))
    except Exception as e:
        page = 1

    # 获取数据的总数
    book_count = Books.objects.count()
    # 书的总数 除以 每页显示的数
    page_count, m = divmod(book_count,
                           10)  # divmod 返回两个元素的元组, 第一个参数是商 第二个参数是余数
    if m:
        # 当余数不为空时 总页数加1
        page_count += 1

    # 实例化Page产生分页对象
    page = Page(page, page_count, '/app01/index/')
    print(page.start_pos, page.end_pos)
    # 根据开始和结束位置  获取数据
    books = Books.objects.values('id', 'books_name', 'stock',
                                 'sales_num')[page.start_pos:page.end_pos]
    # 获取分页的html代码
    page_html = page.get_page_show()
    return render(request, 'books.html', {
        "books": books,
        'page_html': page_html
    })
Esempio n. 2
0
    def get(self, request):
        recv_data = copy.copy(request.GET)
        current_page_number = request.GET.get('page')
        search_field = request.GET.get('search_field')
        if search_field == None:
            search_field = 'customer__name__contains'
        keyword = request.GET.get("keyword")
        all_enrollment = None
        if keyword:
            q = Q()
            q.children.append([search_field, keyword])
            all_enrollment = models.Enrollment.objects.filter(q)
        else:
            all_enrollment = models.Enrollment.objects.all()
        all_enrollment = all_enrollment.filter(delete_status=False)

        total_count = all_enrollment.count()
        per_page_count = settings.PER_PAGE_COUNT
        page_number_show = settings.PAGE_NUMBER_SHOW

        page_obj = Page(current_page_number, total_count, page_number_show,
                        per_page_count, recv_data)
        all_enrollment = all_enrollment[page_obj.start_data_number:page_obj.
                                        end_data_number]
        page_html = page_obj.page_html_func()
        return render(
            request, 'enrollment_record/show_enrollment_record.html', {
                "all_enrollment": all_enrollment,
                "page_html": page_html,
                "keyword": keyword,
                'search_field': search_field
            })
Esempio n. 3
0
 def get(self, request, *args, **kwargs):
     current_page = request.GET.get('page')  # 当前页
     try:
         current_page = int(current_page)
     except Exception as e:
         current_page = int(1)
     all_count = models.UserHost.objects.all().count()  # 数据总条数
     page_obj = Page(current_page, all_count,
                     request.path_info)  # requ request.path_info当前URL
     game_list = models.UserHost.objects.all()[page_obj.start:page_obj.end]
     page_str = page_obj.page_html()
     return render(request, 'games.html', {
         'game_list': game_list,
         'page_str': page_str
     })
Esempio n. 4
0
 def get(self, request):
     article_list = models.Article.objects.all()
     totol_num = article_list.count()
     page_num = request.GET.get("page", 1)
     # 分页实例化传参
     page_obj = Page(total_num=totol_num,
                     page_num=page_num,
                     url_prefix='home',
                     every_page_num=2)
     # 根据分页拿到的start和end切片得到所要的数据
     data = article_list[page_obj.start:page_obj.end]
     # 调用html方法得到分页的html代码片段
     page_html = page_obj.html
     return render(request, 'home.html', {
         'article_list': data,
         'page_html': page_html
     })
Esempio n. 5
0
    def get(self, request):
        recv_data = copy.copy(request.GET)

        current_page_number = request.GET.get("page")  #当前页码
        search_field = request.GET.get('search_field')  #所搜条件
        if search_field == None:
            search_field = 'qq__contains'
        keyword = request.GET.get("keyword")
        all_customers = None
        message = None
        if keyword:
            q = Q()
            q.children.append([search_field, keyword])
            all_customers = models.Customer.objects.filter(q)
        else:
            if request.path == reverse('mysite:show_customers'):
                all_customers = models.Customer.objects.filter(
                    consultant__isnull=True)
                message = "公有"
                change_message = "公有客户转私有客户"
            else:
                all_customers = models.Customer.objects.filter(
                    consultant__username=request.session.get("username"))
                message = "私有"
                change_message = "私有客户转公有客户"

        total_count = all_customers.count()
        per_page_count = settings.PER_PAGE_COUNT
        page_number_show = settings.PAGE_NUMBER_SHOW

        page_obj = Page(current_page_number, total_count, page_number_show,
                        per_page_count, recv_data)
        all_customers = all_customers[page_obj.start_data_number:page_obj.
                                      end_data_number]
        page_html = page_obj.page_html_func()
        return render(
            request, 'customers/show_customers.html', {
                'all_customers': all_customers,
                "page_html": page_html,
                "keyword": keyword,
                'message': message,
                'search_field': search_field
            })
Esempio n. 6
0
    def get(self, request):
        recv_data = copy.copy(request.GET)
        current_page_number = request.GET.get("page")  # 当前页码
        search_field = request.GET.get('search_field')  # 所搜条件
        if search_field == None:
            search_field = 'customer__name__contains'
        keyword = request.GET.get("keyword")
        all_records = None

        print(request.GET.dict())
        #获取单个客户的id
        customer_id = request.GET.get("customer_id")
        if keyword:
            q = Q()
            q.children.append([search_field, keyword])
            all_records = models.ConsultRecord.objects.filter(q)
        else:
            all_records = models.ConsultRecord.objects.all()
        all_records = all_records.filter(
            consultant__username=request.session.get('username'),
            delete_status=False)

        if customer_id:
            all_records = all_records.filter(customer_id=customer_id)

        total_count = all_records.count()
        per_page_count = settings.PER_PAGE_COUNT
        page_number_show = settings.PAGE_NUMBER_SHOW

        page_obj = Page(current_page_number, total_count, page_number_show,
                        per_page_count, recv_data)
        all_records = all_records[page_obj.start_data_number:page_obj.
                                  end_data_number]
        page_html = page_obj.page_html_func()
        return render(
            request, 'consult_record/consult_record.html', {
                'all_records': all_records,
                "page_html": page_html,
                "keyword": keyword,
                'search_field': search_field
            })
Esempio n. 7
0
    def listview(self, request):

        # 批量操作
        if request.method == "POST":
            print(666)
            pk_list = request.POST.getlist('checkbox_pk')
            queryset = self.model.objects.filter(pk__in=pk_list)
            action_name = request.POST.get("action")
            try:
                action = getattr(self, action_name)
                action(queryset)
            except:
                code = 1

        # 添加数据的url,给前端添加button的
        add_url = self.get_add_url()
        # 数据库查询出当数据前表的所有数据
        data_list = self.model.objects.all()

        # 调用get_search_condition方法获取search查询条件
        search_conditions = self.get_search_condition(request)
        # 调用get_filter_condition方法获取filter的查询条件
        filter_conditions = self.get_filter_condition(request)
        # 过滤,找出符合要求的数据
        new_data_list = data_list.filter(search_conditions).filter(filter_conditions)

        # 调用视图展示类实例化来生成类对象
        listview_obj = ListView(self, request, new_data_list)

        # 调用试图类对象生成数据体的方法生成数据
        obj_list = listview_obj.create_body()

        # 分页组件实例化传参
        page_obj = Page(total_num=len(obj_list), page_num=request.GET.get("page", 1), request=request,
                        every_page_num=10)
        # 根据分页拿到的start和end切片得到所要的数据
        obj_list = obj_list[page_obj.start:page_obj.end]
        # 调用html方法得到分页的html代码片段
        page_html = page_obj.html

        return render(request, 'stark/list_view.html', locals())
Esempio n. 8
0
def blogcenter(request, username, *args):
    # 通过用户信息找到当前用户的对象
    user_obj = models.UserInfo.objects.filter(username=username).first()
    # ORM操作查询当前用户对应的所有书籍
    article_list = models.Article.objects.filter(
        user=user_obj).order_by("create_time").reverse()

    if args:
        if args[0] == "category":
            # 表示按照文章分类查询
            article_list = article_list.filter(category__title=args[1])
        elif args[0] == "tag":
            # 表示按照文章的标签查询
            article_list = article_list.filter(tags__title=args[1])
        else:
            # 表示按照文章的日期归档查询
            try:
                year, month = args[1].split("-")
                article_list = article_list.filter(
                    create_time__year=year).filter(create_time__month=month)
            except Exception as e:
                article_list = []

    # 分页
    page_num = request.GET.get("page", 1)
    totol_num = article_list.count()
    page_obj = Page(total_num=totol_num,
                    page_num=page_num,
                    url_prefix=f'blogcenter/{username}',
                    every_page_num=5)
    print(page_obj.start)
    print(page_obj.end)
    article_list = article_list[page_obj.start:page_obj.end]
    page_html = page_obj.html

    return render(request, 'blogcenter.html', {
        'username': username,
        'article_list': article_list,
        'page_html': page_html
    })
Esempio n. 9
0
def backend(request):
    article_list = models.Article.objects.filter(blog=request.user.blog)
    all_count = article_list.count()
    Page_info = Page(request.GET.get('page'), all_count, 4, 3, '/backend')
    page_queryset = article_list[Page_info.start():Page_info.end()]
    return render(request,"backend/backend.html",locals())
Esempio n. 10
0
def login_page(selenium):
    selenium.get('http://39.104.14.232/ecshop/wwwroot/admin/privilege.php?act=login')
    yield Page(selenium, 'login_page.yaml')