You can also refer to a revision as an SWH time and place, time being a timestamp of when we
collected it (or as close to the timestamp as we can provide), place being an origin, and
diff --git a/swh/web/ui/tests/views/test_browse.py b/swh/web/ui/tests/views/test_browse.py
--- a/swh/web/ui/tests/views/test_browse.py
+++ b/swh/web/ui/tests/views/test_browse.py
@@ -76,26 +76,26 @@
origin_url='http://cool/project/url'))
@istest
- def search_directory_dir_sha1_only(self):
+ def search_directory_dir_sha1(self):
# when
rv = self.client.get('/directory/search/?sha1_git=some_sha1'
+ '&path=some/path/in/folder'
'&meaningless_arg=gandalf')
# then
self.assertRedirects(rv, url_for('browse_directory',
- sha1_git='some_sha1'))
+ sha1_git='some_sha1',
+ path='some/path/in/folder'))
@istest
- def search_directory_dir_sha1(self):
+ def search_directory_dir_sha1_nopath(self):
# when
rv = self.client.get('/directory/search/?sha1_git=some_sha1'
- '&path=some/path/in/folder'
'&meaningless_arg=gandalf')
# then
self.assertRedirects(rv, url_for('browse_directory',
- sha1_git='some_sha1',
- path='some/path/in/folder'))
+ sha1_git='some_sha1'))
@istest
def search_directory_rev_sha1(self):
@@ -107,7 +107,18 @@
# then
self.assertRedirects(rv, url_for('browse_revision_directory',
sha1_git='some_sha1',
- path='some/path/in/folder'))
+ dir_path='some/path/in/folder'))
+
+ @istest
+ def search_directory_rev_sha1_nopath(self):
+ # when
+ rv = self.client.get('/directory/search/?sha1_git=some_sha1'
+ '&dir_path='
+ '&meaningless_arg=gandalf')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_revision_directory',
+ sha1_git='some_sha1'))
@istest
def search_directory_dir_time_place(self):
diff --git a/swh/web/ui/views/browse.py b/swh/web/ui/views/browse.py
--- a/swh/web/ui/views/browse.py
+++ b/swh/web/ui/views/browse.py
@@ -17,6 +17,10 @@
@app.route('/origin/search/')
def search_origin():
+ """
+ Redirect request with GET params for an origin to our fragmented URI scheme
+
+ """
if request.method == 'GET':
data = request.args
origin_id = data.get('origin_id')
@@ -30,20 +34,36 @@
@app.route('/directory/search/')
def search_directory():
+ """
+ Redirect request with GET params for a directory to our fragmented
+ URI scheme
+
+ """
+
+ def url_for_filtered(endpoint, **kwargs):
+ """Make url_for ignore keyword args that have an empty string for value
+ """
+ filtered = {k: v for k, v in kwargs.items() if kwargs[k]}
+ return url_for(endpoint, **filtered)
+
if request.method == 'GET':
data = request.args
sha1_git = data.get('sha1_git')
if sha1_git:
- path = data.get('path')
if 'dir_path' in data:
- return redirect(url_for('browse_revision_directory',
- sha1_git=sha1_git,
- path=data.get('dir_path')))
- if path:
- return redirect(url_for('browse_directory',
- sha1_git=sha1_git,
- path=path))
- return redirect(url_for('browse_directory', sha1_git=sha1_git))
+ # dir_path exists only in requests for a revision's directory
+ return redirect(url_for_filtered(
+ 'browse_revision_directory',
+ sha1_git=sha1_git,
+ dir_path=data.get('dir_path')
+ ))
+
+ return redirect(url_for_filtered(
+ 'browse_directory',
+ sha1_git=sha1_git,
+ path=data.get('path')
+ ))
+
args = ['origin_id', 'branch_name', 'ts', 'path']
values = {arg: data.get(arg) for arg in args if data.get(arg)}
if 'origin_id' in values:
@@ -53,6 +73,11 @@
@app.route('/revision/search/')
def search_revision():
+ """
+ Redirect request with GET params for a revision to our fragmented
+ URI scheme
+
+ """
if request.method == 'GET':
data = request.args
sha1_git = data.get('sha1_git')
@@ -548,14 +573,14 @@
@app.route('/browse/revision/
/directory/')
-@app.route('/browse/revision//directory//')
-def browse_revision_directory(sha1_git, path=None):
+@app.route('/browse/revision//directory//')
+def browse_revision_directory(sha1_git, dir_path=None):
"""Browse directory from revision with sha1_git.
"""
env = {
'sha1_git': sha1_git,
- 'path': '.' if not path else path,
+ 'path': '.' if not dir_path else dir_path,
'message': None,
'result': None
}
@@ -568,7 +593,7 @@
return render_template('revision-directory.html', **env)
try:
- result = api.api_revision_directory(sha1_git, path, with_data=True)
+ result = api.api_revision_directory(sha1_git, dir_path, with_data=True)
result['content'] = utils.prepare_data_for_view(result['content'],
encoding=encoding)
env['revision'] = result['revision']