# HG changeset patch # User Marcin Kuzminski # Date 1335903881 -7200 # Node ID 76947224bf27dac22c5264cc82d2466954ed8d88 # Parent a2987fa580d98daecc73d2a6b3913214df719e59 Implemented initial code-review status of changesets diff -r a2987fa580d9 -r 76947224bf27 rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/controllers/changeset.py Tue May 01 22:24:41 2012 +0200 @@ -43,7 +43,7 @@ from rhodecode.lib.utils import EmptyChangeset from rhodecode.lib.compat import OrderedDict from rhodecode.lib import diffs -from rhodecode.model.db import ChangesetComment +from rhodecode.model.db import ChangesetComment, ChangesetStatus from rhodecode.model.comment import ChangesetCommentsModel from rhodecode.model.changeset_status import ChangesetStatusModel from rhodecode.model.meta import Session @@ -202,7 +202,7 @@ cumulative_diff = 0 c.cut_off = False # defines if cut off limit is reached - + c.changeset_statuses = ChangesetStatus.STATUSES c.comments = [] c.statuses = [] c.inline_comments = [] @@ -210,9 +210,9 @@ # Iterate over ranges (default changeset view is always one changeset) for changeset in c.cs_ranges: - c.statuses.extend(ChangesetStatusModel()\ + c.statuses.extend([ChangesetStatusModel()\ .get_status(c.rhodecode_db_repo.repo_id, - changeset.raw_id)) + changeset.raw_id)]) c.comments.extend(ChangesetCommentsModel()\ .get_comments(c.rhodecode_db_repo.repo_id, @@ -376,6 +376,17 @@ f_path=request.POST.get('f_path'), line_no=request.POST.get('line') ) + + # get status if set ! + status = request.POST.get('changeset_status') + if status and request.POST.get('change_changeset_status'): + ChangesetStatusModel().set_status( + c.rhodecode_db_repo.repo_id, + revision, + status, + c.rhodecode_user.user_id, + ) + Session.commit() if not request.environ.get('HTTP_X_PARTIAL_XHR'): return redirect(h.url('changeset_home', repo_name=repo_name, diff -r a2987fa580d9 -r 76947224bf27 rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/lib/helpers.py Tue May 01 22:24:41 2012 +0200 @@ -42,6 +42,7 @@ from rhodecode.lib.utils2 import str2bool, safe_unicode, safe_str, \ get_changeset_safe from rhodecode.lib.markup_renderer import MarkupRenderer +from rhodecode.model.changeset_status import ChangesetStatusModel log = logging.getLogger(__name__) @@ -875,7 +876,6 @@ return ''.join(links) - # urlify changesets - extrac revisions and make link out of them text_ = urlify_changesets(escaper(text_), repository) @@ -939,3 +939,7 @@ """ return literal('
%s
' % MarkupRenderer.rst_with_mentions(source)) + + +def changeset_status(repo, revision): + return ChangesetStatusModel().get_status(repo, revision) diff -r a2987fa580d9 -r 76947224bf27 rhodecode/model/changeset_status.py --- a/rhodecode/model/changeset_status.py Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/model/changeset_status.py Tue May 01 22:24:41 2012 +0200 @@ -29,9 +29,8 @@ from pylons.i18n.translation import _ from rhodecode.lib.utils2 import safe_unicode -from rhodecode.lib import helpers as h from rhodecode.model import BaseModel -from rhodecode.model.db import ChangesetStatus +from rhodecode.model.db import ChangesetStatus, Repository, User log = logging.getLogger(__name__) @@ -41,5 +40,55 @@ def __get_changeset_status(self, changeset_status): return self._get_instance(ChangesetStatus, changeset_status) + def __get_repo(self, repository): + return self._get_instance(Repository, repository, + callback=Repository.get_by_repo_name) + + def __get_user(self, user): + return self._get_instance(User, user, callback=User.get_by_username) + def get_status(self, repo, revision): - return 'status' + """ + Returns status of changeset for given revision + + :param repo: + :type repo: + :param revision: 40char hash + :type revision: str + """ + repo = self.__get_repo(repo) + + status = ChangesetStatus.query()\ + .filter(ChangesetStatus.repo == repo)\ + .filter(ChangesetStatus.revision == revision).scalar() + status = status.status if status else status + st = status or ChangesetStatus.DEFAULT + return str(st) + + def set_status(self, repo, revision, status, user): + """ + Creates new status for changeset or updates the old one + + :param repo: + :type repo: + :param revision: + :type revision: + :param status: + :type status: + :param user: + :type user: + """ + repo = self.__get_repo(repo) + + cur_status = ChangesetStatus.query()\ + .filter(ChangesetStatus.repo == repo)\ + .filter(ChangesetStatus.revision == revision)\ + .scalar() + new_status = cur_status or ChangesetStatus() + new_status.author = self.__get_user(user) + new_status.repo = self.__get_repo(repo) + new_status.status = status + new_status.revision = revision + self.sa.add(new_status) + return new_status + diff -r a2987fa580d9 -r 76947224bf27 rhodecode/model/db.py --- a/rhodecode/model/db.py Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/model/db.py Tue May 01 22:24:41 2012 +0200 @@ -680,6 +680,7 @@ def statuses(self, revisions=None): """ Returns statuses for this repository + :param revisions: list of revisions to get statuses for :type revisions: list """ @@ -688,12 +689,11 @@ .filter(ChangesetStatus.repo == self) if revisions: statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) - grouped = defaultdict(list) + grouped = {} for stat in statuses.all(): - grouped[statuses.revision].append(stat) + grouped[stat.revision] = [str(stat.status), stat.status_lbl] return grouped - #========================================================================== # SCM CACHE INSTANCE #========================================================================== @@ -1229,6 +1229,7 @@ class ChangesetStatus(Base, BaseModel): __tablename__ = 'changeset_statuses' __table_args__ = ( + UniqueConstraint('repo_id', 'revision'), {'extend_existing': True, 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} ) @@ -1239,17 +1240,22 @@ ('rejected', _("Rejected")), ('under_review', _("Under Review")), ] + DEFAULT = STATUSES[0][0] changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True) repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) revision = Column('revision', String(40), nullable=False) - status = Column('status', String(128), nullable=False, default=STATUSES[0][0]) + status = Column('status', String(128), nullable=False, default=DEFAULT) modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now) author = relationship('User', lazy='joined') repo = relationship('Repository') + @property + def status_lbl(self): + return dict(self.STATUSES).get(self.status) + class ChangesetStatusHistory(Base, BaseModel): __tablename__ = 'changeset_statuses_history' diff -r a2987fa580d9 -r 76947224bf27 rhodecode/model/notification.py --- a/rhodecode/model/notification.py Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/model/notification.py Tue May 01 22:24:41 2012 +0200 @@ -142,7 +142,7 @@ def mark_all_read_for_user(self, user): user = self.__get_user(user) UserNotification.query()\ - .filter(UserNotification.read==False)\ + .filter(UserNotification.read == False)\ .update({'read': True}) def get_unread_cnt_for_user(self, user): diff -r a2987fa580d9 -r 76947224bf27 rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/public/css/style.css Tue May 01 22:24:41 2012 +0200 @@ -2447,6 +2447,17 @@ font-weight: bold !important; } +.right .changeset-status-container{ + padding-right: 5px; + margin-top:1px; + float:right; + height:14px; +} +.right .changeset-status-container .changeset-status-lbl{ + color: rgb(136, 136, 136); + float: left; + padding: 0px 4px 0px 0px; +} .right .comments-container{ padding-right: 5px; margin-top:1px; @@ -3908,6 +3919,11 @@ /** comment form **/ +.status-block{ + height:80px; + clear:both +} + .comment-form .clearfix{ background: #EEE; -webkit-border-radius: 4px; diff -r a2987fa580d9 -r 76947224bf27 rhodecode/templates/changelog/changelog.html --- a/rhodecode/templates/changelog/changelog.html Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/templates/changelog/changelog.html Tue May 01 22:24:41 2012 +0200 @@ -65,7 +65,6 @@
${len(cs.affected_files)}
-
${c.statuses.get(cs.raw_id)}
%if len(c.comments.get(cs.raw_id,[])) > 0:
@@ -76,6 +75,12 @@
%endif
+
+ %if c.statuses.get(cs.raw_id): + +
${c.statuses.get(cs.raw_id)[1]}
+ %endif +
%if cs.parents: %for p_cs in reversed(cs.parents): diff -r a2987fa580d9 -r 76947224bf27 rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/templates/changeset/changeset.html Tue May 01 22:24:41 2012 +0200 @@ -40,7 +40,7 @@ ${c.context_url(request.GET)}
${len(c.comments)} comment(s) (${c.inline_cnt} ${_('inline')})
- +
@@ -153,6 +153,15 @@ // inject comments into they proper positions var file_comments = YUQ('.inline-comment-placeholder'); renderInlineComments(file_comments); + + YUE.on(YUD.get('show_changeset_status_box'),'change',function(e){ + if(e.currentTarget.checked){ + YUD.setStyle('status_block_container','display',''); + } + else{ + YUD.setStyle('status_block_container','display','none'); + } + }) }) diff -r a2987fa580d9 -r 76947224bf27 rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html Mon Apr 30 16:07:08 2012 +0200 +++ b/rhodecode/templates/changeset/changeset_file_comment.html Tue May 01 22:24:41 2012 +0200 @@ -38,7 +38,7 @@
${_('Commenting on line')} {1}. ${_('Comments parsed using')} RST ${_('syntax')} ${_('with')} @mention ${_('support')} -
+
@@ -79,6 +79,7 @@ +## MAIN COMMENT FORM <%def name="comments(changeset)">
@@ -99,8 +100,18 @@
${_('Comments parsed using')} RST ${_('syntax')} ${_('with')} @mention ${_('support')} + | ${_('change status')} + +
- ${h.textarea('text')} + + ${h.textarea('text')}
${h.submit('save', _('Comment'), class_='ui-button')}