Changeset - 76947224bf27
[Not reviewed]
codereview
0 9 0
Marcin Kuzminski - 14 years ago 2012-05-01 22:24:41
marcin@python-works.com
Implemented initial code-review status of changesets
8 files changed with 124 insertions and 13 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/changeset.py
Show inline comments
 
@@ -43,7 +43,7 @@ from rhodecode.lib.base import BaseRepoC
 
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 @@ class ChangesetController(BaseRepoContro
 

	
 
        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 @@ class ChangesetController(BaseRepoContro
 
        # 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 @@ class ChangesetController(BaseRepoContro
 
            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,
rhodecode/lib/helpers.py
Show inline comments
 
@@ -42,6 +42,7 @@ from rhodecode.lib.utils import repo_nam
 
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 @@ def urlify_commit(text_, repository=None
 

	
 
        return ''.join(links)
 

	
 

	
 
    # urlify changesets - extrac revisions and make link out of them
 
    text_ = urlify_changesets(escaper(text_), repository)
 

	
 
@@ -939,3 +939,7 @@ def rst_w_mentions(source):
 
    """
 
    return literal('<div class="rst-block">%s</div>' %
 
                   MarkupRenderer.rst_with_mentions(source))
 

	
 

	
 
def changeset_status(repo, revision):
 
    return ChangesetStatusModel().get_status(repo, revision)
rhodecode/model/changeset_status.py
Show inline comments
 
@@ -29,9 +29,8 @@ import traceback
 
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 @@ class ChangesetStatusModel(BaseModel):
 
    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
 

	
rhodecode/model/db.py
Show inline comments
 
@@ -680,6 +680,7 @@ class Repository(Base, BaseModel):
 
    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 @@ class Repository(Base, BaseModel):
 
            .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 ChangesetComment(Base, BaseModel):
 
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 @@ class ChangesetStatus(Base, BaseModel):
 
        ('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'
rhodecode/public/css/style.css
Show inline comments
 
@@ -2447,6 +2447,17 @@ h3.files_location {
 
    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 @@ div.rst-block  pre {
 
 
/** comment form **/
 
 
.status-block{
 
    height:80px;
 
    clear:both	
 
}
 
 
.comment-form .clearfix{
 
	background: #EEE;
 
    -webkit-border-radius: 4px;
rhodecode/templates/changelog/changelog.html
Show inline comments
 
@@ -65,7 +65,6 @@ ${c.repo_name} ${_('Changelog')} - ${c.r
 
						<div class="right">
 
									<div id="${cs.raw_id}_changes_info" class="changes">
 
                                        <div id="${cs.raw_id}"  style="float:right;" class="changed_total tooltip" title="${_('Affected number of files, click to show more details')}">${len(cs.affected_files)}</div>
 
                                        <div class="changeset-status-container">${c.statuses.get(cs.raw_id)}</div>
 
                                        <div class="comments-container">
 
                                        %if len(c.comments.get(cs.raw_id,[])) > 0:
 
                                            <div class="comments-cnt" title="${('comments')}">
 
@@ -76,6 +75,12 @@ ${c.repo_name} ${_('Changelog')} - ${c.r
 
                                            </div>
 
                                        %endif
 
                                        </div>
 
                                        <div class="changeset-status-container">
 
                                            %if c.statuses.get(cs.raw_id):
 
                                              <img src="${h.url('/images/icons/flag_status_%s.png' % c.statuses.get(cs.raw_id)[0])}" />
 
                                              <div class="changeset-status-lbl">${c.statuses.get(cs.raw_id)[1]}</div>
 
                                            %endif
 
                                        </div>
 
									</div>
 
								   %if cs.parents:
 
									%for p_cs in reversed(cs.parents):
rhodecode/templates/changeset/changeset.html
Show inline comments
 
@@ -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');
 
        	  }
 
          })
 
      })
 

	
 
    </script>
rhodecode/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -79,6 +79,7 @@
 

	
 
</%def>
 

	
 
## MAIN COMMENT FORM
 
<%def name="comments(changeset)">
 

	
 
<div class="comments">
 
@@ -99,6 +100,16 @@
 
            <div class="comment-help">
 
                ${_('Comments parsed using')} <a href="${h.url('rst_help')}">RST</a> ${_('syntax')}
 
                ${_('with')} <span style="color:#003367" class="tooltip" title="${_('Use @username inside this text to send notification to this RhodeCode user')}">@mention</span> ${_('support')}
 
                | <span class="tooltip" title="${_('Check this to change current status of code-review for this changeset')}"> ${_('change status')}
 
                  <input style="vertical-align: bottom;margin-bottom:-2px" id="show_changeset_status_box" type="checkbox" name="change_changeset_status" />
 
                  </span> 
 
            </div>
 
            <div id="status_block_container" class="status-block" style="display:none">
 
                %for status,lbl in c.changeset_statuses:
 
                    <div class="">
 
                        <img src="${h.url('/images/icons/flag_status_%s.png' % status)}" /> <input ${'checked="checked"' if status == h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id) else ''}" type="radio" name="changeset_status" value="${status}"> <label>${lbl}</label>
 
                    </div>                    
 
                %endfor
 
            </div>
 
                ${h.textarea('text')}
 
        </div>
0 comments (0 inline, 0 general)