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


Python Query.from_string方法代码示例

本文整理汇总了Python中trac.ticket.query.Query.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Query.from_string方法的具体用法?Python Query.from_string怎么用?Python Query.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.ticket.query.Query的用法示例。


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

示例1: test_repeated_constraint_field

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
 def test_repeated_constraint_field(self):
     like_query = Query.from_string(self.env, "owner!=someone|someone_else", order="id")
     query = Query.from_string(self.env, "owner!=someone&owner!=someone_else", order="id")
     like_sql, like_args = like_query.get_sql()
     sql, args = query.get_sql()
     self.assertEqualSQL(sql, like_sql)
     self.assertEqual(args, like_args)
     tickets = query.execute(self.req)
开发者ID:dafrito,项目名称:trac-mirror,代码行数:10,代码来源:query.py

示例2: _get_product_info

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def _get_product_info(self, product, href, resource, max_):
        penv = ProductEnvironment(self.env, product.prefix)
        results = []

        # some queries return a list/tuple, some a generator,
        # hence count() to get the result length
        def count(iter_):
            try:
                return len(iter_)
            except TypeError:
                return sum(1 for _ in iter_)

        query = resource['type'].select(penv)
        for q in itertools.islice(query, max_):
            q.url = href(resource['name'], q.name) \
                if resource.get('hrefurl') \
                else Query.from_string(penv,
                    '%s=%s&%s&col=%s' % (resource['name'], q.name,
                                         self.COMMON_QUERY, resource['name'])
            ).get_href(href)
            q.ticket_count = penv.db_query("""
                SELECT COUNT(*) FROM ticket WHERE ticket.%s='%s'
                AND ticket.status <> 'closed'
                """ % (resource['name'], q.name))[0][0]

            results.append(q)

        # add a '(No <milestone/component/version>)' entry if there are
        # tickets without an assigned resource in the product
        ticket_count = penv.db_query(
            """SELECT COUNT(*) FROM ticket WHERE %s=''
               AND status <> 'closed'""" % (resource['name'],))[0][0]
        if ticket_count != 0:
            q = resource['type'](penv)
            q.name = '(No %s)' % (resource['name'],)
            q.url = Query.from_string(penv,
               'status=!closed&col=id&col=summary&col=owner'
               '&col=status&col=priority&order=priority&%s='
               % (resource['name'],)
            ).get_href(href)
            q.ticket_count = ticket_count
            results.append(q)

        results.sort(key=lambda x: x.ticket_count, reverse=True)

        # add a link to the resource list if there are
        # more than max resources defined
        if count(query) > max_:
            q = resource['type'](penv)
            q.name = _('... more')
            q.ticket_count = None
            q.url = href(resource['name']) if resource.get('hrefurl') \
                else href.dashboard()
            results.append(q)

        return results
开发者ID:mohsadki,项目名称:dargest,代码行数:58,代码来源:product.py

示例3: __init__

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def __init__(self, env, **kwargs):
        self.env = env

        if kwargs:
            querystring = "type=testrun"
            for key, value in kwargs.iteritems():
                querystring += "&%s=%s" % (key, value)
            self.query = TicketQuery.from_string(env, querystring)
        else:
            # query * testrun tickets
            self.query = TicketQuery.from_string(env, "type=testrun")
开发者ID:InQuant,项目名称:TracTestManager,代码行数:13,代码来源:models.py

示例4: test_template_data

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def test_template_data(self):
        req = Mock(href=self.env.href, perm=MockPerm(), authname="anonymous", tz=None, locale=None)
        context = web_context(req, "query")

        query = Query.from_string(self.env, "owner=$USER&order=id")
        tickets = query.execute(req)
        data = query.template_data(context, tickets, req=req)
        self.assertEqual(["anonymous"], data["clauses"][0]["owner"]["values"])

        query = Query.from_string(self.env, "owner=$USER&order=id")
        tickets = query.execute(req)
        data = query.template_data(context, tickets)
        self.assertEqual(["$USER"], data["clauses"][0]["owner"]["values"])
开发者ID:dafrito,项目名称:trac-mirror,代码行数:15,代码来源:query.py

示例5: test_template_data

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def test_template_data(self):
        req = Mock(href=self.env.href, perm=MockPerm(), authname='anonymous',
                   tz=None, locale=None)
        context = web_context(req, 'query')

        query = Query.from_string(self.env, 'owner=$USER&order=id')
        tickets = query.execute(req)
        data = query.template_data(context, tickets, req=req)
        self.assertEqual(['anonymous'], data['clauses'][0]['owner']['values'])

        query = Query.from_string(self.env, 'owner=$USER&order=id')
        tickets = query.execute(req)
        data = query.template_data(context, tickets)
        self.assertEqual(['$USER'], data['clauses'][0]['owner']['values'])
开发者ID:moreati,项目名称:trac-gitsvn,代码行数:16,代码来源:query.py

示例6: expand_macro

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def expand_macro(self, formatter, name, content):
        req = formatter.req
        stats_provider, kwargs, preview = self._parse_macro_content(content, req)

        # Create & execute the query string
        qstr = '&'.join(['%s=%s' % item
                               for item in kwargs.iteritems()])
        query = Query.from_string(self.env, qstr)
        try:
            # XXX: simplification, may cause problems with more complex queries
            constraints = query.constraints[0]
        except IndexError:
            constraints = {}

        # Calculate stats
        qres = query.execute(req)
        tickets = apply_ticket_permissions(self.env, req, qres)

        stats = get_ticket_stats(stats_provider, tickets)
        stats_data = query_stats_data(req, stats, constraints)

        # ... and finally display them
        add_stylesheet(req, 'common/css/roadmap.css')
        chrome = Chrome(self.env)
        stats_data.update({'preview': preview})     # displaying a preview?
        return chrome.render_template(req, 'progressmeter.html', stats_data,
                                      fragment=True)
开发者ID:andrejtokarcik,项目名称:trac-progressmetermacro,代码行数:29,代码来源:macro.py

示例7: get_profile_actions

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def get_profile_actions(self, req, user):
        """
        Return list of actions
        """
        actions = []
        homeperm = self._get_home_perm(req)
        uresource = Resource('user', user.id)

        # Project settings for own account
        if user.username == req.authname:
            actions.append((-40, tag.a(_('View your projects'), href=homeperm.env.href('myprojects'))))
            actions.append((0, tag.a(_('Edit your settings'), href=homeperm.env.href('prefs'))))
        # View other user profile
        else:
            actions.append((-50, tag.a(_('View service profile'), href=homeperm.env.href('user', user.username))))

        # If user can fully manage account
        if homeperm.has_permission('USER_EDIT', uresource):
            label = 'Manage your account' if user.username == req.authname else 'Manage account'
            actions.append((-2, tag.a(_(label), href=homeperm.env.href('admin/users/manage', username=user.username))))

        # Tickets assigned to or created by user (if component is enabled and user has permissions to view them)
        # Note: href.kwargs cannot be used because of reserved word 'or' and un-ordered nature of dict
        if (self.env.is_component_enabled('trac.ticket.query.QueryModule') or
            self.env.is_component_enabled('multiproject.project.tickets.viewtickets.QueryModuleInterceptor')) \
            and 'TICKET_VIEW' in req.perm:
            qstring = 'owner={0}&or&reporter={0}&group=status'.format(user.username)
            query = Query.from_string(self.env, qstring)
            actions.append((5, (tag.a(_('View tickets'), href=query.get_href(req.href)))))

        return actions
开发者ID:juhamust,项目名称:multiproject,代码行数:33,代码来源:profile.py

示例8: expand_macro

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def expand_macro(self, formatter, name, content):
        req = formatter.req
        query_string = ""
        argv, kwargs = parse_args(content, strict=False)

        if "order" not in kwargs:
            kwargs["order"] = "id"
        if "max" not in kwargs:
            kwargs["max"] = "0"  # unlimited by default

        query_string = "&".join(["%s=%s" % item for item in kwargs.iteritems()])
        query = Query.from_string(self.env, query_string)

        tickets = query.execute(req)
        tickets = [t for t in tickets if "TICKET_VIEW" in req.perm("ticket", t["id"])]
        ticket_ids = [t["id"] for t in tickets]

        # locate the tickets
        geoticket = GeoTicket(self.env)
        locations = geoticket.locate_tickets(ticket_ids, req)

        if not locations:
            return tag.div(tag.b("MapTickets: "), "No locations found for ", tag.i(content))

        data = dict(locations=Markup(simplejson.dumps(locations)), query_href=query.get_href(req), query_string=content)

        # set an id for the map
        map_id = req.environ.setdefault("MapTicketsId", 0) + 1
        req.environ["MapTicketsId"] = map_id
        data["map_id"] = "tickets-map-%d" % map_id

        return Chrome(self.env).render_template(req, "map_tickets.html", data, None, fragment=True)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:34,代码来源:query.py

示例9: execute_query

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
def execute_query(env, req, query_args):
    # set maximum number of returned tickets to 0 to get all tickets at once
    query_args['max'] = 0
    # urlencode the args, converting back a few vital exceptions:
    # see the authorized fields in the query language in
    # http://trac.edgewall.org/wiki/TracQuery#QueryLanguage
    query_string = unicode_urlencode(query_args)\
                        .replace('%21=', '!=')\
                        .replace('%21%7E=', '!~=')\
                        .replace('%7E=', '~=')\
                        .replace('%5E=', '^=')\
                        .replace('%24=', '$=')\
                        .replace('%21%5E=', '!^=')\
                        .replace('%21%24=', '!$=')\
                        .replace('%7C', '|')\
                        .replace('+', ' ')\
                        .replace('%23', '#')\
                        .replace('%28', '(')\
                        .replace('%29', ')')\
                        .replace('%2F', '/')
    env.log.debug("query_string: %s" % query_string)
    query = Query.from_string(env, query_string)

    tickets = query.execute(req)

    tickets = [t for t in tickets
               if ('TICKET_VIEW' or 'TICKET_VIEW_CC') in req.perm('ticket', t['id'])]

    return tickets
开发者ID:Konubinix,项目名称:estimationtoolsplugin,代码行数:31,代码来源:utils.py

示例10: expand_macro

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def expand_macro(self, formatter, name, content):
        req = formatter.req
        stats_provider, kwargs = self._parse_macro_content(content, req)

        # Create & execute the query string
        qstr = '&'.join(['%s=%s' % item
                               for item in kwargs.iteritems()])
        query = Query.from_string(self.env, qstr, max=0)
        try:
            constraints = query.constraints[0]
        except IndexError:
            constraints = query.constraints

        # Calculate stats
        qres = query.execute(req)
        tickets = apply_ticket_permissions(self.env, req, qres)

        stats = get_ticket_stats(stats_provider, tickets)
        stats_data = query_stats_data(req, stats, constraints)

        # ... and finally display them
        add_stylesheet(req, 'common/css/roadmap.css')
        chrome = Chrome(self.env)
        return chrome.render_template(req, 'progressmeter.html', stats_data,
                                      fragment=True)
开发者ID:pombredanne,项目名称:trac-progressmetermacro,代码行数:27,代码来源:macro.py

示例11: expand_macro

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def expand_macro(self, formatter, name, content):
        req = formatter.req

        # Parse arguments
        args, kwargs = parse_args(content, strict=False)
        assert not args and not ('status' in kwargs or 'format' in kwargs), \
          "Invalid input!"
        # hack the `format` kwarg in order to display all-tickets stats
        # when no kwargs are supplied
        kwargs['format'] = 'count'

        # special case for values equal to 'self': replace with current
        # ticket number, if available
        for key in kwargs.keys():
            if kwargs[key] == 'self':
                current_ticket = self._this_ticket(req)
                if current_ticket: kwargs[key] = current_ticket

        # Create & execute the query string
        qstr = '&'.join(['%s=%s' % item
                                for item in kwargs.iteritems()])
        query = Query.from_string(self.env, qstr, max=0)

        # Calculate stats
        qres = query.execute(req)
        tickets = apply_ticket_permissions(self.env, req, qres)

        stats = get_ticket_stats(self.stats_provider, tickets)
        stats_data = query_stats_data(req, stats, query.constraints)

        # ... and finally display them
        add_stylesheet(req, 'common/css/roadmap.css')
        chrome = Chrome(self.env)
        return chrome.render_template(req, 'progressmeter.html', stats_data,
                                      fragment=True)
开发者ID:pombredanne,项目名称:trac-progressmetermacro,代码行数:37,代码来源:macro.py

示例12: harvest

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def harvest(self, req, content):
        """TicketQuery provider method."""
        # Parse args and kwargs.
        argv, kwargs = parse_args(content, strict=False)

        # Define minimal set of values.
        std_fields = ['description', 'owner', 'status', 'summary']
        kwargs['col'] = "|".join(std_fields)

        # Options from old 'wikiticketcalendar' section have been migrated to
        # 'wikicalendar' configuration section.
        due_field = self.config.get('wikicalendar', 'ticket.due_field')

        if due_field:
            kwargs['col'] += '|' + due_field

        # Construct the query-string.
        query_string = '&'.join(['%s=%s' % i for i in kwargs.iteritems()])

        # Get the Query object.
        query = Query.from_string(self.env, query_string)

        # Initialize query and get 1st "page" of Ticket objects.
        result = query.execute(req)
        # Collect tickets from all other query "pages", if available.
        while query.offset + query.max < query.num_items:
            query.offset += query.max
            result.extend(query.execute(req))
        # Filter tickets according to (view) permission.
        tickets = [t for t in result
                   if 'TICKET_VIEW' in req.perm('ticket', t['id'])]
        return tickets
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:34,代码来源:ticket.py

示例13: expand_macro

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def expand_macro(self, formatter, name, content):
        req = formatter.req
        stats_provider, kwargs, is_preview_with_self = self._parse_macro_content(content, req)

        if is_preview_with_self:
            # previewing newticket, without a number but with a reference
            # to current ticket number; show a helpful message
            return tag.div('Progress meter will be inserted here in final ticket')

        # Create & execute the query string
        qstr = '&'.join(['%s=%s' % item
                               for item in kwargs.iteritems()])
        query = Query.from_string(self.env, qstr, max=0)
        try:
            constraints = query.constraints[0]
        except IndexError:
            constraints = query.constraints

        # Calculate stats
        qres = query.execute(req)
        tickets = apply_ticket_permissions(self.env, req, qres)

        stats = get_ticket_stats(stats_provider, tickets)
        stats_data = query_stats_data(req, stats, constraints)

        # ... and finally display them
        add_stylesheet(req, 'common/css/roadmap.css')
        chrome = Chrome(self.env)
        return chrome.render_template(req, 'progressmeter.html', stats_data,
                                      fragment=True)
开发者ID:silk,项目名称:trac-progressmetermacro,代码行数:32,代码来源:macro.py

示例14: get_query

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def get_query(self, constraints=None, args=None):
        req = self.req
        if not args:
            args = req.args
        if not constraints:
            # If no constraints are given in the URL, use the default ones.
            if req.authname and req.authname != 'anonymous':
                qstring = self.default_query
                user = req.authname
            else:
                email = req.session.get('email')
                name = req.session.get('name')
                qstring = self.default_anonymous_query
                user = email or name or None

            query = Query.from_string(self.env, qstring)
            args = {'order': query.order, 'col': query.cols, 'max': 0}
            constraints = query.constraints

            # Substitute $USER, or ensure no field constraints that depend
            # on $USER are used if we have no username.
            for clause in constraints:
                for field, vals in clause.items():
                    for (i, val) in enumerate(vals):
                        if user:
                            vals[i] = val.replace('$USER', user)
                        elif val.endswith('$USER'):
                            del clause[field]
                            break

        query = Query(self.env, args.get('report'), constraints,
                      self._get_cols(), args.get('order'), args.get('desc'))
        self._set_no_paginator(query)
        return query
开发者ID:KKBOX,项目名称:trac-ticket-calendar-plugin,代码行数:36,代码来源:web_ui.py

示例15: harvest

# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import from_string [as 别名]
    def harvest(self, req, content):
        """TicketQuery provider method."""
        # Options in 'wikicalendar' configuration section take precedence over
        # those in old 'wikiticketcalendar' section.
        c = self.config
        if 'wikicalendar' in c.sections():
            tkt_due_field = c.get('wikicalendar', 'ticket.due_field')
        else:
            tkt_due_field = c.get('wikiticketcalendar',
                                  'ticket.due_field.name')

        # Parse args and kwargs.
        argv, kwargs = parse_args(content, strict=False)

        # Define minimal set of values.
        std_fields = ['description', 'owner', 'status', 'summary']
        kwargs['col'] = "|".join(std_fields + [tkt_due_field])

        # Construct the querystring.
        query_string = '&'.join(['%s=%s' %
            item for item in kwargs.iteritems()])

        # Get the Query Object.
        query = Query.from_string(self.env, query_string)

        # Get the tickets.
        tickets = self._get_tickets(query, req)
        return tickets
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:ticket.py


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