From: Stephen Finucane Date: Fri, 4 Mar 2016 15:24:00 +0000 (+0000) Subject: views: Integrate cover letter support X-Git-Tag: v2.0.0-rc1~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a2c22d411bf43f908ecab8f2c66a7b52d946349;p=thirdparty%2Fpatchwork.git views: Integrate cover letter support There isn't really any need to list cover letters right now, seeing as they're really only valuable in the context of series. However, if someone requests a cover letter by ID then this should be displayed. To this effect, add a new "covers" endpoint that can display the basic elements of the cover letter. This includes redirects from/to the "patches" endpoint. Signed-off-by: Stephen Finucane Reviewed-by: Andy Doan --- diff --git a/patchwork/templates/patchwork/patch.html b/patchwork/templates/patchwork/submission.html similarity index 77% rename from patchwork/templates/patchwork/patch.html rename to patchwork/templates/patchwork/submission.html index 8b6d1fe3..bda36f9a 100644 --- a/patchwork/templates/patchwork/patch.html +++ b/patchwork/templates/patchwork/submission.html @@ -5,7 +5,7 @@ {% load person %} {% load patch %} -{% block title %}{{patch.name}}{% endblock %} +{% block title %}{{submission.name}}{% endblock %} {% block body %} -

{{ patch.name }}

+

{{ submission.name }}

- Submitted by {{ patch.submitter|personify:project }} on {{ patch.date }} + Submitted by {{ submission.submitter|personify:project }} on {{ submission.date }}

Details

@@ -37,23 +37,25 @@ function toggle_headers(link_id, headers_id) - + + +{% if submission.state %} + + + - - - - -{% if patch.commit_ref %} - - - - {% endif %} -{% if patch.delegate %} - - - - +{% if submission.commit_ref %} + + + + +{% endif %} +{% if submission.delegate %} + + + + {% endif %} @@ -61,14 +63,13 @@ function toggle_headers(link_id, headers_id) href="javascript:toggle_headers('togglepatchheaders', 'patchheaders')" >show
Message ID{{ patch.msgid|msgid }}{{ submission.msgid|msgid }}
State{{ submission.state.name }}{% if submission.archived %}, archived{% endif %}
State{{ patch.state.name }}{% if patch.archived %}, archived{% endif %}
Commit{{ patch.commit_ref }}
Delegated to:{{ patch.delegate.profile.name }}
Commit{{ submission.commit_ref }}
Delegated to:{{ submission.delegate.profile.name }}
Headers
- {% if patchform %}

Patch Properties

@@ -154,13 +155,13 @@ function toggle_headers(link_id, headers_id)
-{% if patch.pull_url %} +{% if submission.pull_url %}

Pull-request

-{{ patch.pull_url }} +{{ submission.pull_url }} {% endif %} -{% if patch.checks %} +{% if submission.checks %}

Checks

@@ -168,7 +169,7 @@ function toggle_headers(link_id, headers_id) -{% for check in patch.checks %} +{% for check in submission.checks %}
Check Description
{{ check.context }} @@ -191,18 +192,22 @@ function toggle_headers(link_id, headers_id)
{% endif %} +{% if submission.diff %}

Commit Message

+{% else %} +

Message

+{% endif %}
- {{ patch.submitter|personify:project }} - {{ patch.date }} + {{ submission.submitter|personify:project }} + {{ submission.date }}
-{{ patch|commentsyntax }}
+{{ submission|commentsyntax }}
 
-{% for item in patch.comments.all %} +{% for item in submission.comments.all %} {% if forloop.first %}

Comments

{% endif %} @@ -218,20 +223,20 @@ function toggle_headers(link_id, headers_id) {% endfor %} -{% if patch.diff %} +{% if submission.diff %}

Patch hide | - download patch | - download mbox

-{{ patch|patchsyntax }}
+{{ submission|patchsyntax }}
 
{% endif %} diff --git a/patchwork/templatetags/syntax.py b/patchwork/templatetags/syntax.py index 85ed201d..6cb8ff89 100644 --- a/patchwork/templatetags/syntax.py +++ b/patchwork/templatetags/syntax.py @@ -74,8 +74,8 @@ def patchsyntax(patch): @register.filter -def commentsyntax(patch): - content = escape(patch.content) +def commentsyntax(submission): + content = escape(submission.content) for (r, cls) in _comment_span_res: content = r.sub(lambda x: _span % (cls, x.group(0)), content) diff --git a/patchwork/tests/test_detail.py b/patchwork/tests/test_detail.py new file mode 100644 index 00000000..bf6df96a --- /dev/null +++ b/patchwork/tests/test_detail.py @@ -0,0 +1,54 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2016 Intel Corporation +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from __future__ import absolute_import + +from django.core.urlresolvers import reverse +from django.test import TestCase + +from patchwork.tests.utils import create_covers +from patchwork.tests.utils import create_patches + + +class CoverLetterViewTest(TestCase): + fixtures = ['default_states'] + + def testRedirect(self): + patches = create_patches() + patch_id = patches[0].id + + requested_url = reverse('cover-detail', kwargs={'cover_id': patch_id}) + redirect_url = reverse('patch-detail', kwargs={'patch_id': patch_id}) + + response = self.client.post(requested_url) + self.assertRedirects(response, redirect_url) + + +class PatchViewTest(TestCase): + fixtures = ['default_states'] + + def testRedirect(self): + covers = create_covers() + cover_id = covers[0].id + + requested_url = reverse('patch-detail', kwargs={'patch_id': cover_id}) + redirect_url = reverse('cover-detail', kwargs={'cover_id': cover_id}) + + response = self.client.post(requested_url) + self.assertRedirects(response, redirect_url) diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py index 375f188c..26087821 100644 --- a/patchwork/tests/utils.py +++ b/patchwork/tests/utils.py @@ -26,7 +26,10 @@ import os from django.contrib.auth.models import User -from patchwork.models import Project, Person, Patch +from patchwork.models import CoverLetter +from patchwork.models import Patch +from patchwork.models import Person +from patchwork.models import Project # helper functions for tests @@ -105,6 +108,24 @@ def create_patches(count=1): return patches +def create_covers(count=1): + """Create 'count' unique cover letters.""" + defaults.project.save() + defaults.patch_author_person.save() + + covers = [] + + for i in range(0, count): + cover = CoverLetter(project=defaults.project, + submitter=defaults.patch_author_person, + msgid=make_msgid(), + name='testcover%d' % (i + 1)) + cover.save() + covers.append(cover) + + return covers + + def find_in_context(context, key): if isinstance(context, list): for c in context: diff --git a/patchwork/urls.py b/patchwork/urls.py index f3fdc5b6..f664501c 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -25,6 +25,7 @@ from django.contrib.auth import views as auth_views from patchwork import views from patchwork.views import api as api_views from patchwork.views import bundle as bundle_views +from patchwork.views import cover as cover_views from patchwork.views import help as help_views from patchwork.views import mail as mail_views from patchwork.views import patch as patch_views @@ -55,6 +56,10 @@ urlpatterns = [ url(r'^patch/(?P\d+)/mbox/$', patch_views.mbox, name='patch-mbox'), + # cover views + url(r'^cover/(?P\d+)/$', cover_views.cover, + name='cover-detail'), + # logged-in user stuff url(r'^user/$', user_views.profile, name='user-profile'), diff --git a/patchwork/views/cover.py b/patchwork/views/cover.py new file mode 100644 index 00000000..83f5551f --- /dev/null +++ b/patchwork/views/cover.py @@ -0,0 +1,50 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2016 Intel Corporation +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from __future__ import absolute_import + +from django.core import urlresolvers +from django.http import Http404 +from django.http import HttpResponseRedirect +from django.shortcuts import render_to_response, get_object_or_404 + +from patchwork.models import CoverLetter, Submission + + +def cover(request, cover_id): + context = {} + + # redirect to patches where necessary + try: + cover = get_object_or_404(CoverLetter, id=cover_id) + except Http404 as exc: + submissions = Submission.objects.filter(id=cover_id) + if submissions: + return HttpResponseRedirect( + urlresolvers.reverse( + 'patch-detail', + kwargs={'patch_id': cover_id})) + raise exc + + context = { + 'submission': cover, + 'project': cover.project, + } + + return render_to_response('patchwork/submission.html', context) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 002d700b..33465681 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -20,19 +20,33 @@ from __future__ import absolute_import from django.contrib import messages -from django.http import HttpResponse, HttpResponseForbidden +from django.core import urlresolvers +from django.http import Http404 +from django.http import HttpResponse +from django.http import HttpResponseForbidden +from django.http import HttpResponseRedirect from django.shortcuts import render, get_object_or_404 from django.utils import six from patchwork.forms import PatchForm, CreateBundleForm -from patchwork.models import Patch, Project, Bundle +from patchwork.models import Patch, Project, Bundle, Submission from patchwork.views import generic_list, patch_to_mbox def patch(request, patch_id): - patch = get_object_or_404(Patch, id=patch_id) - editable = patch.is_editable(request.user) + # redirect to cover letters where necessary + try: + patch = get_object_or_404(Patch, id=patch_id) + except Http404 as exc: + submissions = Submission.objects.filter(id=patch_id) + if submissions: + return HttpResponseRedirect( + urlresolvers.reverse( + 'cover-detail', + kwargs={'cover_id': patch_id})) + raise exc + editable = patch.is_editable(request.user) context = { 'project': patch.project } @@ -86,12 +100,12 @@ def patch(request, patch_id): if request.user.is_authenticated(): context['bundles'] = Bundle.objects.filter(owner=request.user) - context['patch'] = patch + context['submission'] = patch context['patchform'] = form context['createbundleform'] = createbundleform context['project'] = patch.project - return render(request, 'patchwork/patch.html', context) + return render(request, 'patchwork/submission.html', context) def content(request, patch_id):