• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python app_globals.handle_paging函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pylons.app_globals.handle_paging函数的典型用法代码示例。如果您正苦于以下问题:Python handle_paging函数的具体用法?Python handle_paging怎么用?Python handle_paging使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了handle_paging函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_with_limit

 def test_with_limit(self):
     self.assertEqual(g.handle_paging(10, 0), (10, 0, 0))
     self.assertEqual(g.handle_paging(10, 2), (10, 2, 20))
     # handle paging must not mess up user preferences
     self.assertEqual(c.user.get_pref('results_per_page'), None)
     # maximum enforced
     self.assertEqual(g.handle_paging(99999999, 0), (500, 0, 0))
开发者ID:abhinavthomas,项目名称:allura,代码行数:7,代码来源:test_globals.py


示例2: test_without_limit

    def test_without_limit(self):
        # default limit = 25
        self.assertEqual(g.handle_paging(None, 0), (25, 0, 0))
        self.assertEqual(g.handle_paging(None, 2), (25, 2, 50))
        # handle paging must not mess up user preferences
        self.assertEqual(c.user.get_pref('results_per_page'), None)

        # user has page size preference
        c.user.set_pref('results_per_page', 100)
        self.assertEqual(g.handle_paging(None, 0), (100, 0, 0))
        self.assertEqual(g.handle_paging(None, 2), (100, 2, 200))
        # handle paging must not mess up user preferences
        self.assertEqual(c.user.get_pref('results_per_page'), 100)
开发者ID:abhinavthomas,项目名称:allura,代码行数:13,代码来源:test_globals.py


示例3: test_without_limit_with_default

    def test_without_limit_with_default(self):
        # default limit is not used when explicitly provided
        self.assertEqual(g.handle_paging(None, 0, 30), (30, 0, 0))
        self.assertEqual(g.handle_paging(None, 2, 30), (30, 2, 60))
        # handle paging must not mess up user preferences
        self.assertEqual(c.user.get_pref('results_per_page'), None)

        # user has page size preference, which is not affected by default
        c.user.set_pref('results_per_page', 25)
        self.assertEqual(g.handle_paging(None, 0, 30), (25, 0, 0))
        self.assertEqual(g.handle_paging(None, 2, 30), (25, 2, 50))
        # handle paging must not mess up user preferences
        self.assertEqual(c.user.get_pref('results_per_page'), 25)
开发者ID:abhinavthomas,项目名称:allura,代码行数:13,代码来源:test_globals.py


示例4: index

 def index(self, **kw):
     kw = WidgetConfig.post_filter.validate(kw, None)
     page = kw.pop('page', 0)
     limit = kw.pop('limit', 50)
     status = kw.pop('status', 'pending')
     username = kw.pop('username', None)
     flag = kw.pop('flag', None)
     c.post_filter = WidgetConfig.post_filter
     c.moderate_posts = WidgetConfig.moderate_posts
     c.page_list = WidgetConfig.page_list
     query = dict(
         discussion_id=self.discussion._id,
         deleted=False)
     if status != '-':
         query['status'] = status
     if flag:
         query['flags'] = {'$gte': int(flag)}
     if username:
         filtered_user = User.by_username(username)
         query['author_id'] = filtered_user._id if filtered_user else None
     q = self.PostModel.query.find(query).sort('timestamp', -1)
     count = q.count()
     limit, page, start = g.handle_paging(limit, page or 0, default=50)
     q = q.skip(start)
     q = q.limit(limit)
     pgnum = (page // limit) + 1
     pages = (count // limit) + 1
     return dict(discussion=self.discussion,
                 posts=q, page=page, limit=limit,
                 status=status, flag=flag, username=username,
                 pgnum=pgnum, pages=pages, count=count)
开发者ID:brondsem,项目名称:allura,代码行数:31,代码来源:discuss.py


示例5: index

 def index(self, page=0, limit=DEFAULT_PAGE_LIMIT, **kw):
     c.revision_widget = self.revision_widget
     c.page_list = self.page_list
     result = dict(commit=self._commit)
     if self._commit:
         result.update(self._commit.context())
     tree = self._commit.tree
     limit, page, start = g.handle_paging(limit, page,
                                          default=self.DEFAULT_PAGE_LIMIT)
     diffs = self._commit.paged_diffs(start=start, end=start + limit, onlyChangedFiles=True)
     result['artifacts'] = []
     for t in ('added', 'removed', 'changed', 'copied', 'renamed'):
         for f in diffs[t]:
             if t in ('copied', 'renamed'):
                 filepath = f['new']
             else:
                 filepath = f
             is_text = filepath and tree.get_blob_by_path(filepath) and tree.get_blob_by_path(filepath).has_html_view
             result['artifacts'].append(
                 (t, f, 'blob' if tree.get_blob_by_path(f) else 'tree', is_text)
             )
     count = diffs['total']
     result.update(dict(page=page, limit=limit, count=count))
     # Sort the result['artifacts'] which is in format as below -
     # [('added', u'aaa.txt', 'blob', True),
     # ('added', u'eee.txt', 'blob', True),
     # ('added', u'ggg.txt', 'blob', True),
     # ('removed', u'bbb.txt', 'tree', None),
     # ('removed', u'ddd.txt', 'tree', None),
     # ('changed', u'ccc.txt', 'blob', True)]
     result['artifacts'].sort(key=lambda x: x[1]['old'] if(type(x[1]) == dict) else x[1])
     return result
开发者ID:brondsem,项目名称:allura,代码行数:32,代码来源:repository.py


示例6: adminlist

    def adminlist(self, sort='alpha', limit=25, page=0, **kw):
        limit, page, start = g.handle_paging(limit, page)

        pq = M.Project.query.find(
            dict(neighborhood_id=self.neighborhood._id, deleted=False))
        if sort == 'alpha':
            pq.sort('name')
        else:
            pq.sort('last_updated', pymongo.DESCENDING)
        count = pq.count()
        projects = pq.skip(start).limit(int(limit)).all()

        entries = []
        for proj in projects:
            admin_role = M.ProjectRole.query.get(
                project_id=proj.root_project._id, name='Admin')
            if admin_role is None:
                continue
            user_role_list = M.ProjectRole.query.find(
                dict(project_id=proj.root_project._id, name=None)).all()
            for ur in user_role_list:
                if ur.user is not None and admin_role._id in ur.roles:
                    entries.append({'project': proj, 'user': ur.user})

        set_nav(self.neighborhood)
        return dict(entries=entries,
                    sort=sort,
                    limit=limit, page=page, count=count,
                    page_list=W.page_list,
                    neighborhood=self.neighborhood,
                    )
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:31,代码来源:project.py


示例7: index

 def index(self, version=None, page=0, limit=None, **kw):
     if not self.page:
         redirect(c.app.url + h.urlquote(self.title) + '/edit')
     c.confirmation = W.confirmation
     c.thread = W.thread
     c.attachment_list = W.attachment_list
     c.subscribe_form = W.page_subscribe_form
     post_count = self.page.discussion_thread.post_count
     limit, pagenum, _ = g.handle_paging(limit, page)
     limit, pagenum = h.paging_sanitizer(limit, pagenum, post_count)
     page = self.get_version(version)
     if page is None:
         if version:
             redirect('.?version=%d' % (version - 1))
         else:
             redirect('.')
     elif 'all' not in page.viewable_by and c.user.username not in page.viewable_by:
         raise exc.HTTPForbidden(detail="You may not view this page.")
     cur = page.version
     if cur > 1:
         prev = cur - 1
     else:
         prev = None
     next = cur + 1
     hide_left_bar = not (c.app.show_left_bar)
     subscribed_to_page = M.Mailbox.subscribed(artifact=self.page)
     c.subscribe_form.tool_subscribed = M.Mailbox.subscribed()
     return dict(
         page=page,
         cur=cur, prev=prev, next=next,
         page_subscribed=subscribed_to_page,
         hide_left_bar=hide_left_bar, show_meta=c.app.show_right_bar,
         pagenum=pagenum, limit=limit, count=post_count)
开发者ID:abhinavthomas,项目名称:allura,代码行数:33,代码来源:wiki_main.py


示例8: paged_query

    def paged_query(cls, app_config, user, query, limit=None, page=0, sort=None, deleted=False, **kw):
        """
        Query tickets, filtering for 'read' permission, sorting and paginating the result.

        See also paged_search which does a solr search
        """
        limit, page, start = g.handle_paging(limit, page, default=25)
        q = cls.query.find(dict(query, app_config_id=app_config._id, deleted=deleted))
        q = q.sort('ticket_num', pymongo.DESCENDING)
        if sort:
            field, direction = sort.split()
            if field.startswith('_'):
                field = 'custom_fields.' + field
            direction = dict(
                asc=pymongo.ASCENDING,
                desc=pymongo.DESCENDING)[direction]
            q = q.sort(field, direction)
        q = q.skip(start)
        q = q.limit(limit)
        tickets = []
        count = q.count()
        for t in q:
            if security.has_access(t, 'read', user, app_config.project.root_project):
                tickets.append(t)
            else:
                count = count -1

        return dict(
            tickets=tickets,
            count=count, q=json.dumps(query), limit=limit, page=page, sort=sort,
            **kw)
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:31,代码来源:ticket.py


示例9: index

 def index(self, threads=None, limit=25, page=0, count=0, **kw):
     if self.discussion.deleted:
         redirect(self.discussion.url()+'deleted')
     limit, page, start = g.handle_paging(limit, page)
     c.subscribed=M.Mailbox.subscribed(artifact=self.discussion)
     threads = DM.ForumThread.query.find(dict(discussion_id=self.discussion._id, num_replies={'$gt': 0})) \
                                   .sort([('flags', pymongo.DESCENDING), ('last_post_date', pymongo.DESCENDING)])
     return super(ForumController, self).index(threads=threads.skip(start).limit(int(limit)).all(), limit=limit, page=page, count=threads.count(), **kw)
开发者ID:johnsca,项目名称:incubator-allura,代码行数:8,代码来源:forum.py


示例10: index

 def index(self, limit=100, page=0, **kw):
     limit, page, start = g.handle_paging(int(limit), int(page))
     json_data = {}
     json_data['topic'] = self.topic.__json__(limit=limit, page=page)
     json_data['count'] = self.topic.query_posts(status='ok').count()
     json_data['page'] = page
     json_data['limit'] = limit
     return json_data
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:8,代码来源:root.py


示例11: index

 def index(self, limit=100, page=0, **kw):
     limit, page, start = g.handle_paging(int(limit), int(page))
     posts = self.topic.query_posts(page=page, limit=limit, style='')
     json = {}
     json['topic'] = self.topic.__json__()
     json['count'] = posts.count()
     json['page'] = page
     json['limit'] = limit
     json['topic']['posts'] = posts.all()
     return json
开发者ID:wwitzel3,项目名称:incubator-allura,代码行数:10,代码来源:root.py


示例12: index

    def index(self, sort='alpha', limit=25, page=0, **kw):
        text = None
        if self.neighborhood.use_wiki_page_as_root:
            default_wiki_page = get_default_wiki_page()
            if default_wiki_page:
                text = default_wiki_page.html_text
        elif self.neighborhood.redirect:
            redirect(self.neighborhood.redirect)
        elif not self.neighborhood.has_home_tool:
            mount = c.project.ordered_mounts()[0]
            if mount is not None:
                if 'ac' in mount:
                    redirect(mount['ac'].options.mount_point + '/')
                elif 'sub' in mount:
                    redirect(mount['sub'].url())
            else:
                redirect(c.project.app_configs[0].options.mount_point + '/')
        else:
            text=g.markdown.cached_convert(
                self.neighborhood, 'homepage'),

        c.project_summary = W.project_summary
        c.page_list = W.page_list
        limit, page, start = g.handle_paging(limit, page)
        pq = M.Project.query.find(dict(
            neighborhood_id=self.neighborhood._id,
            deleted=False,
            is_nbhd_project=False,
        ))
        if sort == 'alpha':
            pq.sort('name')
        else:
            pq.sort('last_updated', pymongo.DESCENDING)
        count = pq.count()
        nb_max_projects = self.neighborhood.get_max_projects()
        projects = pq.skip(start).limit(int(limit)).all()
        categories = M.ProjectCategory.query.find(
            {'parent_id': None}).sort('name').all()
        c.custom_sidebar_menu = []
        if h.has_access(self.neighborhood, 'register')() and (nb_max_projects is None or count < nb_max_projects):
            c.custom_sidebar_menu += [
                SitemapEntry('Add a Project', self.neighborhood.url()
                             + 'add_project', ui_icon=g.icons['add']),
                SitemapEntry('')
            ]
        c.custom_sidebar_menu = c.custom_sidebar_menu + [
            SitemapEntry(cat.label, self.neighborhood.url() + 'browse/' + cat.name) for cat in categories
        ]
        return dict(neighborhood=self.neighborhood,
                    title="Welcome to " + self.neighborhood.name,
                    text=text,
                    projects=projects,
                    sort=sort,
                    limit=limit, page=page, count=count)
开发者ID:brondsem,项目名称:allura,代码行数:54,代码来源:project.py


示例13: history

 def history(self, page=0, limit=None, **kw):
     if not self.page:
         raise exc.HTTPNotFound
     c.page_list = W.page_list
     c.page_size = W.page_size
     limit, pagenum, start = g.handle_paging(limit, page, default=25)
     count = 0
     pages = self.page.history()
     count = pages.count()
     pages = pages.skip(start).limit(int(limit))
     return dict(title=self.title, pages=pages,
                 limit=limit, count=count, page=pagenum)
开发者ID:johnsca,项目名称:incubator-allura,代码行数:12,代码来源:wiki_main.py


示例14: index

 def index(self, page=0, limit=None, **kw):
     query_filter = dict(app_config_id=c.app.config._id)
     if not has_access(c.app, "write")():
         query_filter["state"] = "published"
     q = BM.BlogPost.query.find(query_filter)
     post_count = q.count()
     limit, page, _ = g.handle_paging(limit, page)
     limit, page = h.paging_sanitizer(limit, page, post_count)
     posts = q.sort("timestamp", pymongo.DESCENDING).skip(page * limit).limit(limit)
     c.form = W.preview_post_form
     c.pager = W.pager
     return dict(posts=posts, page=page, limit=limit, count=post_count)
开发者ID:joequant,项目名称:allura,代码行数:12,代码来源:main.py


示例15: index

 def index(self, limit=None, page=0, count=0, **kw):
     c.thread = self.W.thread
     c.thread_header = self.W.thread_header
     limit, page, start = g.handle_paging(limit, page)
     self.thread.num_views += 1
     M.session.artifact_orm_session._get().skip_mod_date = True # the update to num_views shouldn't affect it
     count = self.thread.query_posts(page=page, limit=int(limit)).count()
     return dict(discussion=self.thread.discussion,
                 thread=self.thread,
                 page=int(page),
                 count=int(count),
                 limit=int(limit),
                 show_moderate=kw.get('show_moderate'))
开发者ID:johnsca,项目名称:incubator-allura,代码行数:13,代码来源:discuss.py


示例16: index

 def index(self, sort='alpha', limit=25, page=0, **kw):
     c.project_summary = W.project_summary
     c.page_list = W.page_list
     limit, page, start = g.handle_paging(limit, page)
     projects, count = self._find_projects(sort=sort, limit=limit, start=start)
     title = self._build_title()
     c.custom_sidebar_menu = self._build_nav()
     return dict(projects=projects,
                 title=title,
                 text=None,
                 neighborhood=self.neighborhood,
                 sort=sort,
                 limit=limit, page=page, count=count)
开发者ID:pombredanne,项目名称:incubator-allura,代码行数:13,代码来源:project.py


示例17: _search

    def _search(self, model, fields, add_fields, q=None, f=None, page=0, limit=None, **kw):
        all_fields = fields + [(fld, fld) for fld in add_fields]
        c.search_form = W.admin_search_form(all_fields)
        c.page_list = W.page_list
        c.page_size = W.page_size
        count = 0
        objects = []
        limit, page, start = g.handle_paging(limit, page, default=25)
        if q:
            match = search.site_admin_search(model, q, f, rows=limit, start=start)
            if match:
                count = match.hits
                objects = match.docs
                ids = [obj['id'].split('#')[1] for obj in objects]
                ids = [bson.ObjectId(_id) for _id in ids if _id != 'None']
                mongo_objects = {}
                for obj in model.query.find({'_id': {'$in': ids}}):
                    mongo_objects[str(obj._id)] = obj

                for i in range(len(objects)):
                    obj = objects[i]
                    _id = obj['id'].split('#')[1]
                    obj['object'] = mongo_objects.get(_id)
                # Some objects can be deleted, but still have index in solr, should skip those
                objects = [o for o in objects if o.get('object')]

        def convert_fields(obj):
            # throw the type away (e.g. '_s' from 'url_s')
            result = {}
            for k,val in obj.iteritems():
                name = k.rsplit('_', 1)
                if len(name) == 2:
                    name = name[0]
                else:
                    name = k
                result[name] = val
            return result

        return {
            'q': q,
            'f': f,
            'objects': map(convert_fields, objects),
            'count': count,
            'page': page,
            'limit': limit,
            'fields': fields,
            'additional_fields': add_fields,
            'type_s': model.type_s,
        }
开发者ID:abhinavthomas,项目名称:allura,代码行数:49,代码来源:site_admin.py


示例18: new_projects

 def new_projects(self, page=0, limit=100, **kwargs):
     c.page_list = W.page_list
     c.page_size = W.page_size
     limit, pagenum, start = g.handle_paging(limit, page, default=100)
     count = 0
     nb = M.Neighborhood.query.get(name='Users')
     projects = (M.Project.query.find({'neighborhood_id': {'$ne': nb._id}})
                                .sort('_id', -1))
     count = projects.count()
     projects = projects.skip(start).limit(limit)
     return {
         'projects': projects,
         'limit': limit,
         'pagenum': pagenum,
         'count': count
     }
开发者ID:johnsca,项目名称:incubator-allura,代码行数:16,代码来源:site_admin.py


示例19: index

 def index(self, threads=None, limit=None, page=0, count=0, **kw):
     if self.discussion.deleted:
         redirect(self.discussion.url() + 'deleted')
     limit, page, start = g.handle_paging(limit, page)
     c.subscribed = M.Mailbox.subscribed(artifact=self.discussion)
     threads = DM.ForumThread.query.find(dict(discussion_id=self.discussion._id, num_replies={'$gt': 0})) \
                                   .sort([('flags', pymongo.DESCENDING), ('last_post_date', pymongo.DESCENDING)])
     c.discussion = self.W.discussion
     c.discussion_header = self.W.discussion_header
     c.whole_forum_subscription_form = self.W.subscribe_form
     return dict(
         discussion=self.discussion,
         count=threads.count(),
         threads=threads.skip(start).limit(int(limit)).all(),
         limit=limit,
         page=page)
开发者ID:heiths,项目名称:allura,代码行数:16,代码来源:forum.py


示例20: index

 def index(self, page=0, limit=DEFAULT_PAGE_LIMIT, **kw):
     c.revision_widget = self.revision_widget
     c.page_list = self.page_list
     result = dict(commit=self._commit)
     if self._commit:
         result.update(self._commit.context())
     tree = self._commit.tree
     limit, page, start = g.handle_paging(limit, page,
                                          default=self.DEFAULT_PAGE_LIMIT)
     diffs = self._commit.paged_diffs(start=start, end=start + limit)
     result['artifacts'] = [
         (t, f) for t in ('added', 'removed', 'changed', 'copied')
         for f in diffs[t]
         if t == 'removed' or tree.get_blob_by_path(f)]
     count = diffs['total']
     result.update(dict(page=page, limit=limit, count=count))
     return result
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:17,代码来源:repository.py



注:本文中的pylons.app_globals.handle_paging函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python app_globals.make_lock函数代码示例发布时间:2022-05-25
下一篇:
Python pylons.Response类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap