Mercurial > kallithea
changeset 7761:b118e9ffc85c
clone_url: simplify the logic - move summary handling of different URLs with/without id to db
Drop the half-baked concept of a separate "clone_uri_by_id" - just always use a
single template and change back and forth between {repo} and _{repoid} as
necessary.
Make it clear that clone_uri_tmpl always is passed as argument.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 31 Jul 2019 02:09:04 +0200 |
parents | 67962f489ddd |
children | 47e11e924cbe |
files | kallithea/controllers/summary.py kallithea/model/db.py |
diffstat | 2 files changed, 9 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/summary.py Tue Jul 30 22:59:44 2019 +0200 +++ b/kallithea/controllers/summary.py Wed Jul 31 02:09:04 2019 +0200 @@ -117,17 +117,8 @@ username = '' else: username = safe_str(request.authuser.username) - - _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl - if '{repo}' in _def_clone_uri_by_id: - _def_clone_uri_by_id = _def_clone_uri_by_id.replace('{repo}', '_{repoid}') - elif '_{repoid}' in _def_clone_uri: - _def_clone_uri = _def_clone_uri.replace('_{repoid}', '{repo}') - else: - log.error("Configured clone_uri_tmpl %r has no '{repo}' or '_{repoid}' and cannot toggle to use repo id URLs", c.clone_uri_tmpl) - - c.clone_repo_url = c.db_repo.clone_url(clone_uri_tmpl=_def_clone_uri, username=username) - c.clone_repo_url_id = c.db_repo.clone_url(clone_uri_tmpl=_def_clone_uri_by_id, username=username) + c.clone_repo_url = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=False, username=username) + c.clone_repo_url_id = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=True, username=username) if c.db_repo.enable_statistics: c.show_stats = True
--- a/kallithea/model/db.py Tue Jul 30 22:59:44 2019 +0200 +++ b/kallithea/model/db.py Wed Jul 31 02:09:04 2019 +0200 @@ -963,7 +963,6 @@ ) DEFAULT_CLONE_URI = '{scheme}://{user}@{netloc}/{repo}' - DEFAULT_CLONE_URI_ID = '{scheme}://{user}@{netloc}/_{repoid}' STATE_CREATED = u'repo_state_created' STATE_PENDING = u'repo_state_pending' @@ -1260,15 +1259,13 @@ clone_uri = url_obj.with_password('*****') return clone_uri - def clone_url(self, **override): - clone_uri_tmpl = None - if 'with_id' in override: - clone_uri_tmpl = self.DEFAULT_CLONE_URI_ID - del override['with_id'] - - if 'clone_uri_tmpl' in override: - clone_uri_tmpl = override['clone_uri_tmpl'] - del override['clone_uri_tmpl'] + def clone_url(self, clone_uri_tmpl, with_id=False, **override): + if '{repo}' not in clone_uri_tmpl and '_{repoid}' not in clone_uri_tmpl: + log.error("Configured clone_uri_tmpl %r has no '{repo}' or '_{repoid}' and cannot toggle to use repo id URLs", clone_uri_tmpl) + elif with_id: + clone_uri_tmpl = clone_uri_tmpl.replace('{repo}', '_{repoid}') + else: + clone_uri_tmpl = clone_uri_tmpl.replace('_{repoid}', '{repo}') import kallithea.lib.helpers as h prefix_url = h.canonical_url('home')