Пример #1
0
    def render(self):
        self.perm.assert_permission(perm.TICKET_CREATE)

        if self.args.has_key('create'):
            self.create_ticket()

        ticket = Ticket()
        ticket.populate(self.args)
        ticket.setdefault('component',
                          self.env.get_config('ticket', 'default_component'))
        ticket.setdefault('milestone',
                          self.env.get_config('ticket', 'default_milestone'))
        ticket.setdefault('priority',
                          self.env.get_config('ticket', 'default_priority'))
        ticket.setdefault('severity',
                          self.env.get_config('ticket', 'default_severity'))
        ticket.setdefault('version',
                          self.env.get_config('ticket', 'default_version'))
        ticket.setdefault('reporter', util.get_reporter_id(self.req))

        if ticket.has_key('description'):
            self.req.hdf.setValue(
                'newticket.description_preview',
                wiki_to_html(ticket['description'], self.req.hdf, self.env,
                             self.db))

        self.req.hdf.setValue('title', 'New Ticket')
        evals = util.mydict(
            zip(ticket.keys(), map(lambda x: util.escape(x), ticket.values())))
        util.add_to_hdf(evals, self.req.hdf, 'newticket')

        util.sql_to_hdf(self.db, 'SELECT name FROM component ORDER BY name',
                        self.req.hdf, 'newticket.components')
        util.sql_to_hdf(self.db, 'SELECT name FROM milestone ORDER BY name',
                        self.req.hdf, 'newticket.milestones')
        util.sql_to_hdf(self.db, 'SELECT name FROM version ORDER BY name',
                        self.req.hdf, 'newticket.versions')

        insert_custom_fields(self.env, self.req.hdf, ticket)
Пример #2
0
    def insert_ticket_data(self, hdf, id, ticket, reporter_id):
        """Insert ticket data into the hdf"""
        evals = util.mydict(
            zip(ticket.keys(), map(lambda x: util.escape(x), ticket.values())))
        util.add_to_hdf(evals, self.req.hdf, 'ticket')

        util.sql_to_hdf(self.db, 'SELECT name FROM component ORDER BY name',
                        self.req.hdf, 'ticket.components')
        util.sql_to_hdf(self.db, 'SELECT name FROM milestone ORDER BY name',
                        self.req.hdf, 'ticket.milestones')
        util.sql_to_hdf(self.db, 'SELECT name FROM version ORDER BY name',
                        self.req.hdf, 'ticket.versions')
        util.sql_to_hdf(
            self.db, "SELECT name FROM enum WHERE type='resolution'"
            " ORDER BY value", self.req.hdf, 'enums.resolution')
        util.hdf_add_if_missing(self.req.hdf, 'ticket.components',
                                ticket['component'])
        util.hdf_add_if_missing(self.req.hdf, 'ticket.milestones',
                                ticket['milestone'])
        util.hdf_add_if_missing(self.req.hdf, 'ticket.versions',
                                ticket['version'])
        util.hdf_add_if_missing(self.req.hdf, 'enums.priority',
                                ticket['priority'])
        util.hdf_add_if_missing(self.req.hdf, 'enums.severity',
                                ticket['severity'])
        util.hdf_add_if_missing(self.req.hdf, 'enums.resolution', 'fixed')

        self.req.hdf.setValue('ticket.reporter_id', util.escape(reporter_id))
        self.req.hdf.setValue('title', '#%d (%s)' % (id, ticket['summary']))
        self.req.hdf.setValue(
            'ticket.description.formatted',
            wiki_to_html(ticket['description'], self.req.hdf, self.env,
                         self.db))
        self.req.hdf.setValue(
            'ticket.opened',
            time.strftime('%c', time.localtime(int(ticket['time']))))

        changelog = ticket.get_changelog(self.db)
        curr_author = None
        curr_date = 0
        comment = None
        idx = 0
        for date, author, field, old, new in changelog:
            hdf.setValue('ticket.changes.%d.date' % idx,
                         time.strftime('%c', time.localtime(date)))
            hdf.setValue('ticket.changes.%d.time' % idx, str(date))
            hdf.setValue('ticket.changes.%d.author' % idx, util.escape(author))
            hdf.setValue('ticket.changes.%d.field' % idx, field)
            hdf.setValue('ticket.changes.%d.old' % idx, util.escape(old))
            if field == 'comment':
                hdf.setValue(
                    'ticket.changes.%d.new' % idx,
                    wiki_to_html(new, self.req.hdf, self.env, self.db))
            else:
                hdf.setValue('ticket.changes.%d.new' % idx, util.escape(new))
            idx = idx + 1

        insert_custom_fields(self.env, hdf, ticket)
        # List attached files
        self.env.get_attachments_hdf(self.db, 'ticket', str(id), self.req.hdf,
                                     'ticket.attachments')