From patchwork Wed May 11 10:13:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 95121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id D93F21007D9 for ; Wed, 11 May 2011 20:13:55 +1000 (EST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by ozlabs.org (Postfix) with ESMTP id A71DAB6F0A for ; Wed, 11 May 2011 20:13:52 +1000 (EST) Received: from youngberry.canonical.com ([91.189.89.112]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QK6QQ-0005qG-N6; Wed, 11 May 2011 10:13:50 +0000 Received: from business-89-133-214-82.business.broadband.hu ([89.133.214.82] helo=feioso) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1QK6QQ-0005Vp-HQ; Wed, 11 May 2011 10:13:50 +0000 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by feioso (Postfix) with ESMTP id 4F76940DC4; Wed, 11 May 2011 07:13:49 -0300 (BRT) Subject: [PATCH V2] A new page that displays the patches for which the user is waiting feedback To: patchwork@lists.ozlabs.org From: Guilherme Salgado Date: Wed, 11 May 2011 12:13:49 +0200 Message-ID: <20110511101339.24179.50441.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 Cc: patches@linaro.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org This page shows all patches in a state that requires action and that have been submitted by the logged in user to a given project. Also, the profile page now has an extra section with links to this page for every project on which the user has patches that need feedback. Signed-off-by: Guilherme Salgado --- apps/patchwork/models.py | 6 ++++ apps/patchwork/tests/__init__.py | 1 + apps/patchwork/tests/models.py | 42 +++++++++++++++++++++++++++++++ apps/patchwork/urls.py | 2 + apps/patchwork/views/user.py | 27 +++++++++++++++++--- templates/patchwork/profile.html | 13 ++++++++++ templates/patchwork/submitted-list.html | 14 ++++++++++ 7 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 apps/patchwork/tests/models.py create mode 100644 templates/patchwork/submitted-list.html diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 6c8fc71..6a7ffc5 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -104,6 +104,12 @@ class UserProfile(models.Model): def n_todo_patches(self): return self.todo_patches().count() + def submitted_patches_waiting_feedback(self, project): + people = Person.objects.filter(user=self.user) + states = State.objects.filter(action_required=True) + return Patch.objects.filter( + project=project, submitter__in=people, state__in=states) + def todo_patches(self, project = None): # filter on project, if necessary diff --git a/apps/patchwork/tests/__init__.py b/apps/patchwork/tests/__init__.py index 68fe563..3adbbe7 100644 --- a/apps/patchwork/tests/__init__.py +++ b/apps/patchwork/tests/__init__.py @@ -23,3 +23,4 @@ from patchwork.tests.bundles import * from patchwork.tests.mboxviews import * from patchwork.tests.updates import * from patchwork.tests.filters import * +from patchwork.tests.models import * diff --git a/apps/patchwork/tests/models.py b/apps/patchwork/tests/models.py new file mode 100644 index 0000000..91bfb9d --- /dev/null +++ b/apps/patchwork/tests/models.py @@ -0,0 +1,42 @@ + +from django.test import TestCase + +from patchwork.models import State +from patchwork.tests.factory import factory + + +class UserProfileTestCase(TestCase): + + def test_submitted_patches_waiting_feedback(self): + # Create two people linked to the same user. + person = factory.makePerson(is_user=True) + profile = person.user.get_profile() + person2 = factory.makePerson(is_user=False) + person2.user = person.user + person2.save() + + # Create 3 patches that + # - apply to the same project; + # - have been submitted by a Person linked to our newly created user + # Of those 3 patches, only the first two are in a state that needs + # action, so only those will be returned by + # submitted_patches_waiting_feedback(). + # We also create a couple more patches, but one of them applies to a + # different project than the ones created above and the other has not + # been submitted by a Person linked to our user, so they are not in + # the patches returned by submitted_patches_waiting_feedback(). + patch1 = factory.makePatch(submitter=person) + project = patch1.project + patch2 = factory.makePatch(project=project, submitter=person2) + patch3 = factory.makePatch(project=project, submitter=person2) + patch3.state = State.objects.get(name='Accepted') + patch3.save() + patch4 = factory.makePatch(submitter=person2) + patch5 = factory.makePatch(project=project) + + # Here we see that UserProfile.submitted_patches_waiting_feedback() + # only returns the two patches that are in a state that requires + # action and that have been submitted by a person linked to that + # profile. + patches = profile.submitted_patches_waiting_feedback(patch1.project) + self.assertEquals([patch1, patch2], list(patches)) diff --git a/apps/patchwork/urls.py b/apps/patchwork/urls.py index b49b4e1..984b843 100644 --- a/apps/patchwork/urls.py +++ b/apps/patchwork/urls.py @@ -33,6 +33,8 @@ urlpatterns = patterns('', # logged-in user stuff (r'^user/$', 'patchwork.views.user.profile'), + (r'^user/submitted/(?P[^/]+)/$', + 'patchwork.views.user.submitted_patches_list'), (r'^user/todo/$', 'patchwork.views.user.todo_lists'), (r'^user/todo/(?P[^/]+)/$', 'patchwork.views.user.todo_list'), diff --git a/apps/patchwork/views/user.py b/apps/patchwork/views/user.py index 1ae3c2d..6220156 100644 --- a/apps/patchwork/views/user.py +++ b/apps/patchwork/views/user.py @@ -36,15 +36,22 @@ import django.core.urlresolvers def profile(request): context = PatchworkRequestContext(request) + profile = request.user.get_profile() if request.method == 'POST': - form = UserProfileForm(instance = request.user.get_profile(), - data = request.POST) + form = UserProfileForm(instance = profile, data = request.POST) if form.is_valid(): form.save() else: - form = UserProfileForm(instance = request.user.get_profile()) + form = UserProfileForm(instance = profile) - context.project = request.user.get_profile().primary_project + patches_waiting_for_feedback = {} + for project in profile.contributor_projects(): + patches = profile.submitted_patches_waiting_feedback(project) + if patches.count() > 0: + patches_waiting_for_feedback[project] = patches + context['patches_waiting_for_feedback'] = patches_waiting_for_feedback + + context.project = profile.primary_project context['bundles'] = Bundle.objects.filter(owner = request.user) context['profileform'] = form @@ -109,6 +116,18 @@ def unlink(request, person_id): @login_required +def submitted_patches_list(request, project_id): + project = get_object_or_404(Project, linkname=project_id) + profile = request.user.get_profile() + context = generic_list( + request, project, 'patchwork.views.user.submitted_patches_list', + view_args={'project_id': project_id}, + patches=profile.submitted_patches_waiting_feedback(project)) + + return render_to_response('patchwork/submitted-list.html', context) + + +@login_required def todo_lists(request): todo_lists = [] diff --git a/templates/patchwork/profile.html b/templates/patchwork/profile.html index 44df921..d4759c7 100644 --- a/templates/patchwork/profile.html +++ b/templates/patchwork/profile.html @@ -36,6 +36,19 @@ Contributor to
+

Patches for which you are waiting feedback

+ {% if patches_waiting_for_feedback %} + {% for project, patches in patches_waiting_for_feedback.items %} +

+ {{ patches.count }} {{ project.linkname }} patches +

+ {% endfor %} + {% else %} +

There doesn't seem to be any patches for which you are waiting feedback.

+ {% endif %} +
+ +

Linked email addresses

The following email addresses are associated with this patchwork account. Adding alternative addresses allows patchwork to group contributions that diff --git a/templates/patchwork/submitted-list.html b/templates/patchwork/submitted-list.html new file mode 100644 index 0000000..1604187 --- /dev/null +++ b/templates/patchwork/submitted-list.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% load person %} + +{% block title %}Your patches for {{ project.name }}{% endblock %} +{% block heading %}Your patches for {{ project.name }}{% endblock %} + +{% block body %} + +

Patches for which you are waiting feedback

+ +{% include "patchwork/patch-list.html" %} + +{% endblock %}