[PATCH 10/10] bundles: show public bundles by default
WEN Pingbo
wengpingbo at gmail.com
Tue Aug 23 19:05:52 AEST 2016
Signed-off-by: WEN Pingbo <wengpingbo at gmail.com>
---
patchwork/templates/patchwork/bundles.html | 46 ++++++++++++++++++++++++++----
patchwork/views/bundle.py | 32 ++++++++++++++++-----
2 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/patchwork/templates/patchwork/bundles.html b/patchwork/templates/patchwork/bundles.html
index 2eebd26..1ee9ee0 100644
--- a/patchwork/templates/patchwork/bundles.html
+++ b/patchwork/templates/patchwork/bundles.html
@@ -6,9 +6,9 @@
{% block bundle_active %}active{% endblock %}
{% block body %}
-<h1>Bundles</h1>
+<h1>Your Bundles</h1>
-{% if bundles %}
+{% if owned_bundles %}
<table class="bundlelist">
<tr>
<th>Name</th>
@@ -18,7 +18,7 @@
<th>Download</th>
<th>Delete</th>
</tr>
-{% for bundle in bundles %}
+{% for bundle in owned_bundles %}
<tr>
<td><a href="{{ bundle.get_absolute_url }}">{{ bundle.name }}</a></td>
<td>{{ bundle.project.linkname }}</td>
@@ -42,19 +42,53 @@
title="delete" border="0" style="border: none;"/>
</form>
</td>
+ </tr>
+{% endfor %}
+</table>
+{% endif %}
+{% if not owned_bundles %}
+<p>You have no bundles.</p>
+{% endif %}
+
+<h1>Public Bundles</h1>
+
+{% if pub_bundles %}
+<table class="bundlelist">
+ <tr>
+ <th>Name</th>
+ <th>Project</th>
+ <th>Public Link</th>
+ <th>Patches</td>
+ <th>Download</th>
+ </tr>
+{% for bundle in pub_bundles %}
+ <tr>
+ <td><a href="{{ bundle.get_absolute_url }}">{{ bundle.name }}</a></td>
+ <td>{{ bundle.project.linkname }}</td>
+ <td>
+ {% if bundle.public %}
+ <a href="{{ bundle.public_url }}">{{ bundle.public_url }}</a>
+ {% endif %}
+ </td>
+ <td style="text-align: right">{{ bundle.n_patches }}</td>
+ <td style="text-align: center;"><a
+ href="{% url 'bundle-mbox' username=bundle.owner.username bundlename=bundle.name %}"
+ ><img src="{% static "images/16-em-down.png" %}" width="16" height="16" alt="download"
+ title="download"/></a></td>
</tr>
{% endfor %}
</table>
{% endif %}
+{% if not pub_bundles %}
+<p>No public bundles in this project.</p>
+{% endif %}
+
<p>Bundles are groups of related patches. You can create bundles by
selecting patches from a project, then using the 'create bundle' form
to give your bundle a name. Each bundle can be public or private; public
bundles are given a persistent URL, based you your username and the name
of the bundle. Private bundles are only visible to you.</p>
-{% if not bundles %}
-<p>You have no bundles.</p>
-{% endif %}
{% endblock %}
diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py
index dabaef1..55dffaf 100644
--- a/patchwork/views/bundle.py
+++ b/patchwork/views/bundle.py
@@ -101,9 +101,7 @@ def setbundle(request):
@login_required
-def bundles(request, project_id=None):
- project = None
-
+def internal_bundles(request, project=None):
if request.method == 'POST':
form_name = request.POST.get('form_name', '')
@@ -114,24 +112,44 @@ def bundles(request, project_id=None):
id=form.cleaned_data['bundle_id'])
bundle.delete()
- if project_id is None:
+ if project is None:
bundles = Bundle.objects.filter(owner=request.user)
else:
- project = get_object_or_404(Project, linkname=project_id)
bundles = Bundle.objects.filter(owner=request.user, project=project)
for bundle in bundles:
bundle.delete_form = DeleteBundleForm(auto_id=False,
initial={'bundle_id': bundle.id})
+ return bundles
+
+def bundles(request, project_id=None):
+ project = None
+ bundles = None
+
+ if project_id:
+ project = get_object_or_404(Project, linkname=project_id)
+
+ if request.user.is_authenticated():
+ bundles = internal_bundles(request, project)
+
+ # show public bundles
+ if project is None:
+ bundles_pub = Bundle.objects.filter(public=True)
+ else:
+ bundles_pub = Bundle.objects.filter(public=True, project=project)
+
+ if request.user.is_authenticated():
+ bundles_pub = bundles_pub.exclude(owner=request.user)
+
context = {
- 'bundles': bundles,
+ 'owned_bundles': bundles,
+ 'pub_bundles': bundles_pub,
'project': project,
}
return render(request, 'patchwork/bundles.html', context)
-
def bundle(request, username, bundlename):
bundle = get_object_or_404(Bundle, owner__username=username,
name=bundlename)
--
1.9.1
More information about the Patchwork
mailing list