示例#1
0
 def ticket_created(self, ticket):
     ticketsystem = TicketSystem(self.env)
     resource_name = get_resource_shortname(self.env, ticket.resource)
     resource_desc = ticketsystem.get_resource_description(ticket.resource,
                                                           format='summary')
     so = FullTextSearchObject(
         self.project,
         ticket.resource,
         title=u"%(title)s: %(message)s" % {
             'title': resource_name,
             'message': resource_desc
         },
         author=ticket.values.get('reporter'),
         changed=ticket.values.get('changetime'),
         created=ticket.values.get('time'),
         tags=ticket.values.get('keywords'),
         involved=re.split(r'[;,\s]+', ticket.values.get('cc', ''))
         or ticket.values.get('reporter'),
         popularity=0,  #FIXME
         oneline=shorten_result(ticket.values.get('description', '')),
         body=u'%r' % (ticket.values, ),
         comments=[t[4] for t in ticket.get_changelog()],
     )
     self.backend.create(so, quiet=True)
     self._update_ticket(ticket)
     self.log.debug("Ticket added for indexing: %s", ticket)
示例#2
0
 def _do_view(self, env, req, form):
     data = {}
     form_id = form.resource.id
     data['page_title'] = get_resource_description(env, form.resource,
                                                   href=req.href)
     data['title'] = get_resource_shortname(env, form.resource)
     # prime list with current state
     subcontext, author, time = self.get_tracform_meta(form_id)[3:6]
     if not subcontext == '':
         data['subcontext'] = subcontext
     state = self.get_tracform_state(form_id)
     data['fields'] = self._render_fields(form_id, state)
     history = [{'author': author, 'time': time,
                 'old_state': state}]
     # add recorded old_state
     records = self.get_tracform_history(form_id)
     for author, time, old_state in records:
         history.append({'author': author, 'time': time,
                         'old_state': old_state})
     data['history'] = parse_history(history)
     # show reset button in case of existing data and proper permission
     data['allow_reset'] = req.perm(form.resource) \
                           .has_permission('FORM_RESET') and form.has_data
     add_stylesheet(req, 'tracforms/tracforms.css')
     return 'form.html', data, None
示例#3
0
 def _result(doc):
     changed = doc.changed
     href = get_resource_url(self.env, doc.resource, req.href)
     title = doc.title or get_resource_shortname(self.env, doc.resource)
     author = ", ".join(doc.author or [])
     excerpt = doc.oneline or ''
     return (href, title, changed, author, excerpt)
示例#4
0
 def get_resource_description(self, resource, format=None, **kwargs):
     env = self.env
     href = kwargs.get('href')
     if resource.parent is None:
         return _("Unparented form %(id)s", id=resource.id)
     parent_name = get_resource_name(env, resource.parent)
     parent_url = href and \
                  get_resource_url(env, resource.parent, href) or None
     parent = parent_url is not None and \
              tag.a(parent_name, href=parent_url) or parent_name
     # DEVEL: resource description not implemented yet
     #if format == 'summary':
     #    return Form(self.env, resource).description
     if resource.id:
         if format == 'compact':
             return _("Form %(form_id)s (%(parent)s)",
                      form_id=resource.id,
                      parent=get_resource_shortname(env, resource.parent))
         # TRANSLATOR: Most verbose title, i.e. for form history page
         return tag_("Form %(form_id)s (in %(parent)s)",
                     form_id=resource.id,
                     parent=parent)
     else:
         # TRANSLATOR: Title printed i.e. in form select page
         if format == 'compact':
             return tag_("Forms (%(parent)s)", parent=parent)
         return tag_("Forms in %(parent)s", parent=parent)
 def _result(doc):
     changed = doc.changed
     href = get_resource_url(self.env, doc.resource, req.href)
     title = doc.title or get_resource_shortname(self.env, doc.resource)
     author = ", ".join(doc.author or [])
     excerpt = doc.oneline or ""
     return (href, title, changed, author, excerpt)
    def ticket_created(self, ticket):
        ticketsystem = TicketSystem(self.env)
        resource_name = get_resource_shortname(self.env, ticket.resource)
        resource_desc = ticketsystem.get_resource_description(ticket.resource,
                                                              format='summary')
        # make sure we will index customerrequest name not id
        cr_id = ticket['customerrequest']
        if cr_id:
            db = self.env.get_read_db()
            cursor = db.cursor()
            cursor.execute("SELECT name FROM public.customer_requests "
                           " WHERE id='%s'" % cr_id)
            row = cursor.fetchone()
            if row:
                ticket.values['customerrequest'] = row[0]

        so = FullTextSearchObject(
                self.project, ticket.resource,
                title = u"%(title)s: %(message)s" % {'title': resource_name,
                                                     'message': resource_desc},
                author = ticket.values.get('reporter'),
                changed = ticket.values.get('changetime'),
                created = ticket.values.get('time'),
                tags = ticket.values.get('keywords'),
                involved = re.split(r'[;,\s]+', ticket.values.get('cc', ''))
                           or ticket.values.get('reporter'),
                popularity = 0, #FIXME
                oneline = shorten_result(ticket.values.get('description', '')),
                body = u'%r' % (ticket.values,),
                status = ticket.values.get('status'),
                comments = [t[4] for t in ticket.get_changelog()],
                )
        self.backend.create(so, quiet=True)
        self._update_ticket(ticket)
        self.log.debug("Ticket added for indexing: %s", ticket)
示例#7
0
文件: api.py 项目: nyuhuhuu/trachacks
 def get_resource_description(self, resource, format=None, **kwargs):
     env = self.env
     href = kwargs.get('href')
     if resource.parent is None:
         return _("Unparented form %(id)s", id=resource.id)
     parent_name = get_resource_name(env, resource.parent)
     parent_url = href and \
                  get_resource_url(env, resource.parent, href) or None
     parent = parent_url is not None and \
              tag.a(parent_name, href=parent_url) or parent_name
     # DEVEL: resource description not implemented yet
     #if format == 'summary':
     #    return Form(self.env, resource).description
     if resource.id:
         if format == 'compact':
             return _("Form %(form_id)s (%(parent)s)", form_id=resource.id,
                      parent=get_resource_shortname(env, resource.parent))
         # TRANSLATOR: Most verbose title, i.e. for form history page
         return tag_("Form %(form_id)s (in %(parent)s)",
                     form_id=resource.id, parent=parent)
     else:
         # TRANSLATOR: Title printed i.e. in form select page
         if format == 'compact':
             return tag_("Forms (%(parent)s)", parent=parent)
         return tag_("Forms in %(parent)s", parent=parent)
示例#8
0
    def test_global_neighborhood_report(self):
        target = resource.Neighborhood("global", None).child(self.resource)

        self.assertEquals("[global:] report:1", resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] report:1", resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] report:1", resource.get_resource_shortname(self.env, target))
        self.assertEquals("[global:] report:1 at version None", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/report/1", resource.get_resource_url(self.env, target, self.env.href)
        )
示例#9
0
 def _check_blockers(self, req, ticket):
     if req.args.get('action') == 'resolve':
         blockers = self.rls.find_blockers(ticket, self.is_blocker)
         if blockers:
             blockers_str = ', '.join(
                 get_resource_shortname(self.env, blocker_ticket.resource)
                 for blocker_ticket in unique(blockers))
             msg = ("Cannot resolve this ticket because it is "
                    "blocked by tickets [%s]" % blockers_str)
             yield None, msg
示例#10
0
 def _check_blockers(self, req, ticket):
     if req.args.get('action') == 'resolve':
         blockers = self.rls.find_blockers(ticket, self.is_blocker)
         if blockers:
             blockers_str = ', '.join(
                 get_resource_shortname(self.env, blocker_ticket.resource)
                 for blocker_ticket in unique(blockers))
             msg = ("Cannot resolve this ticket because it is "
                    "blocked by tickets [%s]"
                    % blockers_str)
             yield None, msg
示例#11
0
    def test_product_neighborhood_wiki(self):
        target = resource.Neighborhood("product", u"xü").child(self.resource)

        self.assertEquals(u"TestPage", resource.get_resource_description(self.env, target))
        self.assertEquals(u"TestPage", resource.get_resource_name(self.env, target))
        self.assertEquals(u"TestPage", resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"TestPage", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/products/x%C3%BC/wiki/TestPage?version=2",
            resource.get_resource_url(self.env, target, self.env.href),
        )
示例#12
0
    def test_global_neighborhood_wiki(self):
        target = resource.Neighborhood("global", None).child(self.resource)

        self.assertEquals("TestPage", resource.get_resource_description(self.env, target))
        self.assertEquals("TestPage", resource.get_resource_name(self.env, target))
        self.assertEquals("TestPage", resource.get_resource_shortname(self.env, target))
        self.assertEquals("TestPage", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/wiki/TestPage?version=2",
            resource.get_resource_url(self.env, target, self.env.href),
        )
示例#13
0
    def test_product_neighborhood_report(self):
        target = resource.Neighborhood("product", u"xü").child(self.resource)

        self.assertEquals(u"[product:xü] report:1", resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] report:1", resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] report:1", resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"[product:xü] report:1 at version None", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/products/x%C3%BC/report/1",
            resource.get_resource_url(self.env, target, self.env.href),
        )
示例#14
0
    def test_global_neighborhood_milestone(self):
        target = resource.Neighborhood("global", None).child(self.resource)

        self.assertEquals("[global:] Milestone milestone1", resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] Milestone milestone1", resource.get_resource_name(self.env, target))
        self.assertEquals("milestone1", resource.get_resource_shortname(self.env, target))
        self.assertEquals("[global:] Milestone milestone1", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/milestone/milestone1",
            resource.get_resource_url(self.env, target, self.env.href),
        )
示例#15
0
    def test_global_neighborhood_ticket(self):
        nbh = resource.Neighborhood("global", None)
        data = dict(summary="Ticket summary", description="Ticket description", type="enhancement", status="new")
        target = nbh.child("ticket", self._new_ticket(self.global_env, data))

        self.assertEquals("[global:] Ticket #1", resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] Ticket #1", resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] #1", resource.get_resource_shortname(self.env, target))
        self.assertEquals("enhancement: Ticket summary (new)", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/ticket/1", resource.get_resource_url(self.env, target, self.env.href)
        )
示例#16
0
文件: api.py 项目: tsanov/bloodhound
 def _check_blockers(self, req, ticket):
     action = req.args.get('action')
     operations = self._get_operations_for_action(req, ticket, action)
     if 'set_resolution' in operations:
         blockers = self.rls.find_blockers(ticket, self.is_blocker)
         if blockers:
             blockers_str = ', '.join(
                 get_resource_shortname(self.env, blocker_ticket.resource)
                 for blocker_ticket in unique(blockers))
             msg = ("Cannot resolve this ticket because it is "
                    "blocked by tickets [%s]" % blockers_str)
             yield None, msg
示例#17
0
    def test_product_neighborhood_ticket(self):
        nbh = resource.Neighborhood("product", u"xü")
        data = dict(summary="Ticket summary", description="Ticket description", type="task", status="accepted")
        target = nbh.child("ticket", self._new_ticket(self.env1, data))

        self.assertEquals(u"[product:xü] Ticket #1", resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] Ticket #1", resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] #1", resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"task: Ticket summary (accepted)", resource.get_resource_summary(self.env, target))
        self.assertEquals(
            "http://example.org/trac.cgi/products/x%C3%BC/ticket/1",
            resource.get_resource_url(self.env, target, self.env.href),
        )
示例#18
0
 def _check_blockers(self, req, ticket):
     action = req.args.get('action')
     operations = self._get_operations_for_action(req, ticket, action)
     if 'set_resolution' in operations:
         blockers = self.rls.find_blockers(ticket, self.is_blocker)
         if blockers:
             blockers_str = ', '.join(
                 get_resource_shortname(self.env, blocker_ticket.resource)
                 for blocker_ticket in unique(blockers))
             msg = ("Cannot resolve this ticket because it is "
                    "blocked by tickets [%s]"
                    % blockers_str)
             yield None, msg
示例#19
0
    def test_product_neighborhood_report(self):
        target = resource.Neighborhood('product', u'xü').child(self.resource)

        self.assertEquals(u"[product:xü] report:1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] report:1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] report:1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"[product:xü] report:1 at version None",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/products/x%C3%BC/report/1',
            resource.get_resource_url(self.env, target, self.env.href))
示例#20
0
    def test_product_neighborhood_attachments(self):
        target = resource.Neighborhood('product', u'xü').child(self.resource)

        self.assertEquals(u"[product:xü] Attachment 'foo.txt' in [product:xü] Ticket #1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] Attachment 'foo.txt' in [product:xü] Ticket #1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] foo.txt ([product:xü] Ticket #1)",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('Product Bar',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals('http://example.org/trac.cgi/products/x%C3%BC/attachment/ticket/1/foo.txt',
                          resource.get_resource_url(self.env,
                                                    target, self.env.href))
示例#21
0
    def test_global_neighborhood_wiki(self):
        target = resource.Neighborhood('global', None).child(self.resource)

        self.assertEquals("TestPage",
                          resource.get_resource_description(self.env, target))
        self.assertEquals("TestPage",
                          resource.get_resource_name(self.env, target))
        self.assertEquals("TestPage",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals("TestPage",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/wiki/TestPage?version=2',
            resource.get_resource_url(self.env, target, self.env.href))
示例#22
0
    def test_global_neighborhood_attachments(self):
        target = resource.Neighborhood('global', None).child(self.resource)

        self.assertEquals("[global:] Attachment 'foo.txt' in [global:] Ticket #1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] Attachment 'foo.txt' in [global:] Ticket #1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] foo.txt ([global:] Ticket #1)",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('Global Bar',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals('http://example.org/trac.cgi/attachment/ticket/1/foo.txt',
                          resource.get_resource_url(self.env,
                                                    target, self.env.href))
示例#23
0
    def test_global_neighborhood_report(self):
        target = resource.Neighborhood('global', None).child(self.resource)

        self.assertEquals("[global:] report:1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] report:1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] report:1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('[global:] report:1 at version None',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/report/1',
            resource.get_resource_url(self.env, target, self.env.href))
示例#24
0
    def get_search_results(self, req, terms, filters):
        """Overriding search results for Tickets"""
        if not "ticket" in filters:
            return
        ticket_realm = Resource("ticket")
        with self.env.db_query as db:
            sql, args = search_to_sql(
                db, ["summary", "keywords", "description", "reporter", "cc", db.cast("id", "text")], terms
            )
            sql2, args2 = search_to_sql(db, ["newvalue"], terms)
            sql3, args3 = search_to_sql(db, ["value"], terms)
            ticketsystem = TicketSystem(self.env)
            if req.args.get("product"):
                productsql = "product='%s' AND" % req.args.get("product")
            else:
                productsql = ""

            for summary, desc, author, type, tid, ts, status, resolution in db(
                """SELECT summary, description, reporter, type, id,
                                 time, status, resolution 
                          FROM ticket
                          WHERE (%s id IN (
                              SELECT id FROM ticket WHERE %s
                            UNION
                              SELECT ticket FROM ticket_change
                              WHERE field='comment' AND %s
                            UNION
                              SELECT ticket FROM ticket_custom WHERE %s
                          ))
                          """
                % (productsql, sql, sql2, sql3),
                args + args2 + args3,
            ):
                t = ticket_realm(id=tid)
                if "TICKET_VIEW" in req.perm(t):
                    yield (
                        req.href.ticket(tid),
                        tag_(
                            "%(title)s: %(message)s",
                            title=tag.span(get_resource_shortname(self.env, t), class_=status),
                            message=ticketsystem.format_summary(summary, status, resolution, type),
                        ),
                        from_utimestamp(ts),
                        author,
                        shorten_result(desc, terms),
                    )

        # Attachments
        for result in AttachmentModule(self.env).get_search_results(req, ticket_realm, terms):
            yield result
示例#25
0
    def test_product_neighborhood_wiki(self):
        target = resource.Neighborhood('product', u'xü').child(self.resource)

        self.assertEquals(u"TestPage",
                          resource.get_resource_description(self.env, target))
        self.assertEquals(u"TestPage",
                          resource.get_resource_name(self.env, target))
        self.assertEquals(u"TestPage",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"TestPage",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/products/x%C3%BC/wiki/TestPage?version=2',
            resource.get_resource_url(self.env, target, self.env.href))
示例#26
0
    def test_product_neighborhood_milestone(self):
        target = resource.Neighborhood('product', u'xü').child(self.resource)

        self.assertEquals(u"[product:xü] Milestone milestone1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] Milestone milestone1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals(u"milestone1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"[product:xü] Milestone milestone1",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals('http://example.org/trac.cgi/products/x%C3%BC/milestone/milestone1',
                          resource.get_resource_url(self.env,
                                                    target, self.env.href))
示例#27
0
    def test_global_neighborhood_milestone(self):
        target = resource.Neighborhood('global', None).child(self.resource)

        self.assertEquals("[global:] Milestone milestone1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] Milestone milestone1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals("milestone1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals("[global:] Milestone milestone1",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/milestone/milestone1',
            resource.get_resource_url(self.env, target, self.env.href))
示例#28
0
    def get_search_results(self, req, terms, filters):
        """Overriding search results for Tickets"""
        if not 'ticket' in filters:
            return
        ticket_realm = Resource('ticket')
        with self.env.db_query as db:
            sql, args = search_to_sql(db, [
                'summary', 'keywords', 'description', 'reporter', 'cc',
                db.cast('id', 'text')
            ], terms)
            sql2, args2 = search_to_sql(db, ['newvalue'], terms)
            sql3, args3 = search_to_sql(db, ['value'], terms)
            ticketsystem = TicketSystem(self.env)
            if req.args.get('product'):
                productsql = "product='%s' AND" % req.args.get('product')
            else:
                productsql = ""

            for summary, desc, author, type, tid, ts, status, resolution in \
                    db("""SELECT summary, description, reporter, type, id,
                                 time, status, resolution
                          FROM ticket
                          WHERE (%s id IN (
                              SELECT id FROM ticket WHERE %s
                            UNION
                              SELECT ticket FROM ticket_change
                              WHERE field='comment' AND %s
                            UNION
                              SELECT ticket FROM ticket_custom WHERE %s
                          ))
                          """ % (productsql, sql, sql2, sql3),
                          args + args2 + args3):
                t = ticket_realm(id=tid)
                if 'TICKET_VIEW' in req.perm(t):
                    yield (req.href.ticket(tid),
                           tag_("%(title)s: %(message)s",
                                title=tag.span(get_resource_shortname(
                                    self.env, t),
                                               class_=status),
                                message=ticketsystem.format_summary(
                                    summary, status, resolution,
                                    type)), from_utimestamp(ts), author,
                           shorten_result(desc, terms))

        # Attachments
        for result in AttachmentModule(self.env) \
                      .get_search_results(req, ticket_realm, terms):
            yield result
示例#29
0
    def test_global_neighborhood_attachments(self):
        target = resource.Neighborhood('global', None).child(self.resource)

        self.assertEquals(
            "[global:] Attachment 'foo.txt' in [global:] Ticket #1",
            resource.get_resource_description(self.env, target))
        self.assertEquals(
            "[global:] Attachment 'foo.txt' in [global:] Ticket #1",
            resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] foo.txt ([global:] Ticket #1)",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('Global Bar',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/attachment/ticket/1/foo.txt',
            resource.get_resource_url(self.env, target, self.env.href))
示例#30
0
    def test_product_neighborhood_attachments(self):
        target = resource.Neighborhood('product', u'xü').child(self.resource)

        self.assertEquals(
            u"[product:xü] Attachment 'foo.txt' in [product:xü] Ticket #1",
            resource.get_resource_description(self.env, target))
        self.assertEquals(
            u"[product:xü] Attachment 'foo.txt' in [product:xü] Ticket #1",
            resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] foo.txt ([product:xü] Ticket #1)",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('Product Bar',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/products/x%C3%BC/attachment/ticket/1/foo.txt',
            resource.get_resource_url(self.env, target, self.env.href))
    def filter_stream(self, req, method, filename, stream, data):
        crumbs = self._get_crumbs(req.session)
        if not crumbs:
            return stream

        add_stylesheet(req, 'breadcrumbs/css/breadcrumbs.css')
        ul = []

        path = req.path_info
        if path.count('/') >= 2:
            realm, resource_id = path.split('/', 2)[1:]
            if '&' in resource_id:
                resource_id = resource_id[0:resource_id.index('&')]
            current = '/'.join((realm, resource_id))
        else:
            current = None

        offset = 0
        if crumbs and crumbs[0] == current:
            offset = 1
        for crumb in crumbs[offset: self.max_crumbs + offset]:
            realm, resource_id = crumb.split('/', 1)
            resource = Resource(realm, resource_id)

            name = get_resource_shortname(self.env, resource)

            if not resource_exists(self.env, resource):
                continue

            title = get_resource_summary(self.env, resource)
            link = req.href(realm, resource_id)

            first = ul == []
            li = tag.li(tag.a(title=title, href=link)(name))
            if first:
                li(class_="first")
            ul.append(li)

        if ul:
            last = ul.pop()
            ul.append(last(class_="last"))
            label = self.label if self.label else "Breadcrumbs:"
            insert = tag.ul(class_="nav", id="breadcrumbs")(tag.li(label), ul)
        else:
            insert = ''

        return stream | Transformer('//div[@id="metanav"]/ul').after(insert)
示例#32
0
    def test_product_neighborhood_ticket(self):
        nbh = resource.Neighborhood('product', u'xü')
        data = dict(summary='Ticket summary', description='Ticket description',
                    type='task', status='accepted')
        target = nbh.child('ticket', self._new_ticket(self.env1, data))

        self.assertEquals(u"[product:xü] Ticket #1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] Ticket #1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] #1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"task: Ticket summary (accepted)",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals('http://example.org/trac.cgi/products/x%C3%BC/ticket/1',
                          resource.get_resource_url(self.env,
                                                    target, self.env.href))
示例#33
0
    def test_global_neighborhood_ticket(self):
        nbh = resource.Neighborhood('global', None)
        data = dict(summary='Ticket summary', description='Ticket description',
                    type='enhancement', status='new')
        target = nbh.child('ticket', self._new_ticket(self.global_env, data))

        self.assertEquals("[global:] Ticket #1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] Ticket #1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] #1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('enhancement: Ticket summary (new)',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals('http://example.org/trac.cgi/ticket/1',
                          resource.get_resource_url(self.env,
                                                    target, self.env.href))
示例#34
0
    def test_global_neighborhood_ticket(self):
        nbh = resource.Neighborhood('global', None)
        data = dict(summary='Ticket summary',
                    description='Ticket description',
                    type='enhancement',
                    status='new')
        target = nbh.child('ticket', self._new_ticket(self.global_env, data))

        self.assertEquals("[global:] Ticket #1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals("[global:] Ticket #1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals("[global:] #1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals('enhancement: Ticket summary (new)',
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/ticket/1',
            resource.get_resource_url(self.env, target, self.env.href))
示例#35
0
 def _do_switch(self, env, req, form):
     data = {}
     data['page_title'] = get_resource_description(env, form.resource,
                                                   href=req.href)
     data['title'] = get_resource_shortname(env, form.resource)
     data['siblings'] = []
     for sibling in form.siblings:
         form_id = tag.strong(tag.a(_("Form %(form_id)s",
                                      form_id=sibling[0]),
                                      href=req.href.form(sibling[0])))
         if sibling[1] == '':
             data['siblings'].append(form_id)
         else:
             # TRANSLATOR: Form list entry for form select page
             data['siblings'].append(tag_(
                           "%(form_id)s (subcontext = '%(subcontext)s')",
                           form_id=form_id, subcontext = sibling[1]))
     add_stylesheet(req, 'tracforms/tracforms.css')
     return 'switch.html', data, None
示例#36
0
    def test_product_neighborhood_ticket(self):
        nbh = resource.Neighborhood('product', u'xü')
        data = dict(summary='Ticket summary',
                    description='Ticket description',
                    type='task',
                    status='accepted')
        target = nbh.child('ticket', self._new_ticket(self.env1, data))

        self.assertEquals(u"[product:xü] Ticket #1",
                          resource.get_resource_description(self.env, target))
        self.assertEquals(u"[product:xü] Ticket #1",
                          resource.get_resource_name(self.env, target))
        self.assertEquals(u"[product:xü] #1",
                          resource.get_resource_shortname(self.env, target))
        self.assertEquals(u"task: Ticket summary (accepted)",
                          resource.get_resource_summary(self.env, target))
        self.assertEquals(
            'http://example.org/trac.cgi/products/x%C3%BC/ticket/1',
            resource.get_resource_url(self.env, target, self.env.href))
 def _index_ticket(self, ticket):
     ticketsystem = TicketSystem(self.env)
     resource_name = get_resource_shortname(self.env, ticket.resource)
     resource_desc = ticketsystem.get_resource_description(ticket.resource, format="summary")
     so = FullTextSearchObject(
         self.project,
         ticket.resource,
         title=u"%(title)s: %(message)s" % {"title": resource_name, "message": resource_desc},
         author=ticket.values.get("reporter"),
         changed=ticket.values.get("changetime"),
         created=ticket.values.get("time"),
         tags=ticket.values.get("keywords"),
         involved=re.split(r"[;,\s]+", ticket.values.get("cc", "")) or ticket.values.get("reporter"),
         popularity=0,  # FIXME
         oneline=shorten_result(ticket.values.get("description", "")),
         body=u"%r" % (ticket.values,),
         comments=[t[4] for t in ticket.get_changelog()],
     )
     self.backend.create(so, quiet=True)
     self.log.debug("Ticket added for indexing: %s", ticket)
示例#38
0
 def ticket_created(self, ticket):
     ticketsystem = TicketSystem(self.env)
     resource_name = get_resource_shortname(self.env, ticket.resource)
     resource_desc = ticketsystem.get_resource_description(ticket.resource,
                                                           format='summary')
     so = FullTextSearchObject(
             self.project, ticket.resource,
             title = u"%(title)s: %(message)s" % {'title': resource_name,
                                                  'message': resource_desc},
             author = ticket.values.get('reporter'),
             changed = ticket.values.get('changetime'),
             created = ticket.values.get('time'),
             tags = ticket.values.get('keywords'),
             involved = re.split(r'[;,\s]+', ticket.values.get('cc', ''))
                        or ticket.values.get('reporter'),
             popularity = 0, #FIXME
             oneline = shorten_result(ticket.values.get('description', '')),
             body = u'%r' % (ticket.values,),
             comments = [t[4] for t in ticket.get_changelog()],
             )
     self.backend.create(so, quiet=True)
     self._update_ticket(ticket)
     self.log.debug("Ticket added for indexing: %s", ticket)
示例#39
0
    def _format_name(self, req, url):
        linkname = url
        name = ""
        missing = False

        path_info = url
        query_string = ''
        idx = path_info.find('?')
        if idx >= 0:
            path_info, query_string = path_info[:idx], path_info[idx:]
        href = req.href(path_info) + query_string

        args = arg_list_to_args(parse_arg_list(query_string.lstrip('?')))
        version = args.get('version', False)

        path = path_info.strip('/').split('/')
        realm = path[0]
        class_ = realm
        if len(path) > 1:
            resource = Resource(realm, path[1])
            if resource:
                if realm == 'ticket':
                    linkname = get_resource_shortname(self.env, resource)
                    try:
                        name = get_resource_summary(self.env, resource)
                    except ResourceNotFound:
                        missing = True
                    else:
                        from trac.ticket.model import Ticket
                        class_ = Ticket(self.env, resource.id)['status'] + \
                            ' ' + class_
                elif realm == 'milestone':
                    linkname = get_resource_name(self.env, resource)
                elif realm == 'wiki':
                    resource = Resource(realm, '/'.join(path[1:]), version)
                    linkname = get_resource_shortname(self.env, resource)
                    if version:
                        linkname += '@' + version
                elif realm == 'report':
                    linkname = "{%s}" % path[1]
                    name = self._format_report_name(path[1])
                elif realm == 'changeset':
                    rev = path[1]
                    parent = Resource('source', '/'.join(path[2:]))
                    resource = Resource(realm, rev, False, parent)
                    linkname = "[%s]" % rev
                    name = get_resource_description(self.env, resource)
                elif realm == 'browser':
                    parent = Resource('source', path[1])
                    resource = Resource('source', '/'.join(path[2:]), False, parent)
                    linkname = get_resource_description(self.env, resource)
                    name = get_resource_summary(self.env, resource)
                elif realm == 'attachment':
                    # Assume a file and check existence
                    parent = Resource(path[1], '/'.join(path[2:-1]))
                    resource = Resource(realm, path[-1], parent=parent)
                    linkname = get_resource_name(self.env, resource)
                    if not resource_exists(self.env, resource):
                        # Assume an attachment list page and check existence
                        parent = Resource(path[1], '/'.join(path[2:]))
                        if resource_exists(self.env, parent):
                            resource = Resource(realm, parent=parent)
                            linkname = get_resource_name(self.env, resource)
                            if not query_string:
                                # Trailing slash needed for Trac < 1.0, t:#10280
                                href += '/'
                        else:
                            # Assume it's a missing attachment
                            missing = True
                else:
                    linkname = get_resource_shortname(self.env, resource)
                    name = get_resource_summary(self.env, resource)
        elif len(path) == 1 and path[0] and path[0] != 'wiki':
            linkname = path[0].capitalize()
        else:
            class_ = 'wiki'
            linkname = 'WikiStart'

        if missing:
            href = None
            class_ = 'missing ' + realm

        return {
            'class_': class_,
            'href': href,
            'linkname': linkname,
            'name': name,
            'delete': req.href.bookmark('delete_in_page', url),
        }
示例#40
0
    def _format_name(self, req, url):
        linkname = url
        name = ""
        missing = False

        path_info = url
        query_string = ''
        idx = path_info.find('?')
        if idx >= 0:
            path_info, query_string = path_info[:idx], path_info[idx:]
        href = req.href(path_info) + query_string

        args = arg_list_to_args(parse_arg_list(query_string.lstrip('?')))
        version = args.get('version', False)

        path = path_info.strip('/').split('/')
        realm = path[0]
        class_ = realm
        if len(path) > 1:
            resource = Resource(realm, path[1])
            if resource:
                if realm == 'ticket':
                    linkname = get_resource_shortname(self.env, resource)
                    try:
                        name = get_resource_summary(self.env, resource)
                    except ResourceNotFound:
                        missing = True
                    else:
                        from trac.ticket.model import Ticket
                        class_ = Ticket(self.env, resource.id)['status'] + \
                            ' ' + class_
                elif realm == 'milestone':
                    linkname = get_resource_name(self.env, resource)
                elif realm == 'wiki':
                    resource = Resource(realm, '/'.join(path[1:]), version)
                    linkname = get_resource_shortname(self.env, resource)
                    if version:
                        linkname += '@' + version
                elif realm == 'report':
                    linkname = "{%s}" % path[1]
                    name = self._format_report_name(path[1])
                elif realm == 'changeset':
                    rev = path[1]
                    parent = Resource('source', '/'.join(path[2:]))
                    resource = Resource(realm, rev, False, parent)
                    linkname = "[%s]" % rev
                    name = get_resource_description(self.env, resource)
                elif realm == 'browser':
                    rm = RepositoryManager(self.env)
                    reponame, repos, path = rm.get_repository_by_path('/'.join(
                        path[1:]))
                    parent = Resource('source', reponame)
                    resource = Resource('source', path, False, parent)
                    linkname = get_resource_description(self.env, resource)
                    name = get_resource_summary(self.env, resource)
                elif realm == 'attachment':
                    # Assume a file and check existence
                    parent = Resource(path[1], '/'.join(path[2:-1]))
                    resource = Resource(realm, path[-1], parent=parent)
                    linkname = get_resource_name(self.env, resource)
                    if not resource_exists(self.env, resource):
                        # Assume an attachment list page and check existence
                        parent = Resource(path[1], '/'.join(path[2:]))
                        if resource_exists(self.env, parent):
                            resource = Resource(realm, parent=parent)
                            linkname = get_resource_name(self.env, resource)
                            if not query_string:
                                # Trailing slash needed for Trac < 1.0, t:#10280
                                href += '/'
                        else:
                            # Assume it's a missing attachment
                            missing = True
                else:
                    linkname = get_resource_shortname(self.env, resource)
                    name = get_resource_summary(self.env, resource)
        elif len(path) == 1 and path[0] and path[0] != 'wiki':
            linkname = path[0].capitalize()
        else:
            class_ = 'wiki'
            linkname = 'WikiStart'

        if missing:
            href = None
            class_ = 'missing ' + realm

        return {
            'class_': class_,
            'href': href,
            'linkname': linkname,
            'name': name,
            'delete': req.href.bookmark('delete_in_page', url),
        }
        def expand_macro(self, formatter, name, args):
            # Create a HTML div tag to contain our return tables formatted in HTML
            returnDiv = tag.div()
	    # Create a connection to the database.
	    db = self.env.get_read_db()
	    cursor = db.cursor()
	    # Execute the SQL query on the #define ticket database. This query returns all tickets which have been updated with a '[number]:' tag since review.
	    cursor.execute("""SELECT t.id AS ticket, summary, milestone AS __group__, last_committed AS modified, t.owner as owner, t.component as component, t.status as status
                                FROM ticket t 
                                LEFT OUTER JOIN (
                                        SELECT ticket, MAX(time) AS last_reviewed
                                        FROM ticket_change
                                        WHERE field = 'comment' AND newvalue LIKE '%= Review%'
                                        GROUP BY ticket
                                ) rev ON rev.ticket = t.id
                                LEFT OUTER JOIN (
                                        SELECT ticket, MAX(time) AS last_committed
                                        FROM ticket_change
                                        WHERE field = 'comment' AND newvalue LIKE '[%]:%'
                                        GROUP BY ticket
                                ) ch ON ch.ticket = t.id
                                INNER JOIN milestone m ON m.name = milestone
                                WHERE last_committed > COALESCE(last_reviewed, 0)
                                ORDER BY milestone, component,  modified""")

	    currentMilestone = None
	    # i is used to track odd or even row numbers so the table row class can be set as either odd or even.
	    i = 0

	    # This loop iterates through the values returned by the SQL query.
	    for ticket, summary, __group__, modified, owner, component, status in cursor:
                    i+=1
		    if currentMilestone != __group__:
                            i = 0
                            if currentMilestone != None:
                                    # Print a blank line between tables but not before the first table
                                    returnDiv.append(tag.br())
			    # Start a new group.
			    currentMilestone = __group__
			    # Create a table header for the table to hold the values returned by the query.
			    currentTable = tag.table(self.table_header(),
						     class_="listing tickets")
			    # Create a heading for the group and append it to returnDiv then append currentTable.
			    returnDiv.append(tag.h2(currentMilestone or "No milestone set", class_="report-result"))
			    returnDiv.append(currentTable)
		    oddeven = (i%2 and 'odd' or 'even')
		    # oddeven is used to change the css class of the table rows to improve legibility.
		    ticket_resource = Resource('ticket',ticket)
		    # ticket_resource is used to specify the ticket resource from the trac environment. 
		    currentTable.append(tag.tr(tag.td(tag.a(get_resource_shortname(self.env, ticket_resource),
							    href=get_resource_url(self.env, ticket_resource, formatter.href))),
					       tag.td(summary),
					       tag.td(format_datetime(modified, tzinfo=formatter.req.tz)),
					       tag.td(owner),
					       tag.td(component),
					       tag.td(status), class_=oddeven))
		    # The above populates the rows with the results returned by our query.

            

	    return returnDiv
示例#42
0
 def get_resource_name(self, resource_id):
     resource = ResourceIdSerializer.get_resource_by_id(resource_id)
     return get_resource_shortname(self.env, resource)