Ejemplo n.º 1
0
 def notify(self, cr_dict):
     self.cr_dict = cr_dict
     cr_id = cr_dict['cr_id']
     cr = CodeReview(self.env, cr_id)
     reviewers = ", ".join(cr.get_reviewers())
     api_key = self.env.config.get("codereview", "sender_api_key")
     xmlrpcserver = self.env.config.get("codereview", "bamboo_xmlrpc_server")
     bamboo_enabled = self.env.config.get("codereview", "bamboo_enabled")
     absurl = self.env.config.get("codereview", "absurl")
     db = self.env.get_db_cnx()
     cursor = db.cursor()
     cursor.execute("SELECT author from revision where rev=%s" % (str(cr_id), ))
     cs_author = cursor.fetchone()
     if cs_author:
         cs_author = cs_author[0]
     else:
         return
     if absurl.endswith("/"):
         absurl = absurl[:-1]
     if api_key and xmlrpcserver and bamboo_enabled == "true":
         try:
             server = xmlrpclib.ServerProxy(xmlrpcserver)
             server.add_update(int(api_key), \
                 "Revision %s has been reviewed by %s. %s/CodeReview/%s" % \
                               (cr_id, reviewers, absurl, cr_id), 
                               [cs_author,])
         except Exception, error_info:
             self.env.log.error(error_info)
Ejemplo n.º 2
0
 def get_recipients(self, cr_id):
     cr = CodeReview(self.env, cr_id)
     reviewers = list(set(self.get_reviewer_team() + cr.get_reviewers()))
     cr_author = cr['author']
     if cr_author in reviewers:
         reviewers.remove(cr_author)
     return ([cr_author,], reviewers)
Ejemplo n.º 3
0
 def notify(self, cr_dict):
     self.cr_dict = cr_dict
     cr_id = cr_dict['cr_id']
     cr = CodeReview(self.env, cr_id)
     reviewers = ", ".join(cr.get_reviewers())
     api_key = self.env.config.get("codereview", "sender_api_key")
     xmlrpcserver = self.env.config.get("codereview", "bamboo_xmlrpc_server")
     bamboo_enabled = self.env.config.get("codereview", "bamboo_enabled")
     absurl = self.env.config.get("codereview", "absurl")
     db = self.env.get_db_cnx()
     cursor = db.cursor()
     cursor.execute("SELECT author from revision where rev=%s" % (str(cr_id), ))
     cs_author = cursor.fetchone()
     if cs_author:
         cs_author = cs_author[0]
     else:
         return
     if absurl.endswith("/"):
         absurl = absurl[:-1]
     if api_key and xmlrpcserver and bamboo_enabled == "true":
         try:
             server = xmlrpclib.ServerProxy(xmlrpcserver)
             server.add_update(int(api_key), \
                 "Revision %s has been reviewed by %s. %s/CodeReview/%s" % \
                               (cr_id, reviewers, absurl, cr_id), 
                               [cs_author,])
         except Exception, error_info:
             self.env.log.error(error_info)
Ejemplo n.º 4
0
    def _display_edit(self, req):
        req.perm.assert_permission('CODE_REVIEW_EDIT')
        cs_id = req.args.get('id')
        cr = CodeReview(self.env, int(cs_id))
        if not cr.is_existent_rev():
            return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                                'CodeReview for a Non-existent ChangeSet' % cs_id)
        item = cr.get_item()
        if cr.is_existent():
            item['reviewers'] = ', '.join(item['reviewers'])
            #ver, ctime, status, text, priority = record
            ver = item['version']
            status = item['status']
            priority = item['priority']
            ctime = time.ctime(item['time'])
            text = item['text'] or ''
        else:
            authors = ''
            ver = 0
            status = str_status["UndergoingReview"]
            text = ''
            ctime = ''
            priority = 'normal'
        sourcelists = [{'i':i, 'v': '[[CodeSegment(%s, 1, 2, %s)]]'%(v, cs_id)} \
                                    for i, v in enumerate(cr.get_all_pathes())]
        if len(sourcelists) > 0:
            req.hdf['source_count'] = len(sourcelists)
            req.hdf['sourcelists'] = sourcelists
        if req.args.get('action') == 'preview' and req.args.has_key('text'):
            req.hdf['preview'] = wiki_to_html(req.args.get('text'), self.env, req)
            req.hdf['text'] = req.args.get('text')
        else:
            req.hdf['text'] = text
        author = util.get_reporter_id(req)
        if req.args.has_key('req_version'):
            if ver != int(req.args.get('req_version')):
                if req.args.has_key('oldtext'):
                    req.hdf['oldtext'] = req.args.get('oldtext')
                else:
                    req.hdf['oldtext'] = req.args.get('text')
                req.hdf['version'] = req.args.get('req_version')
            else:
                req.hdf['version'] = ver
        else:
            req.hdf['version'] = ver
        self._render_attachment(req, cs_id, True)
        req.hdf['page_class'] = 'edit'
        req.hdf['time'] = ctime
        req.hdf['status'] = status
        req.hdf['reviewers'] = item['reviewers']
        req.hdf['author'] = author
        req.hdf['id'] = cs_id
        req.hdf['priority'] = priority
        req.hdf['cs_href'] = '%s/changeset/%s' % (self.env.href.base, cs_id)
        req.hdf['save_href'] = '%s/CodeReview/%s' % (self.env.href.base, cs_id)
        req.hdf['title'] = "Edit CodeReview r%s" % cs_id

        return 'codereviewpage.cs', None
Ejemplo n.º 5
0
    def notify(self, cr_dict):
        self.cr_dict = cr_dict
        cr = CodeReview(self.env, cr_dict['cr_id'])
        
        cursor = self.env.get_db_cnx().cursor()
        cursor.execute("SELECT author, message FROM revision WHERE rev='%s'" % cr_dict['cr_id'])

        recordset = cursor.fetchall()

        if not recordset:
            return
        cs_author = recordset[0][0]
        cs_message = recordset[0][1]

        if cs_author == "anonymous" and cr_dict['cr_author'] == "anonymous":
            return

        subject = "[TracNotify] ChangeSet r%s by %s reviewed by %s" % \
                  (cr_dict['cr_id'], cs_author, ','.join(cr.get_reviewers()))
        if cr_dict['priority'] == 'critical':
            subject = '[Critical]' + subject

        ticket_info = self.get_ticket_info(cs_message, cr_dict['cr_message'])

        self.hdf['trac_name'] = self.env.config.get('project', 'name')
        absurl = self.env.config.get('codereview', 'absurl')
        self.hdf['absurl'] = absurl
        self.hdf['r_content'] = wiki_to_html(cr_dict['cr_message'], self.env, cr_dict['req'], absurls = absurl)
        self.hdf['ticket_len'] = len(ticket_info)
        self.hdf['t_info'] = ticket_info
        self.hdf['cs_id'] = cr_dict['cr_id']
        self.hdf['cs_author'] = cs_author
        self.hdf['cs_message'] = wiki_to_html(cs_message, self.env, cr_dict['req'], absurls = absurl, escape_newlines=True)
        self.hdf['r_author'] = ', '.join(cr.get_reviewers())
        self.hdf['r_priority'] = cr_dict['priority']

        self.subject = subject

        self.smtp_server = self.config['notification'].get('smtp_server')
        self.smtp_port = self.config['notification'].getint('smtp_port')
        self.from_email = self.config['notification'].get('smtp_from')
        self.replyto_email = self.config['notification'].get('smtp_replyto')
        self.from_email = self.from_email or self.replyto_email
        if not self.from_email and not self.replyto_email:
            raise TracError(Markup('Unable to send email due to identity '
                                   'crisis.<p>Neither <b>notification.from</b> '
                                   'nor <b>notification.reply_to</b> are '
                                   'specified in the configuration.</p>'),
                            'SMTP Notification Error')

        # Authentication info (optional)
        self.user_name = self.config['notification'].get('smtp_user')
        self.password = self.config['notification'].get('smtp_password')

        Notify.notify(self, cr_dict['cr_id'])
Ejemplo n.º 6
0
    def notify(self, cr_dict):
        self.cr_dict = cr_dict
        cr = CodeReview(self.env, cr_dict['cr_id'])
        
        cursor = self.env.get_db_cnx().cursor()
        cursor.execute("SELECT author, message FROM revision WHERE rev='%s'" % cr_dict['cr_id'])

        recordset = cursor.fetchall()

        if not recordset:
            return
        cs_author = recordset[0][0]
        cs_message = recordset[0][1]

        if cs_author == "anonymous" and cr_dict['cr_author'] == "anonymous":
            return

        subject = "[TracNotify] ChangeSet r%s by %s reviewed by %s" % \
                  (cr_dict['cr_id'], cs_author, ','.join(cr.get_reviewers()))
        if cr_dict['priority'] == 'critical':
            subject = '[Critical]' + subject

        ticket_info = self.get_ticket_info(cs_message, cr_dict['cr_message'])

        self.hdf['trac_name'] = self.env.config.get('project', 'name')
        absurl = self.env.config.get('codereview', 'absurl')
        self.hdf['absurl'] = absurl
        self.hdf['r_content'] = wiki_to_html(cr_dict['cr_message'], self.env, cr_dict['req'], absurls = absurl)
        self.hdf['ticket_len'] = len(ticket_info)
        self.hdf['t_info'] = ticket_info
        self.hdf['cs_id'] = cr_dict['cr_id']
        self.hdf['cs_author'] = cs_author
        self.hdf['cs_message'] = wiki_to_html(cs_message, self.env, cr_dict['req'], absurls = absurl, escape_newlines=True)
        self.hdf['r_author'] = ', '.join(cr.get_reviewers())
        self.hdf['r_priority'] = cr_dict['priority']

        self.subject = subject

        self.smtp_server = self.config['notification'].get('smtp_server')
        self.smtp_port = self.config['notification'].getint('smtp_port')
        self.from_email = self.config['notification'].get('smtp_from')
        self.replyto_email = self.config['notification'].get('smtp_replyto')
        self.from_email = self.from_email or self.replyto_email
        if not self.from_email and not self.replyto_email:
            raise TracError(Markup('Unable to send email due to identity '
                                   'crisis.<p>Neither <b>notification.from</b> '
                                   'nor <b>notification.reply_to</b> are '
                                   'specified in the configuration.</p>'),
                            'SMTP Notification Error')

        # Authentication info (optional)
        self.user_name = self.config['notification'].get('smtp_user')
        self.password = self.config['notification'].get('smtp_password')

        Notify.notify(self, cr_dict['cr_id'])
Ejemplo n.º 7
0
    def _save_cr(self, req):
        req.perm.assert_permission('CODE_REVIEW_EDIT')

        cs_id = req.args.get('id')
        req_ver = req.args.get('req_version')

        cr = CodeReview(self.env, int(cs_id))

        if not cr.is_existent_rev():
            return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                                'CodeReview for a Non-existent ChangeSet' % cs_id)
        error_info = []

        try:
            req_ver = int(req_ver)
        except:
            error_info.append(
                'No req_version, cannot know your version for editing.')

        if req.args.get('author').strip() == '':
            error_info.append('Author cannot be empty.')
        if req.args.get('text').strip() == '':
            error_info.append('CodeReview Content cannot be empty.')
        if req.args.get('status') not in [str(k) for k in status_str.keys()]:
            error_info.append('Status value is vaild.')
        if error_info:
            return pretty_err(req, 'Cannot save codereview',
                              '<br>'.join(error_info))

        item = cr.get_item()
        if cr.is_existent():
            #item['text'] = item['text'] or ''
            if req_ver != item['version']:
                req.args['oldtext'] = req.args.get("text", " ")
                return self._display_edit(req)
            ver = int(item['version']) + 1
        else:
            if req_ver != 0:
                req.args['oldtext'] = req.args.get("text", " ")
                return self._display_edit(req)
            ver = 1

        if req.args.get('priority', '') in ('normal', 'critical'):
            item['priority'] = req.args.get('priority')

        item['text'] = req.args.get('text')
        item['time'] = round(time.mktime(time.localtime()), 2)
        item['author'] = req.args.get('author')
        item['status'] = int(req.args.get('status'))
        cr.set_item(item)
        cr.save()

        for change_listener in self.change_listeners:
            change_listener.review_changed(self.env, int(cs_id),
                                           req.args.get('text'), ver,
                                           req.args.get('author'),
                                           int(req.args.get('status')),
                                           item['priority'], req)
        req.redirect('%s/CodeReview/%s' % (self.env.href.base, cs_id))
Ejemplo n.º 8
0
 def _delete_cr(self, req):
     req.perm.assert_permission('CODE_REVIEW_EDIT')
     cs_id = int(req.args.get('id'))
     cr = CodeReview(self.env, int(cs_id))
     current_ver = cr.get_current_ver()
     if current_ver:
         cr.delete()
         req.args['delete_info'] = 'Codereview r%s version: %s has been deleted successfully.' % \
                                     (cs_id, current_ver)
         return self._display_html(req)
     else:
         return pretty_err(req, 'Cannot delete codereview r%s version: %s' % (cs_id, current_ver))
Ejemplo n.º 9
0
 def _delete_cr(self, req):
     req.perm.assert_permission('CODE_REVIEW_EDIT')
     cs_id = int(req.args.get('id'))
     cr = CodeReview(self.env, int(cs_id))
     current_ver = cr.get_current_ver()
     if current_ver:
         cr.delete()
         req.args['delete_info'] = 'Codereview r%s version: %s has been deleted successfully.' % \
                                     (cs_id, current_ver)
         return self._display_html(req)
     else:
         return pretty_err(
             req, 'Cannot delete codereview r%s version: %s' %
             (cs_id, current_ver))
Ejemplo n.º 10
0
    def get_recipients(self, cr_id):
        cr = CodeReview(self.env, cr_id)
        reviewers = list(set(self.get_reviewer_team() + cr.get_reviewers()))

	cs_author = self.hdf.get('cs_author', None)
	if cs_author is None:
            cursor = self.env.get_db_cnx().cursor()
            cursor.execute("SELECT author FROM revision WHERE rev='%s'" % cr_id)
            cs_author = cursor.fetchone()
            if cs_author:
                cs_author = cs_author[0]
            else:
	        cs_author = ''

        if cs_author in reviewers:
            reviewers.remove(cs_author)
        return ([cs_author,], reviewers)
Ejemplo n.º 11
0
    def get_recipients(self, cr_id):
        cr = CodeReview(self.env, cr_id)
        reviewers = list(set(self.get_reviewer_team() + cr.get_reviewers()))

        cs_author = self.hdf.get('cs_author', None)
        if cs_author is None:
            cursor = self.env.get_db_cnx().cursor()
            cursor.execute("SELECT author FROM revision WHERE rev='%s'" %
                           cr_id)
            cs_author = cursor.fetchone()
            if cs_author:
                cs_author = cs_author[0]
            else:
                cs_author = ''

        if cs_author in reviewers:
            reviewers.remove(cs_author)
        return ([
            cs_author,
        ], reviewers)
Ejemplo n.º 12
0
 def _history_cr(self, req):
     cs_id = req.args.get('id')
     cr = CodeReview(self.env, int(cs_id))
     if not cr.is_existent_rev():
         return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                             'CodeReview for a Non-existent ChangeSet' % cs_id)
     history_items = []
     for item in cr.get_all_items():
         item['time'] = time.ctime(item['time'])
         item['status'] = status_str[item['status']]
         item['cr_href'] = '%s/%s?version=%s' % (self.env.href.CodeReview(), cs_id, item['version'])
         history_items.append(item)
     if history_items:
         req.hdf['history.edit_href'] = '%s/%s?action=edit' % (self.env.href.CodeReview(), cs_id)
     else:
         req.hdf['history.edit_href'] = '%s/%s?action=new' % (self.env.href.CodeReview(), cs_id)
     req.hdf['history.count'] = len(history_items)
     req.hdf['history.items'] = history_items
     req.hdf['history.cr_id'] = cs_id
     req.hdf['history.href'] = '%s/%s' % (self.env.href.CodeReview(), cs_id)
     return 'codereviewhistory.cs', None
Ejemplo n.º 13
0
    def _display_edit(self, req):
        req.perm.assert_permission('CODE_REVIEW_EDIT')
        cs_id = req.args.get('id')
        cr = CodeReview(self.env, int(cs_id))
        if not cr.is_existent_rev():
            return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                                'CodeReview for a Non-existent ChangeSet' % cs_id)
        item = cr.get_item()
        if cr.is_existent():
            item['reviewers'] = ', '.join(item['reviewers'])
            #ver, ctime, status, text, priority = record
            ver = item['version']
            status = item['status']
            priority = item['priority']
            ctime = time.ctime(item['time'])
            text = item['text'] or ''
        else:
            authors = ''
            ver = 0
            status = str_status["UndergoingReview"]
            text = ''
            ctime = ''
            priority = 'normal'
        sourcelists = [{'i':i, 'v': '[[CodeSegment(%s, 1, 2, %s)]]'%(v, cs_id)} \
                                    for i, v in enumerate(cr.get_all_pathes())]
        if len(sourcelists) > 0:
            req.hdf['source_count'] = len(sourcelists)
            req.hdf['sourcelists'] = sourcelists
        if req.args.get('action') == 'preview' and req.args.has_key('text'):
            req.hdf['preview'] = wiki_to_html(req.args.get('text'), self.env,
                                              req)
            req.hdf['text'] = req.args.get('text')
        else:
            req.hdf['text'] = text
        author = util.get_reporter_id(req)
        if req.args.has_key('req_version'):
            if ver != int(req.args.get('req_version')):
                if req.args.has_key('oldtext'):
                    req.hdf['oldtext'] = req.args.get('oldtext')
                else:
                    req.hdf['oldtext'] = req.args.get('text')
                req.hdf['version'] = req.args.get('req_version')
            else:
                req.hdf['version'] = ver
        else:
            req.hdf['version'] = ver
        self._render_attachment(req, cs_id, True)
        req.hdf['page_class'] = 'edit'
        req.hdf['time'] = ctime
        req.hdf['status'] = status
        req.hdf['reviewers'] = item['reviewers']
        req.hdf['author'] = author
        req.hdf['id'] = cs_id
        req.hdf['priority'] = priority
        req.hdf['cs_href'] = '%s/changeset/%s' % (self.env.href.base, cs_id)
        req.hdf['save_href'] = '%s/CodeReview/%s' % (self.env.href.base, cs_id)
        req.hdf['title'] = "Edit CodeReview r%s" % cs_id

        return 'codereviewpage.cs', None
Ejemplo n.º 14
0
 def _render_critical(self, req):
     crp = CodeReviewPool(self.env)
     last_rev = crp.get_rev_count()
     revs = range(last_rev + 1)
     author = util.get_reporter_id(req)
     for k in req.args.keys():
         try:
             cr_id = int(k)
         except:
             continue
         if req.args.get(k).lower() == 'on' and cr_id in revs:
             CodeReview(self.env, cr_id, author).set_to_critical()
     req.redirect(
         self.env.href.CodeReview(**self._get_search_keywords(req)))
Ejemplo n.º 15
0
 def _history_cr(self, req):
     cs_id = req.args.get('id')
     cr = CodeReview(self.env, int(cs_id))
     if not cr.is_existent_rev():
         return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                             'CodeReview for a Non-existent ChangeSet' % cs_id)
     history_items = []
     for item in cr.get_all_items():
         item['time'] = time.ctime(item['time'])
         item['status'] = status_str[item['status']]
         item['cr_href'] = '%s/%s?version=%s' % (self.env.href.CodeReview(),
                                                 cs_id, item['version'])
         history_items.append(item)
     if history_items:
         req.hdf['history.edit_href'] = '%s/%s?action=edit' % (
             self.env.href.CodeReview(), cs_id)
     else:
         req.hdf['history.edit_href'] = '%s/%s?action=new' % (
             self.env.href.CodeReview(), cs_id)
     req.hdf['history.count'] = len(history_items)
     req.hdf['history.items'] = history_items
     req.hdf['history.cr_id'] = cs_id
     req.hdf['history.href'] = '%s/%s' % (self.env.href.CodeReview(), cs_id)
     return 'codereviewhistory.cs', None
Ejemplo n.º 16
0
 def _display_html(self, req):
     cs_id = int(req.args.get('id'))
     cr = CodeReview(self.env, int(cs_id))
     if req.args.get('version'):
         try:
             req_ver = int(req.args.get('version'))
         except:
             req_ver = 0
     else:
         req_ver = 0
     if req.args.has_key('delete_info'):
         req.hdf['delete_info'] = req.args.get('delete_info')
     if not cr.is_existent_rev():
         return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                             'CodeReview for a Non-existent ChangeSet' % cs_id)
     if req_ver:
         if cr.is_existent_ver(req_ver):
             ver = req_ver
         else:
             ver = 0
     else:
         ver = cr.get_current_ver()
     if not ver:
         req.hdf['page_class'] = "None"
         if req_ver:
             req.hdf['title'] = "CodeReview r%s version: %s is non-existent" \
                                % (cs_id, req_ver)
             req.hdf['message'] = "CodeReview r%s version: %s is non-existent" \
                                % (cs_id, req_ver)
             req.hdf['create_href'] = "%s/%s" % (self.env.href.CodeReview(), \
                                             cs_id)
         else:
             req.hdf['title'] = "CodeReview r%s is non-existent" % cs_id
             req.hdf['message'] = "CodeReview r%s is non-existent, Do you want to create it?" % cs_id
             req.hdf['create_href'] = "%s/%s" % (self.env.href.CodeReview(), \
                                             cs_id)
         return 'codereviewpage.cs', None
     else:
         req.hdf['page_class'] = "View"
         req.hdf['title'] = "CodeReview r%s" % cs_id
         item = cr.get_item()
         self._render_attachment(req, cs_id)
         if cr.get_current_ver() == ver:
             req.hdf['delete_href'] = "%s/%s" % (self.env.href.CodeReview(), cs_id)
         else:
             req.hdf['source_text'] = item['text'] or ''
         req.hdf['status'] = status_str[item['status']]
         req.hdf['authors'] = ', '.join(item['reviewers'])
         req.hdf['text'] = item['text'] and wiki_to_html(item['text'], self.env, req) or ''
         req.hdf['time'] = time.ctime(item['time'])
         req.hdf['cr_id'] = cs_id
         req.hdf['version'] = ver
         req.hdf['priority'] = item['priority']
         req.hdf['cs_href'] = "%s/changeset/%s" % (self.env.href.base, cs_id)
         req.hdf['edit_href'] = "%s/CodeReview/%s" % (self.env.href.base, cs_id)
         return 'codereviewpage.cs', None
Ejemplo n.º 17
0
 def _display_html(self, req):
     cs_id = int(req.args.get('id'))
     cr = CodeReview(self.env, int(cs_id))
     if req.args.get('version'):
         try:
             req_ver = int(req.args.get('version'))
         except:
             req_ver = 0
     else:
         req_ver = 0
     if req.args.has_key('delete_info'):
         req.hdf['delete_info'] = req.args.get('delete_info')
     if not cr.is_existent_rev():
         return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                             'CodeReview for a Non-existent ChangeSet' % cs_id)
     if req_ver:
         if cr.is_existent_ver(req_ver):
             ver = req_ver
         else:
             ver = 0
     else:
         ver = cr.get_current_ver()
     if not ver:
         req.hdf['page_class'] = "None"
         if req_ver:
             req.hdf['title'] = "CodeReview r%s version: %s is non-existent" \
                                % (cs_id, req_ver)
             req.hdf['message'] = "CodeReview r%s version: %s is non-existent" \
                                % (cs_id, req_ver)
             req.hdf['create_href'] = "%s/%s" % (self.env.href.CodeReview(), \
                                             cs_id)
         else:
             req.hdf['title'] = "CodeReview r%s is non-existent" % cs_id
             req.hdf[
                 'message'] = "CodeReview r%s is non-existent, Do you want to create it?" % cs_id
             req.hdf['create_href'] = "%s/%s" % (self.env.href.CodeReview(), \
                                             cs_id)
         return 'codereviewpage.cs', None
     else:
         req.hdf['page_class'] = "View"
         req.hdf['title'] = "CodeReview r%s" % cs_id
         item = cr.get_item()
         self._render_attachment(req, cs_id)
         if cr.get_current_ver() == ver:
             req.hdf['delete_href'] = "%s/%s" % (self.env.href.CodeReview(),
                                                 cs_id)
         else:
             req.hdf['source_text'] = item['text'] or ''
         req.hdf['status'] = status_str[item['status']]
         req.hdf['authors'] = ', '.join(item['reviewers'])
         req.hdf['text'] = item['text'] and wiki_to_html(
             item['text'], self.env, req) or ''
         req.hdf['time'] = time.ctime(item['time'])
         req.hdf['cr_id'] = cs_id
         req.hdf['version'] = ver
         req.hdf['priority'] = item['priority']
         req.hdf['cs_href'] = "%s/changeset/%s" % (self.env.href.base,
                                                   cs_id)
         req.hdf['edit_href'] = "%s/CodeReview/%s" % (self.env.href.base,
                                                      cs_id)
         return 'codereviewpage.cs', None
Ejemplo n.º 18
0
    def _save_cr(self, req):
        req.perm.assert_permission('CODE_REVIEW_EDIT')

        cs_id = req.args.get('id')
        req_ver = req.args.get('req_version')

        cr = CodeReview(self.env, int(cs_id))

        if not cr.is_existent_rev():
            return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \
                                'CodeReview for a Non-existent ChangeSet' % cs_id)
        error_info = []

        try:
            req_ver = int(req_ver)
        except:
            error_info.append('No req_version, cannot know your version for editing.')
        
        if req.args.get('author').strip() == '':
            error_info.append('Author cannot be empty.')
        if req.args.get('text').strip() == '':
            error_info.append('CodeReview Content cannot be empty.')
        if req.args.get('status') not in [str(k) for k in status_str.keys()]:
            error_info.append('Status value is vaild.')
        if error_info:
            return pretty_err(req, 'Cannot save codereview', '<br>'.join(error_info))
        
        item = cr.get_item()
        if cr.is_existent():
            #item['text'] = item['text'] or ''
            if req_ver != item['version']:
                req.args['oldtext'] = req.args.get("text", " ")
                return self._display_edit(req)
            ver = int(item['version']) + 1
        else:
            if req_ver != 0:
                req.args['oldtext'] = req.args.get("text", " ")
                return self._display_edit(req)
            ver = 1
        
        if req.args.get('priority', '') in ('normal', 'critical'):
            item['priority'] = req.args.get('priority')
        
        item['text'] = req.args.get('text')
        item['time'] = round(time.mktime(time.localtime()), 2)
        item['author'] = req.args.get('author')
        item['status'] = int(req.args.get('status'))
        cr.set_item(item)
        cr.save()

        for change_listener in self.change_listeners:
            change_listener.review_changed(self.env,
                                           int(cs_id),
                                           req.args.get('text'),
                                           ver,
                                           req.args.get('author'),
                                           int(req.args.get('status')),
                                           item['priority'],
                                           req
                                          )
        req.redirect('%s/CodeReview/%s' % (self.env.href.base, cs_id))