Пример #1
0
 def search(self,
            q=None,
            history=False,
            project=False,
            limit=None,
            page=0,
            **kw):
     'local tool search'
     if project:
         redirect(c.project.url() + 'search?' +
                  urlencode(dict(q=q, history=history)))
     results = []
     count = 0
     limit, page, start = g.handle_paging(limit, page, default=25)
     if not q:
         q = ''
     else:
         results = search(
             q,
             rows=limit,
             start=start,
             fq=[
                 'is_history_b:%s' % history,
                 'project_id_s:%s' % c.project._id,
                 'mount_point_s:%s' % c.app.config.options.mount_point,
                 '-deleted_b:true'
             ])
         if results: count = results.hits
     c.search_results = self.W.search_results
     return dict(q=q,
                 history=history,
                 results=results or [],
                 count=count,
                 limit=limit,
                 page=page)
Пример #2
0
    def url_paginated(self):
        '''Return link to the thread with a #target that poins to this comment.

        Also handle pagination properly.
        '''
        if not self.thread:  # pragma no cover
            return None
        limit, p, s = g.handle_paging(None, 0)  # get paging limit
        if self.query.find(dict(thread_id=self.thread._id)).count() <= limit:
            # all posts in a single page
            page = 0
        else:
            posts = self.thread.find_posts()
            posts = self.thread.create_post_threads(posts)

            def find_i(posts):
                '''Find the index number of this post in the display order'''
                q = []
                def traverse(posts):
                    for p in posts:
                        if p['post']._id == self._id:
                            return True  # found
                        q.append(p)
                        if traverse(p['children']):
                            return True
                traverse(posts)
                return len(q)

            page = find_i(posts) / limit

        slug = h.urlquote(self.slug)
        url = self.thread.url()
        if page == 0:
            return '%s?limit=%s#%s' % (url, limit, slug)
        return '%s?limit=%s&page=%s#%s' % (url, limit, page, slug)
Пример #3
0
    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,
                    )
Пример #4
0
    def search(self,
               q=None,
               history=None,
               project=None,
               limit=None,
               page=0,
               **kw):
        if project:
            redirect(c.project.url() + 'search?' +
                     urlencode(dict(q=q, history=history)))
        results = []
        count = 0
        limit, page, start = g.handle_paging(limit, page, default=25)
        if not q:
            q = ''
        else:
            query = [
                'is_history_b:%s' % history,
                'project_id_s:%s' % c.project._id,
                'mount_point_s:%s' % c.app.config.options.mount_point,
                'type_s:%s' % ShortUrl.type_s
            ]
            if not has_access(c.app, 'view_private'):
                query.append('private_b:False')
            results = search(q, fq=query)

            if results:
                count = results.hits
        c.search_results = W.search_results
        return dict(q=q,
                    history=history,
                    results=results or [],
                    count=count,
                    limit=limit,
                    page=page)
Пример #5
0
    def paged_query(cls, app_config, user, query, limit=None, page=0, sort=None, **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))
        q = q.sort('ticket_num')
        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):
                tickets.append(t)
            else:
                count = count -1

        return dict(
            tickets=tickets,
            count=count, q=json.dumps(query), limit=limit, page=page, sort=sort,
            **kw)
Пример #6
0
    def search(self, q=None,
               history=None, project=None,
               limit=None, page=0, **kw):
        if project:
            redirect(c.project.url() +
                     'search?' +
                     urlencode(dict(q=q, history=history)))
        results = []
        count = 0
        limit, page, start = g.handle_paging(limit, page, default=25)
        if not q:
            q = ''
        else:
            query = ['is_history_b:%s' % history,
                    'project_id_s:%s' % c.project._id,
                    'mount_point_s:%s' % c.app.config.options.mount_point,
                    'type_s:%s' % ShortUrl.type_s]
            if not has_access(c.app, 'view_private'):
                query.append('private_b:False')
            results = search(q, fq=query)

            if results:
                count = results.hits
        c.search_results = W.search_results
        return dict(q=q, history=history, results=results or [],
                    count=count, limit=limit, page=page)
Пример #7
0
    def url_paginated(self):
        '''Return link to the thread with a #target that poins to this comment.

        Also handle pagination properly.
        '''
        if not self.thread:  # pragma no cover
            return None
        limit, p, s = g.handle_paging(None, 0)  # get paging limit
        if self.query.find(dict(thread_id=self.thread._id)).count() <= limit:
            # all posts in a single page
            page = 0
        else:
            posts = self.thread.find_posts()
            posts = self.thread.create_post_threads(posts)

            def find_i(posts):
                '''Find the index number of this post in the display order'''
                q = []
                def traverse(posts):
                    for p in posts:
                        if p['post']._id == self._id:
                            return True  # found
                        q.append(p)
                        if traverse(p['children']):
                            return True
                traverse(posts)
                return len(q)

            page = find_i(posts) / limit

        slug = h.urlquote(self.slug)
        url = self.thread.url()
        if page == 0:
            return '%s?limit=%s#%s' % (url, limit, slug)
        return '%s?limit=%s&page=%s#%s' % (url, limit, page, slug)
Пример #8
0
    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,
        )
Пример #9
0
 def search(self, q=None, history=False, project=False, limit=None, page=0, **kw):
     'local tool search'
     if project:
         redirect(c.project.url() + 'search?' + urlencode(dict(q=q, history=history)))
     results = []
     count=0
     limit, page, start = g.handle_paging(limit, page, default=25)
     if not q:
         q = ''
     else:
         results = search(
             q, rows=limit, start=start,
             fq=[
                 'is_history_b:%s' % history,
                 'project_id_s:%s' % c.project._id,
                 'mount_point_s:%s'% c.app.config.options.mount_point,
                 '-deleted_b:true'])
         if results: count=results.hits
     c.search_results = self.W.search_results
     if results is not None:
         for doc in results:
             if doc.get('type_s', '') == 'Post':
                 _id = doc.get('id').split('#')
                 _id = _id[-1].replace('/', '.') if _id else ''
                 p = model.ForumPost.query.get(_id=_id)
                 doc['url_paginated'] = p.url_paginated()
     return dict(q=q, history=history, results=results or [],
                 count=count, limit=limit, page=page)
Пример #10
0
 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)
Пример #11
0
 def index(self, sort='alpha', limit=25, page=0, **kw):
     c.project = self.neighborhood.neighborhood_project
     if self.neighborhood.redirect:
         redirect(self.neighborhood.redirect)
     if not self.neighborhood.has_home_tool:
         mount = c.project.first_mount()
         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 + '/')
     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['plus']),
             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=g.markdown.convert(self.neighborhood.homepage),
                 projects=projects,
                 sort=sort,
                 limit=limit,
                 page=page,
                 count=count)
Пример #12
0
 def history(self, page=0, limit=None):
     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)
Пример #13
0
 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)
Пример #14
0
 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'))
Пример #15
0
 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)
Пример #16
0
 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'))
Пример #17
0
    def paged_search(cls,
                     app_config,
                     user,
                     q,
                     limit=None,
                     page=0,
                     sort=None,
                     **kw):
        """Query tickets from Solr, filtering for 'read' permission, sorting and paginating the result.

        See also paged_query which does a mongo search.

        We do the sorting and skipping right in SOLR, before we ever ask
        Mongo for the actual tickets.  Other keywords for
        search_artifact (e.g., history) or for SOLR are accepted through
        kw.  The output is intended to be used directly in templates,
        e.g., exposed controller methods can just:

            return paged_query(q, ...)

        If you want all the results at once instead of paged you have
        these options:
          - don't call this routine, search directly in mongo
          - call this routine with a very high limit and TEST that
            count<=limit in the result
        limit=-1 is NOT recognized as 'all'.  500 is a reasonable limit.
        """

        limit, page, start = g.handle_paging(limit, page, default=25)
        count = 0
        tickets = []
        refined_sort = sort if sort else 'ticket_num_i asc'
        if 'ticket_num_i' not in refined_sort:
            refined_sort += ',ticket_num_i asc'
        try:
            if q:
                matches = search_artifact(cls,
                                          q,
                                          rows=limit,
                                          sort=refined_sort,
                                          start=start,
                                          fl='ticket_num_i',
                                          **kw)
            else:
                matches = None
            solr_error = None
        except ValueError, e:
            solr_error = e.args[0]
            matches = []
Пример #18
0
 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
     }
Пример #19
0
 def log(self, limit=None, page=0, count=0, **kw):
     limit, page, start = g.handle_paging(limit, page)
     revisions = c.app.repo.log(
             branch=self._commit._id,
             offset=start,
             limit=limit)
     c.log_widget = self.log_widget
     count = 0
     return dict(
         username=c.user._id and c.user.username,
         branch=None,
         log=revisions,
         page=page,
         limit=limit,
         count=count,
         **kw)
Пример #20
0
 def log(self, limit=25, page=0, **kw):
     limit, page, start = g.handle_paging(limit, page, default=25)
     revisions = c.app.repo.log(
             branch=self._commit._id,
             offset=start,
             limit=limit)
     count = c.app.repo.count(branch=self._commit._id)
     c.log_widget = self.log_widget
     return dict(
         username=c.user._id and c.user.username,
         branch=None,
         log=revisions,
         page=page,
         limit=limit,
         count=count,
         **kw)
Пример #21
0
 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)
Пример #22
0
 def index(self, page=0, limit=DEFAULT_PAGE_LIMIT):
     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)
     result['artifacts'] = [
             (t,f) for t in ('added', 'removed', 'changed', 'copied')
                 for f in self._commit.diffs[t]
                     if t == 'removed' or tree.get_blob_by_path(f)]
     count = len(result['artifacts'])
     result['artifacts'] = result['artifacts'][start:start+limit]
     result.update(dict(page=page, limit=limit, count=count))
     return result
Пример #23
0
 def browse_tags(self, sort='alpha', page=0, limit=None):
     'list of all labels in the wiki'
     c.page_list = W.page_list
     c.page_size = W.page_size
     limit, pagenum, start = g.handle_paging(limit, page, default=25)
     count = 0
     page_tags = {}
     q = WM.Page.query.find(dict(app_config_id=c.app.config._id, deleted=False))
     count = q.count()
     q = q.skip(start).limit(int(limit))
     for page in q:
         if page.labels:
             for label in page.labels:
                 if label not in page_tags:
                     page_tags[label] = []
                 page_tags[label].append(page)
     return dict(labels=page_tags, limit=limit, count=count, page=pagenum)
Пример #24
0
    def index(self, page=0, limit=100, **kw):
        c.page_list = W.page_list
        c.page_size = W.page_size
        limit, pagenum, start = g.handle_paging(limit, page, default=100)
        p = {'app_config_id': c.app.config._id}
        if not has_access(c.app, 'view_private'):
            p['private'] = False
        short_urls = (ShortUrl.query.find(p))
        count = short_urls.count()

        short_urls = short_urls.skip(start).limit(limit)

        return {
            'short_urls': short_urls,
            'limit': limit,
            'pagenum': pagenum,
            'count': count
        }
Пример #25
0
    def index(self, page=0, limit=100, **kw):
        c.page_list = W.page_list
        c.page_size = W.page_size
        limit, pagenum, start = g.handle_paging(limit, page, default=100)
        p = {'app_config_id': c.app.config._id}
        if not has_access(c.app, 'view_private'):
            p['private'] = False
        short_urls = (ShortUrl.query.find(p))
        count = short_urls.count()

        short_urls = short_urls.skip(start).limit(limit)

        return {
            'short_urls': short_urls,
            'limit': limit,
            'pagenum': pagenum,
            'count': count
        }
Пример #26
0
 def index(self, sort='alpha', limit=25, page=0, **kw):
     c.project = self.neighborhood.neighborhood_project
     if self.neighborhood.redirect:
         redirect(self.neighborhood.redirect)
     if not self.neighborhood.has_home_tool:
         mount = c.project.first_mount()
         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 + '/')
     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['plus']),
             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=g.markdown.convert(self.neighborhood.homepage),
                 projects=projects,
                 sort=sort,
                 limit=limit, page=page, count=count)
Пример #27
0
 def search(self,
            q=None,
            history=False,
            project=False,
            limit=None,
            page=0,
            **kw):
     'local tool search'
     if project:
         redirect(c.project.url() + 'search?' +
                  urlencode(dict(q=q, history=history)))
     results = []
     count = 0
     limit, page, start = g.handle_paging(limit, page, default=25)
     if not q:
         q = ''
     else:
         results = search(
             q,
             rows=limit,
             start=start,
             fq=[
                 'is_history_b:%s' % history,
                 'project_id_s:%s' % c.project._id,
                 'mount_point_s:%s' % c.app.config.options.mount_point,
                 '-deleted_b:true'
             ])
         if results: count = results.hits
     c.search_results = self.W.search_results
     if results is not None:
         for doc in results:
             if doc.get('type_s', '') == 'Post':
                 _id = doc.get('id').split('#')
                 _id = _id[-1].replace('/', '.') if _id else ''
                 p = model.ForumPost.query.get(_id=_id)
                 doc['url_paginated'] = p.url_paginated()
     return dict(q=q,
                 history=history,
                 results=results or [],
                 count=count,
                 limit=limit,
                 page=page)
Пример #28
0
 def search(self, q=None, history=None, project=None, limit=None, page=0, **kw):
     'local wiki search'
     if project:
         redirect(c.project.url() + 'search?' + urlencode(dict(q=q, history=history)))
     results = []
     count=0
     limit, page, start = g.handle_paging(limit, page, default=25)
     if not q:
         q = ''
     else:
         results = search(
             q, rows=limit, start=start,
             fq=[
                 'is_history_b:%s' % history,
                 'project_id_s:%s' % c.project._id,
                 'mount_point_s:%s'% c.app.config.options.mount_point,
                 '-deleted_b:true'])
         if results: count=results.hits
     c.search_results = W.search_results
     return dict(q=q, history=history, results=results or [],
                 count=count, limit=limit, page=page)
Пример #29
0
    def paged_query(cls,
                    app_config,
                    user,
                    query,
                    limit=None,
                    page=0,
                    sort=None,
                    **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))
        q = q.sort('ticket_num')
        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):
                tickets.append(t)
            else:
                count = count - 1

        return dict(tickets=tickets,
                    count=count,
                    q=json.dumps(query),
                    limit=limit,
                    page=page,
                    sort=sort,
                    **kw)
Пример #30
0
    def paged_search(cls, app_config, user, q, limit=None, page=0, sort=None, **kw):
        """Query tickets from Solr, filtering for 'read' permission, sorting and paginating the result.

        See also paged_query which does a mongo search.

        We do the sorting and skipping right in SOLR, before we ever ask
        Mongo for the actual tickets.  Other keywords for
        search_artifact (e.g., history) or for SOLR are accepted through
        kw.  The output is intended to be used directly in templates,
        e.g., exposed controller methods can just:

            return paged_query(q, ...)

        If you want all the results at once instead of paged you have
        these options:
          - don't call this routine, search directly in mongo
          - call this routine with a very high limit and TEST that
            count<=limit in the result
        limit=-1 is NOT recognized as 'all'.  500 is a reasonable limit.
        """

        limit, page, start = g.handle_paging(limit, page, default=25)
        count = 0
        tickets = []
        refined_sort = sort if sort else 'ticket_num_i asc'
        if  'ticket_num_i' not in refined_sort:
            refined_sort += ',ticket_num_i asc'
        try:
            if q:
                matches = search_artifact(
                    cls, q,
                    rows=limit, sort=refined_sort, start=start, fl='ticket_num_i', **kw)
            else:
                matches = None
            solr_error = None
        except ValueError, e:
            solr_error = e.args[0]
            matches = []
Пример #31
0
 def browse_pages(self, sort='alpha', show_deleted=False, page=0, limit=None, **kw):
     'list of all pages in the wiki'
     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 = []
     uv_pages = []
     criteria = dict(app_config_id=c.app.config._id)
     can_delete = has_access(c.app, 'delete')()
     show_deleted = show_deleted and can_delete
     if not can_delete:
         criteria['deleted'] = False
     q = WM.Page.query.find(criteria)
     if sort == 'alpha':
         q = q.sort('title')
     count = q.count()
     q = q.skip(start).limit(int(limit))
     for page in q:
         recent_edit = page.history().first()
         p = dict(title=page.title, url=page.url(), deleted=page.deleted)
         if recent_edit:
             p['updated'] = recent_edit.timestamp
             p['user_label'] = recent_edit.author.display_name
             p['user_name'] = recent_edit.author.username
             pages.append(p)
         else:
             if sort == 'recent':
                 uv_pages.append(p)
             else:
                 pages.append(p)
     if sort == 'recent':
         pages.sort(reverse=True, key=lambda x:(x['updated']))
         pages = pages + uv_pages
     return dict(pages=pages, can_delete=can_delete, show_deleted=show_deleted,
                 limit=limit, count=count, page=pagenum)