def _link_tickets(self, req, tickets):
        items = []

        for i, word in enumerate(re.split(r'([;,\s]+)', tickets)):
            if i % 2:
                items.append(word)
            elif word:
                tid = word
                word = '#%s' % word

                try:
                    ticket = Ticket(self.env, tid)
                    if 'TICKET_VIEW' in req.perm(ticket.resource):
                        word = \
                            tag.a(
                                '#%s' % ticket.id,
                                href=req.href.ticket(ticket.id),
                                class_=classes(ticket['status'], 'ticket'),
                                title=get_resource_summary(self.env, ticket.resource)
                            )
                except ResourceNotFound:
                    pass

                items.append(word)

        if items:
            return tag(items)
        else:
            return None
Пример #2
0
    def _link_tickets(self, req, tickets):
        items = []

        for i, word in enumerate(re.split(r'([;,\s]+)', tickets)):
            if i % 2:
                items.append(word)
            elif word:
                tid = word
                word = '#%s' % word

                try:
                    ticket = Ticket(self.env, tid)
                    if 'TICKET_VIEW' in req.perm(ticket.resource):
                        word = \
                            html.a(
                                '#%s' % ticket.id,
                                href=req.href.ticket(ticket.id),
                                class_=classes(ticket['status'], 'ticket'),
                                title=get_resource_summary(self.env,
                                                           ticket.resource)
                            )
                except ResourceNotFound:
                    pass

                items.append(word)

        if items:
            return html(items)
        else:
            return None
Пример #3
0
def render_resource_link(env, context, resource, format='default'):
    """Utility for generating a link `Element` to the given resource.

    Some component manager may directly use an extra `context` parameter
    in order to directly generate rich content. Otherwise, the textual output
    is wrapped in a link to the resource.
    """
    link = get_resource_description(env, resource, format, context=context)
    if not isinstance(link, Fragment):
        missing = resource_exists(env, resource) is False
        link = tag.a(link, class_=classes(resource.realm, missing=missing),
                     href=get_resource_url(env, resource, context.href),
                     rel='nofollow' if missing else None)

    return link
Пример #4
0
def render_resource_link(env, context, resource, format='default'):
    """Utility for generating a link `Element` to the given resource.

    Some component manager may directly use an extra `context` parameter
    in order to directly generate rich content. Otherwise, the textual output
    is wrapped in a link to the resource.
    """
    from genshi.builder import Fragment, tag
    link = get_resource_description(env, resource, format, context=context)
    if not isinstance(link, Fragment):
        missing = resource_exists(env, resource) is False
        link = tag.a(link, class_=classes(resource.realm, missing=missing),
                     href=get_resource_url(env, resource, context.href),
                     rel='nofollow' if missing else None)

    return link
Пример #5
0
 def _render_link(self, context, name, label, extra=''):
     if not (name or extra):
         return tag()
     try:
         milestone = Milestone(self.env, name)
     except ResourceNotFound:
         milestone = None
     # Note: the above should really not be needed, `Milestone.exists`
     # should simply be false if the milestone doesn't exist in the db
     # (related to #4130)
     href = context.href.milestone(name)
     exists = milestone and milestone.exists
     if exists:
         if 'MILESTONE_VIEW' in context.perm(milestone.resource):
             title = None
             if hasattr(context, 'req'):
                 if milestone.is_completed:
                     title = _("Completed %(duration)s ago (%(date)s)",
                               duration=pretty_timedelta(
                                   milestone.completed),
                               date=user_time(context.req, format_datetime,
                                              milestone.completed))
                 elif milestone.is_late:
                     title = _("%(duration)s late (%(date)s)",
                               duration=pretty_timedelta(milestone.due),
                               date=user_time(context.req, format_datetime,
                                              milestone.due))
                 elif milestone.due:
                     title = _("Due in %(duration)s (%(date)s)",
                               duration=pretty_timedelta(milestone.due),
                               date=user_time(context.req, format_datetime,
                                              milestone.due))
                 else:
                     title = _("No date set")
             closed = 'closed ' if milestone.is_completed else ''
             return tag.a(label,
                          class_='%smilestone' % closed,
                          href=href + extra,
                          title=title)
     elif 'MILESTONE_CREATE' in context.perm(self.realm, name):
         return tag.a(label,
                      class_='missing milestone',
                      href=href + extra,
                      rel='nofollow')
     return tag.a(label, class_=classes('milestone', missing=not exists))