diff options
author | Andy Doan <andy.doan@linaro.org> | 2015-05-15 14:38:46 -0500 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2015-05-18 10:02:58 -0500 |
commit | 88a304d85924a7a661d7f21053efdbdd09233d83 (patch) | |
tree | 700bc5d67c26061e4114ebc853b68f2bae674738 | |
parent | 290e0b9440d930283a5ef222f2c421ff97a23c03 (diff) |
only show license column when have files in the directory
This change helps 2 things:
1) people sometimes find it confusing why we don't show license values
2) performance - we have to recurse into each sub-directory when doing a
directory listing, to find license info.
This helps #1 by only showing the column if there's a file with
licensing. #2 is less important now, but will likely be important in the
future if we move away from using local disk for storing artifacts.
Change-Id: I31d4e4a34a8f289163f1ba3fa9297a115a7579b9
-rw-r--r-- | license_protected_downloads/common.py | 19 | ||||
-rw-r--r-- | license_protected_downloads/tests/test_views.py | 4 | ||||
-rw-r--r-- | license_protected_downloads/views.py | 7 | ||||
-rw-r--r-- | templates/dir_template.html | 2 |
4 files changed, 19 insertions, 13 deletions
diff --git a/license_protected_downloads/common.py b/license_protected_downloads/common.py index 499a34e..df3af29 100644 --- a/license_protected_downloads/common.py +++ b/license_protected_downloads/common.py @@ -243,8 +243,18 @@ def dir_list(url, path, human_readable=True): if os.path.isdir(file_name): target_type = "folder" + license_digest_list = [] else: target_type = mimetypes.guess_type(name)[0] + pathname = os.path.join(path, name) + try: + license_digest_list = is_protected(pathname) + except Exception as e: + print("Invalid BUILD-INFO.txt for %s: %s" % (pathname, repr(e))) + traceback.print_exc() + license_digest_list = "INVALID" + license_list = models.License.objects.all_with_hashes( + license_digest_list) if os.path.exists(file_name): size = os.path.getsize(file_name) @@ -272,15 +282,6 @@ def dir_list(url, path, human_readable=True): size = _sizeof_fmt(size) - pathname = os.path.join(path, name) - try: - license_digest_list = is_protected(pathname) - except Exception as e: - print("Invalid BUILD-INFO.txt for %s: %s" % (pathname, repr(e))) - traceback.print_exc() - license_digest_list = "INVALID" - license_list = models.License.objects.all_with_hashes( - license_digest_list) listing.append({'name': name, 'size': size, 'type': target_type, diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py index 581678a..ca240b7 100644 --- a/license_protected_downloads/tests/test_views.py +++ b/license_protected_downloads/tests/test_views.py @@ -302,8 +302,8 @@ class ViewTests(BaseServeViewTest): # If we have access to the file, we will get an X-Sendfile response self.assertContains( response, - r"<th></th><th>Name</th><th>Last modified</th>" - "<th>Size</th><th>License</th>") + r'<th></th><th>Name</th><th>Last modified</th>' + '<th>Size</th><th style="display: None">License</th>') def test_not_found_file(self): target_file = "12qwaszx" diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py index eec11da..ec5b6c2 100644 --- a/license_protected_downloads/views.py +++ b/license_protected_downloads/views.py @@ -285,13 +285,18 @@ def _handle_dir_list(request, url, path): rendered_files = {} rendered_files["Git Descriptions"] = render_descriptions(path) + dirlist = dir_list(url, path) + lics = [x['license_digest_list'] for x in dirlist + if x['license_digest_list']] + args = { - 'dirlist': dir_list(url, path), + 'dirlist': dirlist, 'up_dir': up_dir, 'dl': download, 'header_content': header_content, 'request': request, 'rendered_files': rendered_files, + 'hide_lics': len(lics) == 0, } return render(request, 'dir_template.html', args) diff --git a/templates/dir_template.html b/templates/dir_template.html index f9977e6..80df98e 100644 --- a/templates/dir_template.html +++ b/templates/dir_template.html @@ -5,7 +5,7 @@ <table> <thead> <tr> - <th></th><th>Name</th><th>Last modified</th><th>Size</th><th>License</th> + <th></th><th>Name</th><th>Last modified</th><th>Size</th><th {%if hide_lics %}style="display: None"{% endif %}>License</th> </tr> <tr> <th colspan="5"><hr></th> |