Beispiel #1
0
 def _render_attachment(self, req, cr_id, perm = False):
     for idx, attachment in enumerate(Attachment.select(self.env, 'CodeReview',
                                                        cr_id)):
         hdf = attachment_to_hdf(self.env, db=self.env.get_db_cnx(), req=req, attachment=attachment)
         req.hdf['codereview.attachments.%s' % idx] = hdf
     if req.perm.has_permission('CODE_REVIEW_EDIT') and perm:
         req.hdf['codereview.attach_href'] = self.env.href.attachment('CodeReview',
                                                                  cr_id)
Beispiel #2
0
 def _render_attachment(self, req, cr_id, perm=False):
     for idx, attachment in enumerate(
             Attachment.select(self.env, 'CodeReview', cr_id)):
         hdf = attachment_to_hdf(self.env,
                                 db=self.env.get_db_cnx(),
                                 req=req,
                                 attachment=attachment)
         req.hdf['codereview.attachments.%s' % idx] = hdf
     if req.perm.has_permission('CODE_REVIEW_EDIT') and perm:
         req.hdf['codereview.attach_href'] = self.env.href.attachment(
             'CodeReview', cr_id)
Beispiel #3
0
    def _render_view(self, req, db, page):
        req.perm.assert_permission('WIKI_VIEW')

        if page.name == 'WikiStart':
            req.hdf['title'] = ''
        else:
            req.hdf['title'] = escape(page.name)

        version = req.args.get('version')
        if version:
            # Ask web spiders to not index old versions
            req.hdf['html.norobots'] = 1

        txt_href = self.env.href.wiki(page.name, version=version, format='txt')
        add_link(req, 'alternate', txt_href, 'Plain Text', 'text/plain')

        req.hdf['wiki'] = {
            'page_name': page.name,
            'exists': page.exists,
            'version': page.version,
            'readonly': page.readonly
        }
        if page.exists:
            req.hdf['wiki.page_html'] = wiki_to_html(page.text, self.env, req)
            history_href = self.env.href.wiki(page.name, action='history')
            req.hdf['wiki.history_href'] = escape(history_href)
        else:
            if not req.perm.has_permission('WIKI_CREATE'):
                raise TracError('Page %s not found' % page.name)
            req.hdf['wiki.page_html'] = '<p>Describe "%s" here</p>' % page.name

        # Show attachments
        attachments = []
        for attachment in Attachment.select(self.env, 'wiki', page.name, db):
            attachments.append(attachment_to_hdf(self.env, db, req,
                                                 attachment))
        req.hdf['wiki.attachments'] = attachments
        if req.perm.has_permission('WIKI_MODIFY'):
            attach_href = self.env.href.attachment('wiki', page.name)
            req.hdf['wiki.attach_href'] = attach_href
Beispiel #4
0
    def _render_view(self, req, db, page):
        req.perm.assert_permission("WIKI_VIEW")

        if page.name == "WikiStart":
            req.hdf["title"] = ""
        else:
            req.hdf["title"] = page.name

        version = req.args.get("version")
        if version:
            # Ask web spiders to not index old versions
            req.hdf["html.norobots"] = 1

        txt_href = self.env.href.wiki(page.name, version=version, format="txt")
        add_link(req, "alternate", txt_href, "Plain Text", "text/plain")

        req.hdf["wiki"] = {
            "page_name": page.name,
            "exists": page.exists,
            "version": page.version,
            "readonly": page.readonly,
        }
        if page.exists:
            req.hdf["wiki.page_html"] = wiki_to_html(page.text, self.env, req)
            history_href = self.env.href.wiki(page.name, action="history")
            req.hdf["wiki.history_href"] = history_href
        else:
            if not req.perm.has_permission("WIKI_CREATE"):
                raise TracError("Page %s not found" % page.name)
            req.hdf["wiki.page_html"] = Markup('<p>Describe "%s" here</p>', page.name)

        # Show attachments
        attachments = []
        for attachment in Attachment.select(self.env, "wiki", page.name, db):
            attachments.append(attachment_to_hdf(self.env, db, req, attachment))
        req.hdf["wiki.attachments"] = attachments
        if req.perm.has_permission("WIKI_MODIFY"):
            attach_href = self.env.href.attachment("wiki", page.name)
            req.hdf["wiki.attach_href"] = attach_href
Beispiel #5
0
    def _insert_ticket_data(self, req, db, ticket, reporter_id):
        """Insert ticket data into the hdf"""
        req.hdf['ticket'] = ticket.values
        req.hdf['ticket.id'] = ticket.id
        req.hdf['ticket.href'] = self.env.href.ticket(ticket.id)

        for field in TicketSystem(self.env).get_ticket_fields():
            if field['type'] in ('radio', 'select'):
                value = ticket.values.get(field['name'])
                options = field['options']
                if value and not value in options:
                    # Current ticket value must be visible even if its not in the
                    # possible values
                    options.append(value)
                field['options'] = options
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution', 'owner'):
                field['skip'] = True
            req.hdf['ticket.fields.' + name] = field

        req.hdf['ticket.reporter_id'] = reporter_id
        req.hdf['title'] = '#%d (%s)' % (ticket.id, ticket['summary'])
        req.hdf['ticket.description.formatted'] = wiki_to_html(ticket['description'],
                                                               self.env, req, db)

        req.hdf['ticket.opened'] = util.format_datetime(ticket.time_created)
        req.hdf['ticket.opened_delta'] = util.pretty_timedelta(ticket.time_created)
        if ticket.time_changed != ticket.time_created:
            req.hdf['ticket.lastmod'] = util.format_datetime(ticket.time_changed)
            req.hdf['ticket.lastmod_delta'] = util.pretty_timedelta(ticket.time_changed)

        changelog = ticket.get_changelog(db=db)
        curr_author = None
        curr_date   = 0
        changes = []
        for date, author, field, old, new in changelog:
            if date != curr_date or author != curr_author:
                changes.append({
                    'date': util.format_datetime(date),
                    'author': author,
                    'fields': {}
                })
                curr_date = date
                curr_author = author
            if field == 'comment':
                changes[-1]['comment'] = wiki_to_html(new, self.env, req, db)
            elif field == 'description':
                changes[-1]['fields'][field] = ''
            else:
                changes[-1]['fields'][field] = {'old': old,
                                                'new': new}
        req.hdf['ticket.changes'] = changes

        # List attached files
        for idx, attachment in util.enum(Attachment.select(self.env, 'ticket',
                                                           ticket.id)):
            hdf = attachment_to_hdf(self.env, db, req, attachment)
            req.hdf['ticket.attachments.%s' % idx] = hdf
        if req.perm.has_permission('TICKET_APPEND'):
            req.hdf['ticket.attach_href'] = self.env.href.attachment('ticket',
                                                                     ticket.id)

        # Add the possible actions to hdf
        actions = TicketSystem(self.env).get_available_actions(ticket, req.perm)
        for action in actions:
            req.hdf['ticket.actions.' + action] = '1'
Beispiel #6
0
    def _insert_ticket_data(self, req, db, ticket, reporter_id):
        """Insert ticket data into the hdf"""
        req.hdf['ticket'] = dict(zip(ticket.values.keys(),
                                 map(lambda x: util.escape(x),
                                     ticket.values.values())))
        req.hdf['ticket.id'] = ticket.id
        req.hdf['ticket.href'] = self.env.href.ticket(ticket.id)

        for field in TicketSystem(self.env).get_ticket_fields():
            if field['type'] in ('radio', 'select'):
                value = ticket.values.get(field['name'])
                options = field['options']
                if value and not value in options:
                    # Current ticket value must be visible even if its not in the
                    # possible values
                    options.append(value)
                field['options'] = [util.escape(option) for option in options]
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution', 'owner'):
                field['skip'] = True
            req.hdf['ticket.fields.' + name] = field

        req.hdf['ticket.reporter_id'] = util.escape(reporter_id)
        req.hdf['title'] = '#%d (%s)' % (ticket.id,
                                         util.escape(ticket['summary']))
        req.hdf['ticket.description.formatted'] = wiki_to_html(ticket['description'],
                                                               self.env, req, db)

        req.hdf['ticket.opened'] = util.format_datetime(ticket.time_created)
        req.hdf['ticket.opened_delta'] = util.pretty_timedelta(ticket.time_created)
        if ticket.time_changed != ticket.time_created:
            req.hdf['ticket.lastmod'] = util.format_datetime(ticket.time_changed)
            req.hdf['ticket.lastmod_delta'] = util.pretty_timedelta(ticket.time_changed)

        changelog = ticket.get_changelog(db=db)
        curr_author = None
        curr_date   = 0
        changes = []
        for date, author, field, old, new in changelog:
            if date != curr_date or author != curr_author:
                changes.append({
                    'date': util.format_datetime(date),
                    'author': util.escape(author),
                    'fields': {}
                })
                curr_date = date
                curr_author = author
            if field == 'comment':
                changes[-1]['comment'] = wiki_to_html(new, self.env, req, db)
            elif field == 'description':
                changes[-1]['fields'][field] = ''
            else:
                changes[-1]['fields'][field] = {'old': util.escape(old),
                                                'new': util.escape(new)}
        req.hdf['ticket.changes'] = changes

        # List attached files
        for idx, attachment in util.enum(Attachment.select(self.env, 'ticket',
                                                           ticket.id)):
            hdf = attachment_to_hdf(self.env, db, req, attachment)
            req.hdf['ticket.attachments.%s' % idx] = hdf
        if req.perm.has_permission('TICKET_APPEND'):
            req.hdf['ticket.attach_href'] = self.env.href.attachment('ticket',
                                                                     ticket.id)

        # Add the possible actions to hdf
        actions = TicketSystem(self.env).get_available_actions(ticket, req.perm)
        for action in actions:
            req.hdf['ticket.actions.' + action] = '1'