Skip to contentSkip to conversation

Series-view: Enable status/bundle edition

PATCH Superseded Jose Lamego 1 participant 6 messages Jan 30, 2017 – Feb 7, 2017

lore
Share & tools
lore
#0 lore raw

cover Series-view: Enable status/bundle edition

This changes enable patch status updating, adding a patch to an existing bundle and creating a new bundle from the series view.

[YOCTO #10973]

Jose Lamego (2):
series.js: Get patch id and pass it to POST request series.py: Add POST call

 htdocs/js/series.js       | 24 ++++++++++++--
 patchwork/views/series.py | 84 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 104 insertions(+), 4 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 series.js: Get patch id and pass it to POST request

Patch forms in series view do not pass selected patch id as context element during a POST call, so no status/bundle updates can be performed from such view.

This change includes the selected patch id as a context element and pass it to POST call through a hidden input field.

[YOCTO #10973]

---
 htdocs/js/series.js | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
htdocs/js/series.js +22 -2
index 4f4f477..1795bc3 100644
@@ -1,5 +1,5 @@
 $(document).ready(function(){
-    $('[data-toggle="tooltip"]').tooltip();
+    $('[data-toggle="tooltip"]').tooltip()
     revTab=document.getElementById('revs-list')
     coverView=document.getElementById('cover-letter-view'),
     patchView=document.getElementById('patch-view'),
@@ -34,10 +34,30 @@ $(document).ready(function(){
     })
 
     $('.patch-link').on('click', function(){
+        var pa=this.getAttribute("data-url")
+        var curr_rev=document.getElementById('revs-list').value
+        pa=pa.match(/\d+/)[0]
         coverView.style.display='none'
         patchView.style.display='block'
         patchView.innerHTML=
         '<p style="text-align:center;">Loading patch...</p>'
-        $("#patch-view").load(this.getAttribute("data-url") + " #patch-body")
+        $("#patch-view").load(
+            this.getAttribute("data-url") + " #patch-body", function() {
+                forms=document.forms
+                for (i=0 i < document.forms.length i++){
+                    var n=(i + 1)
+                    var patch_field=document.createElement("input")
+                    patch_field.type="hidden"
+                    patch_field.name="patch"
+                    patch_field.value=pa
+                    var div=document.createElement("div")
+                    var this_form=document.forms.item(i)
+                    if (typeof this_form !== "undefined"){
+                        this_form.appendChild(div)
+                        div.appendChild(patch_field)
+                    }
+                }
+            }
+        )
     })
 })
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/2 series.py: Add POST call

In reply to Jose Lamego

Current view is missing a POST call, avoiding users to update or edit patch status or bundles.

This change adds POST call to series view, including the target patch id, which is taken from request context.

[YOCTO #10973]

---
 patchwork/views/series.py | 84 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)
patchwork/views/series.py +82 -2
index 1c14074..0a70232 100644
@@ -18,9 +18,14 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 from django.conf import settings
-from django.shortcuts import render, get_object_or_404, get_list_or_404
+from django.shortcuts import render, render_to_response
+from django.shortcuts import get_object_or_404, get_list_or_404
+from django.http import HttpResponseForbidden
 from django.views.generic import View
-from patchwork.models import Project, Series, SeriesRevision, TestResult
+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
 
 
 class SeriesListView(View):
@@ -53,3 +58,78 @@ class SeriesView(View):
             'cover_letter': revision.cover_letter,
             'revisions': revisions,
         })
+
+    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)
+        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)
+        for revision in revisions:
+            revision.patch_list = revision.ordered_patches().\
+                select_related('state', 'submitter')
+            revision.test_results = TestResult.objects \
+                    .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()
+
+        if request.method == 'POST':
+            action = request.POST.get('action', None)
+            if action:
+                action = action.lower()
+
+            if action == 'createbundle':
+                bundle = Bundle(owner=request.user, project=patch.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)
+
+        context['series'] = series
+        context['patchform'] = form
+        context['createbundleform'] = createbundleform
+        context['project'] = patch.project
+        context['revisions'] = revisions
+        context['test_results'] = TestResult.objects \
+            .filter(revision=None, patch=patch) \
+            .order_by('test__name').select_related('test')
+
+        return render_to_response('patchwork/series.html', context)
Signature · 1 line
1.9.1
#3 lore raw

v2 cover Series-view: Enable status/bundle edition

In reply to Jose Lamego

These changes enable patch status updating, adding a patch to an existing bundle and creating a new bundle from the series view.

[YOCTO #10973]

Changes in v2: Fixed javascript formatting and pep8 compliance.

Jose Lamego (2):
series.js: Get patch id and pass it to POST request series.py: Add POST call

 htdocs/js/series.js       | 25 ++++++++++++--
 patchwork/views/series.py | 83 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 104 insertions(+), 4 deletions(-)
Signature · 1 line
1.9.1
#4 lore raw

PATCH v2 1/2 series.js: Get patch id and pass it to POST request

Patch forms in series view do not pass selected patch id as request element during a POST call, so no status/bundle updates can be performed from such view.

This change includes the selected patch id as a request element and pass it to POST call through a hidden input field.

[YOCTO #10973]

---
 htdocs/js/series.js | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
htdocs/js/series.js +23 -2
index 4f4f477..bd75790 100644
@@ -1,5 +1,5 @@
 $(document).ready(function(){
-    $('[data-toggle="tooltip"]').tooltip();
+    $('[data-toggle="tooltip"]').tooltip()
     revTab=document.getElementById('revs-list')
     coverView=document.getElementById('cover-letter-view'),
     patchView=document.getElementById('patch-view'),
@@ -34,10 +34,31 @@ $(document).ready(function(){
     })
 
     $('.patch-link').on('click', function(){
+        var pa=this.getAttribute("data-url")
+        var curr_rev=document.getElementById('revs-list').value
+        pa=pa.match(/\d+/)[0]
         coverView.style.display='none'
         patchView.style.display='block'
         patchView.innerHTML=
         '<p style="text-align:center;">Loading patch...</p>'
-        $("#patch-view").load(this.getAttribute("data-url") + " #patch-body")
+        $("#patch-view").load(
+            this.getAttribute("data-url") + " #patch-body", function() {
+                forms=document.forms
+                for (i=0; i<document.forms.length; i++){
+                    var n=(i + 1)
+                    var patch_field=document.createElement("input")
+                    patch_field.type="hidden"
+                    patch_field.name="patch"
+                    patch_field.value=pa
+                    var div=document.createElement("div")
+                    var this_form=document.forms.item(i)
+                    if (typeof this_form !== "undefined"){
+                        this_form.appendChild(div)
+                        div.appendChild(patch_field)
+                    }
+                }
+            }
+
+        )
     })
 })
Signature · 1 line
1.9.1
#5 lore raw

PATCH v2 2/2 series.py: Add POST call

In reply to Jose Lamego

Current series view is missing a POST call, avoiding users to update or edit patch status or bundles.

This change adds POST call to series view, including the target patch id, which is taken from request context.

[YOCTO #10973]

---
 patchwork/views/series.py | 83 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 2 deletions(-)
patchwork/views/series.py +81 -2
index 1c14074..5fe8a74 100644
@@ -18,9 +18,13 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 from django.conf import settings
-from django.shortcuts import render, get_object_or_404, get_list_or_404
+from django.shortcuts import render, render_to_response
+from django.shortcuts import get_object_or_404, get_list_or_404
 from django.views.generic import View
-from patchwork.models import Project, Series, SeriesRevision, TestResult
+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
 
 
 class SeriesListView(View):
@@ -53,3 +57,78 @@ class SeriesView(View):
             'cover_letter': revision.cover_letter,
             'revisions': revisions,
         })
+
+    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)
+        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)
+        for revision in revisions:
+            revision.patch_list = revision.ordered_patches().\
+                select_related('state', 'submitter')
+            revision.test_results = TestResult.objects \
+                    .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()
+
+        if request.method == 'POST':
+            action = request.POST.get('action', None)
+            if action:
+                action = action.lower()
+
+            if action == 'createbundle':
+                bundle = Bundle(owner=request.user, project=patch.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)
+
+        context['series'] = series
+        context['patchform'] = form
+        context['createbundleform'] = createbundleform
+        context['project'] = patch.project
+        context['revisions'] = revisions
+        context['test_results'] = TestResult.objects \
+            .filter(revision=None, patch=patch) \
+            .order_by('test__name').select_related('test')
+
+        return render_to_response('patchwork/series.html', context)
Signature · 1 line
1.9.1