All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [patchwork][PATCH 0/2] Series-view: Enable status/bundle edition
@ 2017-01-30 23:31 Jose Lamego
  2017-01-30 23:31 ` [patchwork][PATCH 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jose Lamego @ 2017-01-30 23:31 UTC (permalink / raw
  To: yocto

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(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patchwork][PATCH 1/2] series.js: Get patch id and pass it to POST request
  2017-01-30 23:31 [patchwork][PATCH 0/2] Series-view: Enable status/bundle edition Jose Lamego
@ 2017-01-30 23:31 ` Jose Lamego
  2017-01-30 23:31 ` [patchwork][PATCH 2/2] series.py: Add POST call Jose Lamego
  2017-02-07 20:17 ` [patchwork][PATCH v2 0/2] Series-view: Enable status/bundle edition Jose Lamego
  2 siblings, 0 replies; 6+ messages in thread
From: Jose Lamego @ 2017-01-30 23:31 UTC (permalink / raw
  To: yocto

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]

Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
 htdocs/js/series.js | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/htdocs/js/series.js b/htdocs/js/series.js
index 4f4f477..1795bc3 100644
--- a/htdocs/js/series.js
+++ b/htdocs/js/series.js
@@ -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)
+                    }
+                }
+            }
+        )
     })
 })
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [patchwork][PATCH 2/2] series.py: Add POST call
  2017-01-30 23:31 [patchwork][PATCH 0/2] Series-view: Enable status/bundle edition Jose Lamego
  2017-01-30 23:31 ` [patchwork][PATCH 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
@ 2017-01-30 23:31 ` Jose Lamego
  2017-02-07 20:17 ` [patchwork][PATCH v2 0/2] Series-view: Enable status/bundle edition Jose Lamego
  2 siblings, 0 replies; 6+ messages in thread
From: Jose Lamego @ 2017-01-30 23:31 UTC (permalink / raw
  To: yocto

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]

Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
 patchwork/views/series.py | 84 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)

diff --git a/patchwork/views/series.py b/patchwork/views/series.py
index 1c14074..0a70232 100644
--- a/patchwork/views/series.py
+++ b/patchwork/views/series.py
@@ -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)
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [patchwork][PATCH v2 0/2] Series-view: Enable status/bundle edition
  2017-01-30 23:31 [patchwork][PATCH 0/2] Series-view: Enable status/bundle edition Jose Lamego
  2017-01-30 23:31 ` [patchwork][PATCH 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
  2017-01-30 23:31 ` [patchwork][PATCH 2/2] series.py: Add POST call Jose Lamego
@ 2017-02-07 20:17 ` Jose Lamego
  2017-02-07 20:17   ` [patchwork][PATCH v2 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
  2017-02-07 20:17   ` [patchwork][PATCH v2 2/2] series.py: Add POST call Jose Lamego
  2 siblings, 2 replies; 6+ messages in thread
From: Jose Lamego @ 2017-02-07 20:17 UTC (permalink / raw
  To: yocto

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(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patchwork][PATCH v2 1/2] series.js: Get patch id and pass it to POST request
  2017-02-07 20:17 ` [patchwork][PATCH v2 0/2] Series-view: Enable status/bundle edition Jose Lamego
@ 2017-02-07 20:17   ` Jose Lamego
  2017-02-07 20:17   ` [patchwork][PATCH v2 2/2] series.py: Add POST call Jose Lamego
  1 sibling, 0 replies; 6+ messages in thread
From: Jose Lamego @ 2017-02-07 20:17 UTC (permalink / raw
  To: yocto

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]

Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
 htdocs/js/series.js | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/htdocs/js/series.js b/htdocs/js/series.js
index 4f4f477..bd75790 100644
--- a/htdocs/js/series.js
+++ b/htdocs/js/series.js
@@ -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)
+                    }
+                }
+            }
+
+        )
     })
 })
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [patchwork][PATCH v2 2/2] series.py: Add POST call
  2017-02-07 20:17 ` [patchwork][PATCH v2 0/2] Series-view: Enable status/bundle edition Jose Lamego
  2017-02-07 20:17   ` [patchwork][PATCH v2 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
@ 2017-02-07 20:17   ` Jose Lamego
  1 sibling, 0 replies; 6+ messages in thread
From: Jose Lamego @ 2017-02-07 20:17 UTC (permalink / raw
  To: yocto

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]

Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
 patchwork/views/series.py | 83 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 2 deletions(-)

diff --git a/patchwork/views/series.py b/patchwork/views/series.py
index 1c14074..5fe8a74 100644
--- a/patchwork/views/series.py
+++ b/patchwork/views/series.py
@@ -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)
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-07 20:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-30 23:31 [patchwork][PATCH 0/2] Series-view: Enable status/bundle edition Jose Lamego
2017-01-30 23:31 ` [patchwork][PATCH 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
2017-01-30 23:31 ` [patchwork][PATCH 2/2] series.py: Add POST call Jose Lamego
2017-02-07 20:17 ` [patchwork][PATCH v2 0/2] Series-view: Enable status/bundle edition Jose Lamego
2017-02-07 20:17   ` [patchwork][PATCH v2 1/2] series.js: Get patch id and pass it to POST request Jose Lamego
2017-02-07 20:17   ` [patchwork][PATCH v2 2/2] series.py: Add POST call Jose Lamego

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.