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))
def _display_html(self, req): base_href = self.env.href.base crp = CodeReviewPool(self.env) db = self.env.get_db_cnx() is_completed = req.args.get('completed', '') keywords = {} action = req.args.get('action', '').strip() if req.args.get('comment', '').strip(): keywords['comment'] = req.args.get('comment', '').strip().lower() req_author = req.args.get('author', '').strip().lower() if req_author: if ',' in req_author: keywords['author'] = [ i.strip() for i in req_author.split(',') if i.strip() ] else: keywords['author'] = [ req_author, ] start_rev = int(self.env.config.get('codereview', 'start_rev', '0')) not_shown = self._get_not_shown() req.hdf['base_href'] = base_href req.hdf['search_href'] = self.env.href.CodeReview() if req.args.get('action', '') == 'search' and req.args.get('date', '').strip(): re_date = re.compile('^(\d{4})(\d{2})(\d{2})$') req_date = re_date.match(req.args.get('date', '').strip()) if req_date: try: req_date = [int(v) for v in req_date.groups()] keywords['start_date'] = time.mktime( datetime.date(*req_date).timetuple()) keywords['end_date'] = time.mktime( (datetime.date(*req_date) + datetime.timedelta(1)).timetuple()) except ValueError, error_info: return pretty_err(req, 'Search keyword error', error_info) else: return pretty_err(req, 'Search keyword error', 'search date format should be yyyymmdd.')
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
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
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))
def _display_html(self, req): base_href = self.env.href.base crp = CodeReviewPool(self.env) db = self.env.get_db_cnx() is_completed = req.args.get('completed', '') keywords = {} action = req.args.get('action', '').strip() if req.args.get('comment', '').strip(): keywords['comment'] = req.args.get('comment', '').strip().lower() req_author = req.args.get('author', '').strip().lower() if req_author: if ',' in req_author: keywords['author'] = [i.strip() for i in req_author.split(',') if i.strip()] else: keywords['author'] = [req_author,] start_rev = int(self.env.config.get('codereview', 'start_rev', '0')) not_shown = self._get_not_shown() req.hdf['base_href'] = base_href req.hdf['search_href'] = self.env.href.CodeReview() if req.args.get('action', '') == 'search' and req.args.get('date', '').strip(): re_date = re.compile('^(\d{4})(\d{2})(\d{2})$') req_date = re_date.match(req.args.get('date', '').strip()) if req_date: try: req_date = [int(v) for v in req_date.groups()] keywords['start_date'] = time.mktime(datetime.date(*req_date).timetuple()) keywords['end_date'] = time.mktime((datetime.date(*req_date) + datetime.timedelta(1)).timetuple()) except ValueError, error_info: return pretty_err(req, 'Search keyword error', error_info) else: return pretty_err(req, 'Search keyword error', 'search date format should be yyyymmdd.')
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))
def _diff_cr(self, req): add_stylesheet(req, 'common/css/diff.css') cs_id = req.args.get('id') old_version = req.args.get('old_version', 1) version = req.args.get('version', 1) db = self.env.get_db_cnx() cursor = db.cursor() try: version_author, version_status, newtext = self._get_version_record( cursor, cs_id, version) oldversion_author, oldversion_status, oldtext = self._get_version_record( cursor, cs_id, old_version) except ValueError: return pretty_err(req, 'Version Error') ctime = round(time.time(), 2) diff_style, diff_options = get_diff_options(req) context = 3 for option in diff_options: if option.startswith('-U'): context = int(option[2:]) break if context < 0: context = None changes = hdf_diff(oldtext.splitlines(), newtext.splitlines(), context=context, ignore_blank_lines='-B' in diff_options, ignore_case='-i' in diff_options, ignore_space_changes='-b' in diff_options) req.hdf['version.diff'] = changes req.hdf['version_author'] = version_author req.hdf['oldversion_author'] = oldversion_author req.hdf['version_status'] = status_str[version_status] req.hdf['oldversion_status'] = status_str[oldversion_status] req.hdf['ctime'] = time.ctime(ctime) req.hdf['old_version'] = old_version req.hdf['version'] = version req.hdf['rev'] = cs_id req.hdf['update.href'] = self.env.href.CodeReview(cs_id, action='diff') return 'codereviewdiff.cs', None
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
def _diff_cr(self, req): add_stylesheet(req, 'common/css/diff.css') cs_id = req.args.get('id') old_version = req.args.get('old_version', 1) version = req.args.get('version', 1) db = self.env.get_db_cnx() cursor = db.cursor() try: version_author, version_status, newtext = self._get_version_record(cursor, cs_id, version) oldversion_author, oldversion_status, oldtext = self._get_version_record(cursor, cs_id, old_version) except ValueError: return pretty_err(req, 'Version Error') ctime = round(time.time(), 2) diff_style, diff_options = get_diff_options(req) context = 3 for option in diff_options: if option.startswith('-U'): context = int(option[2:]) break if context < 0: context = None changes = hdf_diff(oldtext.splitlines(), newtext.splitlines(), context=context, ignore_blank_lines='-B' in diff_options, ignore_case='-i' in diff_options, ignore_space_changes='-b' in diff_options) req.hdf['version.diff'] = changes req.hdf['version_author'] = version_author req.hdf['oldversion_author'] = oldversion_author req.hdf['version_status'] = status_str[version_status] req.hdf['oldversion_status'] = status_str[oldversion_status] req.hdf['ctime'] = time.ctime(ctime) req.hdf['old_version'] = old_version req.hdf['version'] = version req.hdf['rev'] = cs_id req.hdf['update.href'] = self.env.href.CodeReview(cs_id, action='diff') return 'codereviewdiff.cs', None
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
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
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))