Mercurial > kallithea
changeset 2363:745dda7817ed codereview
Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 30 May 2012 23:12:16 +0200 |
parents | 3c4afb8894bd |
children | 9d61aad859bc |
files | rhodecode/config/routing.py rhodecode/controllers/compare.py rhodecode/templates/branches/branches.html rhodecode/templates/changelog/changelog.html |
diffstat | 4 files changed, 26 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/config/routing.py Wed May 30 22:23:23 2012 +0200 +++ b/rhodecode/config/routing.py Wed May 30 23:12:16 2012 +0200 @@ -416,10 +416,12 @@ controller='changeset', action='raw_changeset', revision='tip', conditions=dict(function=check_repo)) - rmap.connect('compare_home', - '/{repo_name:.*}/compare/{ref:.*}', + rmap.connect('compare_url', + '/{repo_name:.*}/compare/{org_ref_type}@{org_ref}...{other_ref_type}@{other_ref}', controller='compare', action='index', - conditions=dict(function=check_repo)) + conditions=dict(function=check_repo), + requirements=dict(org_ref_type='(branch|book|tag)', + other_ref_type='(branch|book|tag)')) rmap.connect('pullrequest_home', '/{repo_name:.*}/pull-request/new',
--- a/rhodecode/controllers/compare.py Wed May 30 22:23:23 2012 +0200 +++ b/rhodecode/controllers/compare.py Wed May 30 23:12:16 2012 +0200 @@ -49,41 +49,6 @@ def __before__(self): super(CompareController, self).__before__() - def _handle_ref(self, ref): - """ - Parse the org...other string - Possible formats are - `(branch|book|tag):<name>...(branch|book|tag):<othername>` - - :param ref: <orginal_reference>...<other_reference> - :type ref: str - """ - org_repo = c.rhodecode_db_repo.repo_name - - def org_parser(org): - _repo = org_repo - name, val = org.split(':') - return _repo, (name, val) - - def other_parser(other): - _other_repo = request.GET.get('repo') - _repo = org_repo - name, val = other.split(':') - if _other_repo: - _repo = _other_repo - - return _repo, (name, val) - - if '...' in ref: - try: - org, other = ref.split('...') - org_repo, org_ref = org_parser(org) - other_repo, other_ref = other_parser(other) - return org_repo, org_ref, other_repo, other_ref - except: - log.error(traceback.format_exc()) - - raise HTTPNotFound def _get_discovery(self, org_repo, org_ref, other_repo, other_ref): from mercurial import discovery @@ -125,13 +90,18 @@ return changesets - def index(self, ref): - org_repo, org_ref, other_repo, other_ref = self._handle_ref(ref) + def index(self, org_ref_type, org_ref, other_ref_type, other_ref): - c.swap_url = h.url('compare_home', repo_name=other_repo, - ref='%s...%s' % (':'.join(other_ref), - ':'.join(org_ref)), - repo=org_repo) + org_repo = c.rhodecode_db_repo.repo_name + org_ref = (org_ref_type, org_ref) + other_ref = (other_ref_type, other_ref) + other_repo = request.GET.get('repo', org_repo) + + c.swap_url = h.url('compare_url', repo_name=other_repo, + org_ref_type=other_ref[0], org_ref=other_ref[1], + other_ref_type=org_ref[0], other_ref=org_ref[1], + repo=org_repo) + c.org_repo = org_repo = Repository.get_by_repo_name(org_repo) c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
--- a/rhodecode/templates/branches/branches.html Wed May 30 22:23:23 2012 +0200 +++ b/rhodecode/templates/branches/branches.html Wed May 30 23:12:16 2012 +0200 @@ -37,10 +37,11 @@ YUE.preventDefault(e); var org = YUQ('input[name=compare_org]:checked')[0]; var other = YUQ('input[name=compare_other]:checked')[0]; - var compare_url = "${h.url('compare_home',repo_name=c.repo_name,ref='__ORG__...__OTHER__')}"; + if(org && other){ - var u = compare_url.replace('__ORG__','branch:'+org.value) - .replace('__OTHER__','branch:'+other.value); + var compare_url = "${h.url('compare_url',repo_name=c.repo_name,org_ref_type='branch',org_ref='__ORG__',other_ref_type='branch',other_ref='__OTHER__')}"; + var u = compare_url.replace('__ORG__',org.value) + .replace('__OTHER__',other.value); window.location=u; }
--- a/rhodecode/templates/changelog/changelog.html Wed May 30 22:23:23 2012 +0200 +++ b/rhodecode/templates/changelog/changelog.html Wed May 30 23:12:16 2012 +0200 @@ -32,7 +32,12 @@ <canvas id="graph_canvas"></canvas> </div> <div id="graph_content"> - <div class="info_box" style="clear: both;padding: 10px 6px;vertical-align: right;text-align: right;"><a href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a></div> + <div class="info_box" style="clear: both;padding: 10px 6px;vertical-align: right;text-align: right;"> + %if c.rhodecode_db_repo.fork: + <a title="${_('compare fork with %s' % c.rhodecode_db_repo.fork.repo_name)}" href="${h.url('compare_url',repo_name=c.repo_name,org_ref_type='branch',org_ref='default',other_ref_type='branch',other_ref='default',repo=c.rhodecode_db_repo.fork.repo_name)}" class="ui-btn small">${_('Compare fork')}</a> + %endif + <a href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a> + </div> <div class="container_header"> ${h.form(h.url.current(),method='get')} <div class="info_box" style="float:left">