Exemple #1
0
    def render(self):
        self.perm.assert_permission(perm.TICKET_VIEW)

        action = self.args.get('action', 'view')
        preview = self.args.has_key('preview')

        if not self.args.has_key('id'):
            self.req.redirect(self.env.href.wiki())

        id = int(self.args.get('id'))

        if not preview \
               and action in ['leave', 'accept', 'reopen', 'resolve', 'reassign']:
            self.save_changes(id)

        ticket = Ticket(self.db, id)
        reporter_id = util.get_reporter_id(self.req)

        if preview:
            # Use user supplied values
            for field in Ticket.std_fields:
                if self.args.has_key(field) and field != 'reporter':
                    ticket[field] = self.args.get(field)
            self.req.hdf.setValue('ticket.action', action)
            reporter_id = self.args.get('author')
            comment = self.args.get('comment')
            if comment:
                self.req.hdf.setValue('ticket.comment', comment)
                # Wiki format a preview of comment
                self.req.hdf.setValue(
                    'ticket.comment_preview',
                    wiki_to_html(comment, self.req.hdf, self.env, self.db))

        self.insert_ticket_data(self.req.hdf, id, ticket, reporter_id)

        cursor = self.db.cursor()
        cursor.execute("SELECT max(id) FROM ticket")
        row = cursor.fetchone()
        if row:
            max_id = int(row[0])
            if id > 1:
                self.add_link('first', self.env.href.ticket(1), 'Ticket #1')
                self.add_link('prev', self.env.href.ticket(id - 1),
                              'Ticket #%d' % (id - 1))
            if id < max_id:
                self.add_link('next', self.env.href.ticket(id + 1),
                              'Ticket #%d' % (id + 1))
                self.add_link('last', self.env.href.ticket(max_id),
                              'Ticket #%d' % (max_id))
Exemple #2
0
 def display(self):
     text, link = self.get_attachment_parent_link()
     self.add_link('up', link, text)
     self.req.hdf.setValue('title', '%s%s: %s' % (
                           self.attachment_type == 'ticket' and '#' or '',
                           self.attachment_id, self.filename))
     self.req.hdf.setValue('file.attachment_parent', text)
     self.req.hdf.setValue('file.attachment_parent_href', link)
     if self.view_form:
         self.req.hdf.setValue('attachment.type', self.attachment_type)
         self.req.hdf.setValue('attachment.id', self.attachment_id)
         self.req.hdf.setValue('attachment.author', util.get_reporter_id(self.req))
         self.req.display('attachment.cs')
         return
     self.req.hdf.setValue('file.filename', urllib.unquote(self.filename))
     self.req.hdf.setValue('trac.active_module', self.attachment_type) # Kludge
     FileCommon.display(self)
Exemple #3
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)
Exemple #4
0
    def render(self):
        name = self.args.get('page', 'WikiStart')
        author = self.args.get('author', get_reporter_id(self.req))
        edit_version = self.args.get('edit_version', None)
        delete_ver = self.args.get('delete_ver', None)
        delete_page = self.args.get('delete_page', None)
        comment = self.args.get('comment', '')
        save = self.args.get('save', None)
        edit = self.args.get('edit', None)
        diff = self.args.get('diff', None)
        cancel = self.args.get('cancel', None)
        preview = self.args.get('preview', None)
        history = self.args.get('history', None)
        version = int(self.args.get('version', 0))
        readonly = self.args.get('readonly', None)

        # Ask web spiders to not index old version
        if diff or version:
            self.req.hdf.setValue('html.norobots', '1')

        if cancel:
            self.req.redirect(self.env.href.wiki(name))
            # Not reached

        if delete_ver and edit_version and name:
            # Delete only a specific page version
            self.perm.assert_permission(perm.WIKI_DELETE)
            cursor = self.db.cursor()
            cursor.execute('DELETE FROM wiki WHERE name=%s and version=%s',
                           name, int(edit_version))
            self.db.commit()
            self.log.info('Deleted version %d of page %s' %
                          (int(edit_version), name))
            if int(edit_version) > 1:
                self.req.redirect(self.env.href.wiki(name))
            else:
                # Delete orphaned attachments
                for attachment in self.env.get_attachments(
                        self.db, 'wiki', name):
                    self.env.delete_attachment(self.db, 'wiki', name,
                                               attachment[0])
                self.req.redirect(self.env.href.wiki())
            # Not reached

        if delete_page and name:
            # Delete a wiki page completely
            self.perm.assert_permission(perm.WIKI_DELETE)
            cursor = self.db.cursor()
            cursor.execute('DELETE FROM wiki WHERE name=%s', name)
            self.db.commit()
            self.log.info('Deleted version %d of page ' + name)
            # Delete orphaned attachments
            for attachment in self.env.get_attachments(self.db, 'wiki', name):
                self.env.delete_attachment(self.db, 'wiki', name,
                                           attachment[0])
            self.req.redirect(self.env.href.wiki())
            # Not reached

        self.req.hdf.setValue('wiki.name', escape(name))
        self.req.hdf.setValue('wiki.author', escape(author))
        self.req.hdf.setValue('wiki.comment', escape(comment))
        # Workaround so that we can attach files to wiki pages
        # even if the page name contains a '/'
        self.req.hdf.setValue('wiki.namedoublequoted',
                              urllib.quote(urllib.quote(name, '')))

        session = Session(self.env, self.req)
        editrows = self.args.get('editrows')
        if editrows:
            self.req.hdf.setValue('wiki.edit_rows', editrows)
            pref = session.get('wiki_editrows', '20')
            if editrows != pref:
                session.set_var('wiki_editrows', editrows)
        else:
            self.req.hdf.setValue('wiki.edit_rows',
                                  session.get('wiki_editrows', '20'))

        if save:
            self.req.hdf.setValue('wiki.action', 'save')
        elif edit:
            self.perm.assert_permission(perm.WIKI_MODIFY)
            self.req.hdf.setValue('wiki.action', 'edit')
            self.req.hdf.setValue('title', escape(name) + ' (edit)')
        elif preview:
            self.req.hdf.setValue('wiki.action', 'preview')
            self.req.hdf.setValue('wiki.scroll_bar_pos',
                                  self.args.get('scroll_bar_pos', ''))
            self.req.hdf.setValue('title', escape(name) + ' (preview)')
        elif diff and version > 0:
            self.req.hdf.setValue('wiki.action', 'diff')
            self.generate_diff(name, version)
            self.req.hdf.setValue('title', escape(name) + ' (diff)')
        elif history:
            self.req.hdf.setValue('wiki.action', 'history')
            self.generate_history(name)
            self.req.hdf.setValue('title', escape(name) + ' (history)')
        else:
            self.perm.assert_permission(perm.WIKI_VIEW)
            if version:
                self.add_link('alternate',
                              '?version=%d&amp;format=txt' % version,
                              'Plain Text', 'text/plain')
            else:
                self.add_link('alternate', '?format=txt', 'Plain Text',
                              'text/plain')
            if self.args.has_key('text'):
                del self.args['text']
            self.req.hdf.setValue('wiki.action', 'view')
            if name == 'WikiStart':
                self.req.hdf.setValue('title', '')
            else:
                self.req.hdf.setValue('title', escape(name))
            self.env.get_attachments_hdf(self.db, 'wiki', name, self.req.hdf,
                                         'wiki.attachments')

        self.page = WikiPage(name, version, self.perm, self.db)
        if self.args.has_key('text'):
            self.page.set_content(self.args.get('text'))
        else:
            self.page.modified = 0

        # Modify the read-only flag if it has been changed and the user is WIKI_ADMIN
        if save and self.perm.has_permission(perm.WIKI_ADMIN):
            if readonly:
                self.page.readonly = 1
            else:
                self.page.readonly = 0

        self.req.hdf.setValue('wiki.readonly', str(self.page.readonly))
        # We store the page version when we start editing a page.
        # This way we can stop users from saving changes if they are
        # not based on the latest version any more
        if edit_version:
            self.req.hdf.setValue('wiki.edit_version', edit_version)
        else:
            self.req.hdf.setValue('wiki.edit_version', str(self.page.version))

        if save and edit_version != str(self.page.version - 1):
            raise TracError('Sorry, Cannot create new version, this page has '
                            'already been modified by someone else.')

        if save:
            self.page.commit(author, comment, self.req.remote_addr)
            self.req.redirect(self.env.href.wiki(self.page.name))

        self.req.hdf.setValue('wiki.current_href',
                              escape(self.env.href.wiki(self.page.name)))
        self.req.hdf.setValue(
            'wiki.history_href',
            escape(self.env.href.wiki(self.page.name, history=1)))
        self.req.hdf.setValue('wiki.page_name', escape(self.page.name))
        self.req.hdf.setValue('wiki.page_source', escape(self.page.text))
        out = StringIO.StringIO()
        Formatter(self.req.hdf, self.env, self.db).format(self.page.text, out)
        self.req.hdf.setValue('wiki.page_html', out.getvalue())