[yocto] [patchwork][PATCH 1/3] series.py: add patch and bundle edition actions to view
Jose Lamego
jose.a.lamego at linux.intel.com
Mon Feb 27 17:25:33 PST 2017
This change adds patch and bundle edition actions to the series
view.
[YOCTO # 10822]
Signed-off-by: Jose Lamego <jose.a.lamego at linux.intel.com>
---
patchwork/views/series.py | 88 ++++++++++++++++++++++++++++-------------------
1 file changed, 52 insertions(+), 36 deletions(-)
diff --git a/patchwork/views/series.py b/patchwork/views/series.py
index 7645596..cb3b721 100644
--- a/patchwork/views/series.py
+++ b/patchwork/views/series.py
@@ -17,6 +17,7 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from django.http import HttpResponseForbidden
from django.conf import settings
from django.shortcuts import render, render_to_response
from django.shortcuts import get_object_or_404, get_list_or_404
@@ -25,6 +26,7 @@ from patchwork.models import Patch, Project, Bundle
from patchwork.models import Series, SeriesRevision, TestResult
from patchwork.requestcontext import PatchworkRequestContext
from patchwork.forms import PatchForm, CreateBundleForm
+import json
class SeriesListView(View):
@@ -44,6 +46,9 @@ class SeriesView(View):
def get(self, request, *args, **kwargs):
series = get_object_or_404(Series, pk=kwargs['series'])
revisions = get_list_or_404(SeriesRevision, series=series)
+ patchform = PatchForm(project=series.project)
+ createbundleform = CreateBundleForm()
+ bundles = Bundle.objects.filter(owner=request.user)
for revision in revisions:
revision.patch_list = revision.ordered_patches().\
select_related('state', 'submitter')
@@ -56,19 +61,20 @@ class SeriesView(View):
'project': series.project,
'cover_letter': revision.cover_letter,
'revisions': revisions,
+ 'patchform': patchform,
+ 'createbundleform': createbundleform,
+ 'bundles': bundles,
})
def post(self, request, *args, **kwargs):
init_data = request.POST
- pa_id = init_data.get('patch', None)
- curr_rev = init_data.get('rev', None)
- patch = get_object_or_404(Patch, id=pa_id)
+ patches = json.loads(init_data.get('patches'))
series = get_object_or_404(Series, pk=kwargs['series'])
- context = PatchworkRequestContext(request)
- context.project = patch.project
- editable = patch.is_editable(request.user)
-
revisions = get_list_or_404(SeriesRevision, series=series)
+ context = PatchworkRequestContext(request)
+ context.project = series.project
+ form = None
+ createbundleform = None
for revision in revisions:
revision.patch_list = revision.ordered_patches().\
select_related('state', 'submitter')
@@ -76,11 +82,6 @@ class SeriesView(View):
.filter(revision=revision, patch=None) \
.order_by('test__name').select_related('test')
- form = None
- createbundleform = None
-
- if editable:
- form = PatchForm(instance=patch)
if request.user.is_authenticated():
createbundleform = CreateBundleForm()
@@ -90,42 +91,57 @@ class SeriesView(View):
action = action.lower()
if action == 'createbundle':
- bundle = Bundle(owner=request.user, project=patch.project)
+ bundle = Bundle(owner=request.user, project=series.project)
createbundleform = CreateBundleForm(instance=bundle,
data=request.POST)
if createbundleform.is_valid():
createbundleform.save()
- bundle.append_patch(patch)
- bundle.save()
- createbundleform = CreateBundleForm()
- context.add_message('Bundle %s created' % bundle.name)
elif action == 'addtobundle':
bundle = get_object_or_404(
Bundle, id=request.POST.get('bundle_id'))
- try:
- bundle.append_patch(patch)
- bundle.save()
- context.add_message('Patch added to bundle "%s"' %
- bundle.name)
- except Exception as ex:
- context.add_message("Couldn't add patch '%s' to bundle %s:\
- %s" % (patch.name, bundle.name, ex.message))
-
- # all other actions require edit privs
- elif not editable:
- return HttpResponseForbidden()
-
- elif action is None:
- form = PatchForm(data=request.POST, instance=patch)
- if form.is_valid():
- form.save()
- context.add_message('Patch ID: %s updated' % patch.pk)
+
+ for pa_id in patches:
+ patch = get_object_or_404(Patch, id=pa_id)
+ editable = patch.is_editable(request.user)
+
+ if editable:
+ form = PatchForm(instance=patch)
+
+ if action == 'createbundle':
+ if createbundleform.is_valid():
+ bundle.append_patch(patch)
+ bundle.save()
+
+ elif action == 'addtobundle':
+ try:
+ bundle.append_patch(patch)
+ bundle.save()
+ context.add_message('Patch %s added to bundle "%s"' %
+ (patch.pk, bundle.name))
+ except Exception as ex:
+ context.add_message('Couldn\'t add patch %s to bundle\
+ "%s": %s' % (patch.pk, bundle.name, ex.message))
+
+ # all other actions require edit privs
+ elif not editable:
+ return HttpResponseForbidden()
+
+ elif action is None:
+ form = PatchForm(data=request.POST, instance=patch)
+ if form.is_valid():
+ form.save()
+ context.add_message('Patch ID: %s updated' % patch.pk)
+
+ if action == 'createbundle':
+ createbundleform.save()
+ createbundleform = CreateBundleForm()
+ context.add_message('Bundle %s created' % bundle.name)
context['series'] = series
context['patchform'] = form
context['createbundleform'] = createbundleform
- context['project'] = patch.project
+ context['project'] = series.project
context['revisions'] = revisions
context['test_results'] = TestResult.objects \
.filter(revision=None, patch=patch) \
--
2.7.4
More information about the yocto
mailing list