Ejemplo n.º 1
0
 def _refresh_counts(self):
     # Refresh bin counts
     self._bin_counts_data = []
     for b in Bin.query.find(dict(app_config_id=self.app_config_id)):
         r = search_artifact(Ticket, b.terms, rows=0)
         hits = r is not None and r.hits or 0
         self._bin_counts_data.append(dict(summary=b.summary, hits=hits))
     self._bin_counts_expire = \
         datetime.utcnow() + timedelta(minutes=60)
Ejemplo n.º 2
0
 def _refresh_counts(self):
     # Refresh bin counts
     self._bin_counts_data = []
     for b in Bin.query.find(dict(
             app_config_id=self.app_config_id)):
         r = search_artifact(Ticket, b.terms, rows=0)
         hits = r is not None and r.hits or 0
         self._bin_counts_data.append(dict(summary=b.summary, hits=hits))
     self._bin_counts_expire = \
         datetime.utcnow() + timedelta(minutes=60)
Ejemplo n.º 3
0
 def update_bin_counts(self):
     # Refresh bin counts
     self._bin_counts_data = []
     for b in Bin.query.find(dict(app_config_id=self.app_config_id)):
         if b.terms and '$USER' in b.terms:
             continue  # skip queries with $USER variable, hits will be inconsistent for them
         r = search_artifact(Ticket, b.terms, rows=0, short_timeout=False)
         hits = r is not None and r.hits or 0
         self._bin_counts_data.append(dict(summary=b.summary, hits=hits))
     self._bin_counts_expire = \
         datetime.utcnow() + timedelta(minutes=60)
     self._bin_counts_invalidated = None
Ejemplo n.º 4
0
 def update_bin_counts(self):
     # Refresh bin counts
     self._bin_counts_data = []
     for b in Bin.query.find(dict(
             app_config_id=self.app_config_id)):
         if b.terms and '$USER' in b.terms:
             continue  # skip queries with $USER variable, hits will be inconsistent for them
         r = search_artifact(Ticket, b.terms, rows=0, short_timeout=False)
         hits = r is not None and r.hits or 0
         self._bin_counts_data.append(dict(summary=b.summary, hits=hits))
     self._bin_counts_expire = \
         datetime.utcnow() + timedelta(minutes=60)
     self._bin_counts_invalidated = None
Ejemplo n.º 5
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 = []
Ejemplo n.º 6
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 = []
Ejemplo n.º 7
0
    def paged_search(cls, app_config, user, q, limit=None, page=0, sort=None, show_deleted=False, **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 desc'
        if  'ticket_num_i' not in refined_sort:
            refined_sort += ',ticket_num_i asc'
        try:
            if q:
                matches = search_artifact(
                    cls, q, short_timeout=True,
                    rows=limit, sort=refined_sort, start=start, fl='ticket_num_i', **kw)
            else:
                matches = None
            solr_error = None
        except SearchError as e:
            solr_error = e
            matches = []
        if matches:
            count = matches.hits
            # ticket_numbers is in sorted order
            ticket_numbers = [match['ticket_num_i'] for match in matches.docs]
            # but query, unfortunately, returns results in arbitrary order
            query = cls.query.find(dict(app_config_id=app_config._id, ticket_num={'$in':ticket_numbers}))
            # so stick all the results in a dictionary...
            ticket_for_num = {}
            for t in query:
                ticket_for_num[t.ticket_num] = t
            # and pull them out in the order given by ticket_numbers
            tickets = []
            for tn in ticket_numbers:
                if tn in ticket_for_num:
                    show_deleted = show_deleted and security.has_access(ticket_for_num[tn], 'delete', user, app_config.project.root_project)
                    if (security.has_access(ticket_for_num[tn], 'read', user, app_config.project.root_project) and
                        (show_deleted or ticket_for_num[tn].deleted==False)):
                        tickets.append(ticket_for_num[tn])
                    else:
                        count = count -1
        return dict(tickets=tickets,
                    count=count, q=q, limit=limit, page=page, sort=sort,
                    solr_error=solr_error, **kw)
Ejemplo n.º 8
0
    def paged_search(cls,
                     app_config,
                     user,
                     q,
                     limit=None,
                     page=0,
                     sort=None,
                     show_deleted=False,
                     **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 desc'
        if 'ticket_num_i' not in refined_sort:
            refined_sort += ',ticket_num_i asc'
        try:
            if q:
                matches = search_artifact(cls,
                                          q,
                                          short_timeout=True,
                                          rows=limit,
                                          sort=refined_sort,
                                          start=start,
                                          fl='ticket_num_i',
                                          **kw)
            else:
                matches = None
            solr_error = None
        except SearchError as e:
            solr_error = e
            matches = []
        if matches:
            count = matches.hits
            # ticket_numbers is in sorted order
            ticket_numbers = [match['ticket_num_i'] for match in matches.docs]
            # but query, unfortunately, returns results in arbitrary order
            query = cls.query.find(
                dict(app_config_id=app_config._id,
                     ticket_num={'$in': ticket_numbers}))
            # so stick all the results in a dictionary...
            ticket_for_num = {}
            for t in query:
                ticket_for_num[t.ticket_num] = t
            # and pull them out in the order given by ticket_numbers
            tickets = []
            for tn in ticket_numbers:
                if tn in ticket_for_num:
                    show_deleted = show_deleted and security.has_access(
                        ticket_for_num[tn], 'delete', user,
                        app_config.project.root_project)
                    if (security.has_access(ticket_for_num[tn], 'read', user,
                                            app_config.project.root_project)
                            and
                        (show_deleted or ticket_for_num[tn].deleted == False)):
                        tickets.append(ticket_for_num[tn])
                    else:
                        count = count - 1
        return dict(tickets=tickets,
                    count=count,
                    q=q,
                    limit=limit,
                    page=page,
                    sort=sort,
                    solr_error=solr_error,
                    **kw)