当前位置: 首页>>代码示例>>Python>>正文


Python app_globals.handle_paging函数代码示例

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


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


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