Merge lp:~zyga/linaro-license-protection/zyga into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 93
Merged at revision: 91
Proposed branch: lp:~zyga/linaro-license-protection/zyga
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 91 lines (+35/-1)
3 files modified
license_protected_downloads/models.py (+18/-0)
license_protected_downloads/views.py (+6/-0)
templates/dir_template.html (+11/-1)
To merge this branch: bzr merge lp:~zyga/linaro-license-protection/zyga
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+117064@code.launchpad.net

Description of the change

This is a small branch I did locally for testing BUILD-INFO support.

It extends the directory listing to show the license that is required to
download something. I'm not sure if you want to get it applied but it could be
useful for others so I though I would post it.

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks good. Thanks for working on this - it was on our TODO list, so thanks for ticking that item off :-)

review: Approve
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

You may want to stop inserting tabs into python though... PEP8 gets a bit angry over mixing tabs and spaces!

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Sorry about that, wrong editor

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'license_protected_downloads/models.py'
2--- license_protected_downloads/models.py 2012-07-11 11:56:10 +0000
3+++ license_protected_downloads/models.py 2012-07-27 14:10:45 +0000
4@@ -1,10 +1,28 @@
5 from django.db import models
6
7
8+class LicenseManager(models.Manager):
9+ """
10+ Model manager for License model.
11+
12+ Provides additional convenience method
13+ """
14+
15+ def all_with_hashes(self, hash_list):
16+ """
17+ Produce a list of licenses that match the specified list of hashes.
18+ The main use case is to convert license digest to something the user
19+ can relate to.
20+ """
21+ return self.all().filter(digest__in=hash_list)
22+
23+
24 class License(models.Model):
25 digest = models.CharField(max_length=40)
26 text = models.TextField()
27 theme = models.CharField(max_length=60)
28
29+ objects = LicenseManager()
30+
31 def __unicode__(self):
32 return self.digest
33
34=== modified file 'license_protected_downloads/views.py'
35--- license_protected_downloads/views.py 2012-07-11 13:13:56 +0000
36+++ license_protected_downloads/views.py 2012-07-27 14:10:45 +0000
37@@ -64,10 +64,16 @@
38 size = os.path.getsize(file)
39 if not re.search(r'^/', url) and url != '':
40 url = '/' + url
41+
42+ pathname = os.path.join(path, name)
43+ license_digest_list = is_protected(pathname)
44+ license_list = License.objects.all_with_hashes(license_digest_list)
45 listing.append({'name': name,
46 'size': size,
47 'type': type,
48 'mtime': mtime,
49+ 'license_digest_list': license_digest_list,
50+ 'license_list': license_list,
51 'url': url + '/' + name})
52 return listing
53
54
55=== modified file 'manage.py' (properties changed: -x to +x)
56=== modified file 'templates/dir_template.html'
57--- templates/dir_template.html 2012-06-27 15:49:28 +0000
58+++ templates/dir_template.html 2012-07-27 14:10:45 +0000
59@@ -3,7 +3,7 @@
60 {% block content %}
61 <table>
62 <tr>
63- <th></th><th>Name</th><th>Last modified</th><th>Size</th>
64+ <th></th><th>Name</th><th>License</th><th>Last modified</th><th>Size</th>
65 <tr><th colspan="5"><hr></th>
66 </tr>
67 {% if up_dir != None %}
68@@ -14,6 +14,7 @@
69 <td><a href="{{ up_dir }}">Parent Directory</a></td>
70 <td></td>
71 <td></td>
72+ <td></td>
73 </tr>
74 {% endif %}
75
76@@ -23,6 +24,15 @@
77 <img src="{{ STATIC_URL }}/static/{{ value.type }}.png" alt="{{ value.type }}"/>
78 </td>
79 <td><a href="{{ value.url }}">{{ value.name }}</a></td>
80+ <td>
81+ {% if value.license_digest_list == "OPEN" %}
82+ <i>open</i>
83+ {% else %}
84+ {% for license in value.license_list %}
85+ {{ license.theme }}
86+ {% endfor %}
87+ {% endif %}
88+ </td>
89 <td>{{ value.mtime }}</td>
90 <td>{% if value.type != 'folder' %}{{ value.size }}{% endif %}</td>
91 </tr>

Subscribers

People subscribed via source and target branches