From patchwork Sun Oct 14 12:45:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1YV22QSz9s8F for ; Sun, 14 Oct 2018 23:47:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="M0NIL2s2"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1YT4yPgzF31L for ; Sun, 14 Oct 2018 23:47:09 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="M0NIL2s2"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.8; helo=relay001.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="M0NIL2s2"; dkim-atps=neutral Received: from relay001.mxroute.com (relay001.mxroute.com [185.234.75.8]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YN3d8czF0ym for ; Sun, 14 Oct 2018 23:47:04 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay001.mxroute.com (Postfix) with ESMTP id EAC433F28E; Sun, 14 Oct 2018 12:46:31 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id B0C083F051; Sun, 14 Oct 2018 12:46:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JCI/YULFL5MInEM+l1rt2AKAWF6iaIgp0WY+kvpGiIQ=; b=M0NIL2s2uhhchU0HkeVuL+/a88 AtzhE3TNGR6US3Wu6ALbsdhNzI+r8lR1o4foCDcmWYKLINSLoOVgq22eHwq29pNFx77zWa6hbBMB3 uwL+93fV5B7+XAa/atwlaefyZ6pWvMuZnU8gtVq5BIuAkakp396Fv4Zn05v1xJ60oFiGlDiQtHiGl xnMFJyxVQrPTJ42ty91FY1uf5gkPS1cdmcQRc7CI5ZcDH3veFrKvJUVLEq8m11LCFmZ0+xqVpwYhN YLMPc3v/mkZlTelZ3UX20o8LFp5qEZM4QLV1QcxB2ur1nFhiXhpj8GKCLFkoymKQjgFqMSIENgwoo Dgh40Cvw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 01/10] fields: Add ColorField Date: Sun, 14 Oct 2018 13:45:32 +0100 Message-Id: <20181014124541.13393-2-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This will allow us to store color codes cleanly in the database. Signed-off-by: Stephen Finucane --- v2: - Change input type of widget to 'color' --- patchwork/fields.py | 25 +++++++++++++++++++++++++ patchwork/forms.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/patchwork/fields.py b/patchwork/fields.py index dd29ea08..45ac8212 100644 --- a/patchwork/fields.py +++ b/patchwork/fields.py @@ -28,3 +28,28 @@ class HashField(models.CharField): def db_type(self, connection=None): return 'char(%d)' % self.n_bytes + + +class ColorField(models.Field): + + description = 'Hex color code' + + def get_internal_type(self): + return "PositiveIntegerField" + + def to_python(self, value): + if isinstance(value, six.string_types) or value is None: + return value + return '#%06x' % value + + def from_db_value(self, value, *args, **kwargs): + return self.to_python(value) + + def get_prep_value(self, value): + return int(value.lstrip('#'), 16) + + def formfield(self, *args, **kwargs): + from patchwork import forms # noqa + + kwargs['form_class'] = forms.ColorField + return super(ColorField, self).formfield(*args, **kwargs) diff --git a/patchwork/forms.py b/patchwork/forms.py index f112dccc..ad696a22 100644 --- a/patchwork/forms.py +++ b/patchwork/forms.py @@ -3,8 +3,11 @@ # # SPDX-License-Identifier: GPL-2.0-or-later +import re + from django.contrib.auth.models import User from django import forms +from django.forms import widgets from django.db.models import Q from django.db.utils import ProgrammingError @@ -200,3 +203,29 @@ class MultiplePatchForm(forms.Form): if commit: instance.save() return instance + + +class ColorInput(widgets.Input): + input_type = 'color' + + +class ColorField(forms.CharField): + + widget = ColorInput + default_error_messages = { + 'invalid': 'Enter a valid colour value: e.g. "#ff0022"', + } + + def clean(self, value): + if not re.match('^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$', value): + raise forms.ValidationError(self.error_messages['invalid']) + + value = int(value.lstrip('#'), 16) + super(ColorField, self).clean(value) + + return value + + def widget_attrs(self, widget): + attrs = super().widget_attrs(widget) + attrs['maxlength'] = 7 + return attrs From patchwork Sun Oct 14 12:45:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1ZN3Qn7z9s8F for ; Sun, 14 Oct 2018 23:47:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="ITp8M2OC"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1ZN1q5fzF3Dt for ; Sun, 14 Oct 2018 23:47:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="ITp8M2OC"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.13; helo=relay013.mxrelay.co; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="ITp8M2OC"; dkim-atps=neutral Received: from relay013.mxrelay.co (relay013.mxrelay.co [185.234.75.13]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YP2P1BzF18l for ; Sun, 14 Oct 2018 23:47:05 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay013.mxrelay.co (Postfix) with ESMTP id 7C1E442DD6; Sun, 14 Oct 2018 12:46:32 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 649503F051; Sun, 14 Oct 2018 12:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7xPLQ28XxTV1ssJnmLV/vIHmzMTmQMFVb2f+EnxXDsA=; b=ITp8M2OCuhRjKqag8A8b8dsPFR VECQKZQGJElLuexEwrOtmsXxjpE1C1IERrIX8LpxOvMJEIL23pfoidaL3mPsRIK5xG8TAvNN39GhJ Y0H7ig9eCBuHl4MrVP1et0ZE9u+1CtkZ3sT3jqjQtihj0dGz5S4hG5uIFpPLfL4hwDHC3m1WmeIeX rWTTjs4+WVFPtnttv2UPo+OJPwMfTtm9xjit6KGAXLOdNyy/CsqW/spB5kuXcaqxtbcHcKfQopRhz HT7G/0/L0UlSkgiPIiGjHHL1aFck8VhTRBGYPzY8vehQrMvKJrEnyuq+XwnayFhE1/0Acn4y+xwPF uqGrBs3Q==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 02/10] models: Add submission labels Date: Sun, 14 Oct 2018 13:45:33 +0100 Message-Id: <20181014124541.13393-3-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Labels are arbitrary bits of metadata attached to a submission. They can be used to signify priority, category, or other similar information. They can also be used to filter patches and identify the ones most interesting to a given user. Labels can be associated with a project to ensure that one project can use a totally different set of labels to another and to, in the future, allow a project administrator to use their own labels. However, they can also be global, which is useful for things that would be common across multiple projects such as "RFC". Signed-off-by: Stephen Finucane --- v2: - Associate labels with cover letters as well as patches - Update migration numbers - Add release note --- patchwork/fixtures/default_labels.xml | 9 +++++ patchwork/migrations/0031_add_labels.py | 39 +++++++++++++++++++ patchwork/models.py | 35 +++++++++++++++++ .../notes/labels-6d0096c7d8505627.yaml | 11 ++++++ 4 files changed, 94 insertions(+) create mode 100644 patchwork/fixtures/default_labels.xml create mode 100644 patchwork/migrations/0031_add_labels.py create mode 100644 releasenotes/notes/labels-6d0096c7d8505627.yaml diff --git a/patchwork/fixtures/default_labels.xml b/patchwork/fixtures/default_labels.xml new file mode 100644 index 00000000..1e1aa705 --- /dev/null +++ b/patchwork/fixtures/default_labels.xml @@ -0,0 +1,9 @@ + + + + + RFC + "RFC" stands for "Request for Comment", which tells maintainers that they should review your patch thoroughly and provide feedback. RFC is typically used when sending feature patches for the first time, or anytime the patch is more than just a simple bug fix. + #EDEDED + + diff --git a/patchwork/migrations/0031_add_labels.py b/patchwork/migrations/0031_add_labels.py new file mode 100644 index 00000000..ba93ecd6 --- /dev/null +++ b/patchwork/migrations/0031_add_labels.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.15 on 2018-09-13 03:49 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import patchwork.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0030_add_submission_covering_index'), + ] + + operations = [ + migrations.CreateModel( + name='Label', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(help_text=b'The label value.', max_length=25)), + ('description', models.TextField(blank=True, help_text=b'A description of what the label is and when it should be applied.', null=True)), + ('color', patchwork.fields.ColorField(help_text=b'The color code to use in the UI.')), + ('project', models.ForeignKey(help_text=b'The project this label is associated with. If unset, this label is global to the instance', null=True, blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='labels', related_query_name='label', to='patchwork.Project')), + ], + options={ + 'ordering': ['name'], + }, + ), + migrations.AddField( + model_name='submission', + name='labels', + field=models.ManyToManyField(to='patchwork.Label'), + ), + migrations.AlterUniqueTogether( + name='label', + unique_together=set([('project', 'name')]), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index a043844d..b6a1fe38 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -18,6 +18,7 @@ from django.urls import reverse from django.utils.encoding import python_2_unicode_compatible from django.utils.functional import cached_property +from patchwork.fields import ColorField from patchwork.fields import HashField from patchwork.hasher import hash_diff @@ -219,6 +220,39 @@ class State(models.Model): ordering = ['ordering'] +@python_2_unicode_compatible +class Label(models.Model): + """Labels for patches. + + Labels are arbitrary bits of metadata attached to a patch. They can + be used to signify priority, category, or other similar information. + They can also be used to filter patches and identify the ones most + interesting to a given user. + """ + project = models.ForeignKey( + Project, related_name='labels', related_query_name='label', null=True, + blank=True, on_delete=models.CASCADE, + help_text='The project this label is associated with. If unset, this ' + 'label is global to the instance') + + name = models.CharField( + max_length=25, + help_text='The label value.') + description = models.TextField( + null=True, blank=True, + help_text='A description of what the label is and when it should be ' + 'applied.') + color = ColorField( + help_text='The color code to use in the UI.') + + def __str__(self): + return self.name + + class Meta: + ordering = ['name'] + unique_together = [('project', 'name')] + + @python_2_unicode_compatible class Tag(models.Model): name = models.CharField(max_length=20) @@ -355,6 +389,7 @@ class Submission(FilenameMixin, EmailMixin, models.Model): # submission metadata name = models.CharField(max_length=255) + labels = models.ManyToManyField(Label) # patchwork metadata diff --git a/releasenotes/notes/labels-6d0096c7d8505627.yaml b/releasenotes/notes/labels-6d0096c7d8505627.yaml new file mode 100644 index 00000000..fdebd6b7 --- /dev/null +++ b/releasenotes/notes/labels-6d0096c7d8505627.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + Add support for patch labels. Labels are a way to organize and prioritize + submissions. You can apply labels to patches and cover letters to signify + priority, category, or any other marker you wish. + + Labels can be either global or tied to the project they are created in. + Labels can have an optional description attached, which will provide a + little insight into the purpose of the label. Labels are completely + customizable and the labels available will vary by instance. From patchwork Sun Oct 14 12:45:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1Zn37MJz9s8F for ; Sun, 14 Oct 2018 23:48:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="PBJmAiCD"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1Zn1ZXlzDrJl for ; Sun, 14 Oct 2018 23:48:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="PBJmAiCD"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.13; helo=relay013.mxrelay.co; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="PBJmAiCD"; dkim-atps=neutral Received: from relay013.mxrelay.co (relay013.mxrelay.co [185.234.75.13]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YP428YzDsRY for ; Sun, 14 Oct 2018 23:47:05 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay013.mxrelay.co (Postfix) with ESMTP id 2A35B42DF0; Sun, 14 Oct 2018 12:46:33 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 08F303F53E; Sun, 14 Oct 2018 12:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9DnNeN5vnmyBvBXU9PYkGGgUU0w/sqbUneB2L0F8jrg=; b=PBJmAiCDa+60ROcWFHp3Z+GesR 6RgateoBVnFU9TOgLOb4djQ2ZenRiCQGq3I+hj0MQDm+WzS926PXkv2fGtBO6FuQwr2+d642+BMOz 29kraCVtWXOLoc1owemcLk46mDK+gNokEQCkp2eDPL0CIZodtT7n7y86m1Fbcozc1nDcqllRpDiIk MpeVCehTH7mv720/Mcx45CYNeegxEO08IUivtXltbNyCxwoZwP5yqClRR1lA7Nstb259/VtBKECz8 DAkyxy5Ie0s3+XwUVo3EBE4wgxASjUg8yGSvsQInOInJuEeMr5YPUw/ROFFSJauSfh6RXnMaY5Wn1 /y8FM+Jw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 03/10] parser: Extract and save labels Date: Sun, 14 Oct 2018 13:45:34 +0100 Message-Id: <20181014124541.13393-4-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Signed-off-by: Stephen Finucane --- patchwork/parser.py | 17 +++++++++++++++++ patchwork/tests/test_parser.py | 16 ++++++++++++++++ patchwork/tests/utils.py | 15 +++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/patchwork/parser.py b/patchwork/parser.py index 2ba1db74..8c5106c9 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -16,12 +16,14 @@ import re from django.contrib.auth.models import User from django.db.utils import IntegrityError +from django.db.models import Q from django.utils import six from patchwork.models import Comment from patchwork.models import CoverLetter from patchwork.models import DelegationRule from patchwork.models import get_default_initial_patch_state +from patchwork.models import Label from patchwork.models import Patch from patchwork.models import Person from patchwork.models import Project @@ -490,6 +492,16 @@ def parse_version(subject, subject_prefixes): return 1 +def parse_labels(subject_prefixes, project): + """Extract labels from subject. + + Args: + subject_prefixes: List of subject prefixes to extract tags from + """ + return Label.objects.filter(Q(project=project) | Q(project=None), + name__in=subject_prefixes) + + def _find_content(mail): """Extract the payload(s) from a mail. @@ -1004,6 +1016,8 @@ def parse_mail(mail, list_id=None): filenames = find_filenames(diff) delegate = find_delegate_by_filename(project, filenames) + labels = parse_labels(prefixes, project) + try: patch = Patch.objects.create( msgid=msgid, @@ -1022,6 +1036,9 @@ def parse_mail(mail, list_id=None): except IntegrityError: raise DuplicateMailError(msgid=msgid) + if labels: + patch.labels.set(labels) + # if we don't have a series marker, we will never have an existing # series to match against. series = None diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index a9df5e35..9a4066fe 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -25,6 +25,7 @@ from patchwork.parser import find_patch_content as find_content from patchwork.parser import find_comment_content from patchwork.parser import find_project from patchwork.parser import find_series +from patchwork.parser import parse_labels from patchwork.parser import parse_mail as _parse_mail from patchwork.parser import parse_pull_request from patchwork.parser import parse_series_marker @@ -33,6 +34,7 @@ from patchwork.parser import split_prefixes from patchwork.parser import subject_check from patchwork.tests import TEST_MAIL_DIR from patchwork.tests import TEST_FUZZ_DIR +from patchwork.tests.utils import create_label from patchwork.tests.utils import create_project from patchwork.tests.utils import create_series from patchwork.tests.utils import create_series_reference @@ -900,6 +902,20 @@ class SubjectTest(TestCase): self.assertEqual(parse_version('Hello, world (v2)', []), 2) self.assertEqual(parse_version('Hello, world (V6)', []), 6) + def test_labels(self): + label = create_label(name='RFC') + + self.assertEqual(list(parse_labels(['RFC'], label.project)), [label]) + self.assertEqual(list(parse_labels(['rfcx'], label.project)), []) + + project = create_project() + + self.assertEqual(list(parse_labels(['RFC'], project)), []) + + label = create_label(name='stuff', project=None) + + self.assertEqual(list(parse_labels(['stuff'], project)), [label]) + class SubjectMatchTest(TestCase): diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py index d280fd69..38452f00 100644 --- a/patchwork/tests/utils.py +++ b/patchwork/tests/utils.py @@ -15,6 +15,7 @@ from patchwork.models import Bundle from patchwork.models import Check from patchwork.models import Comment from patchwork.models import CoverLetter +from patchwork.models import Label from patchwork.models import Patch from patchwork.models import Person from patchwork.models import Project @@ -252,6 +253,20 @@ def create_series_reference(**kwargs): return SeriesReference.objects.create(**values) +def create_label(**kwargs): + """Create a 'Label' object.""" + num = Label.objects.count() + + values = { + 'name': 'label%d' % num, + 'project': create_project() if 'project' not in kwargs else None, + 'color': '#fff', + } + values.update(**kwargs) + + return Label.objects.create(**values) + + def _create_submissions(create_func, count=1, **kwargs): """Create 'count' Submission-based objects. From patchwork Sun Oct 14 12:45:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1bC5qztz9s8F for ; Sun, 14 Oct 2018 23:48:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BF86LLlS"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1bC3rFgzF35J for ; Sun, 14 Oct 2018 23:48:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BF86LLlS"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.13; helo=relay013.mxrelay.co; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BF86LLlS"; dkim-atps=neutral Received: from relay013.mxrelay.co (relay013.mxrelay.co [185.234.75.13]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YQ52fnzDsRY for ; Sun, 14 Oct 2018 23:47:06 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay013.mxrelay.co (Postfix) with ESMTP id 2EE9142DF8; Sun, 14 Oct 2018 12:46:34 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id F18E83F051; Sun, 14 Oct 2018 12:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yt42b0iHbDkHNY3QVZWbvpYCp6p0WoXM3iQs4Ehr6PY=; b=BF86LLlSxGjtdWhlkd00GOpjqA +9TM6sFOqb8NC45sm/zBqehPKFn5D2cYfzC5kOP6AyWAtVp89WDRf3rk5iAThJFlLyhOqMcV6BLYT MskwMSJQ2dIhb7ToKRTBj4lIaqQYtYih7Ox4O3/G6x5aXcIKEQxIyvg2aEId/3DLMAbUxhYIQWx7a gpPUR3Mggq5p2mr8JELiPxTIiKj72YQ+HtKNY54bfH7I03wCkCXISN+qfexls4KEfRx7rdia1y1lt 8mnmilcOzFfLdfDidRdL9jHS/o5iQ/wQbKvXhpOizGJh5jtMu+YRhKQ2VveDO5QQytcu8nCenIlNm Ca5tlluw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 04/10] parser: Remove matching label from subject prefixes Date: Sun, 14 Oct 2018 13:45:35 +0100 Message-Id: <20181014124541.13393-5-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Extend the parser to strip the label from the list of prefixes. This means we don't duplicate things twice in the UI. Signed-off-by: Stephen Finucane --- I'm not 100% sure about this which is why I've kept it separate. On one hand, it doesn't make sense to duplicate things like this. On another, not every label is something we'd want to parse from the subject line and it makes prefixes in the UI kind of useless. Perhaps we should add a 'Label.parseable' flag? --- patchwork/parser.py | 9 +++++++-- patchwork/tests/test_parser.py | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/patchwork/parser.py b/patchwork/parser.py index 8c5106c9..9393a062 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -498,8 +498,13 @@ def parse_labels(subject_prefixes, project): Args: subject_prefixes: List of subject prefixes to extract tags from """ - return Label.objects.filter(Q(project=project) | Q(project=None), - name__in=subject_prefixes) + labels = Label.objects.filter(Q(project=project) | Q(project=None), + name__in=subject_prefixes) + for label in labels: + if label.name in subject_prefixes: + subject_prefixes.remove(label.name) + + return labels def _find_content(mail): diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index 9a4066fe..39f40d56 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -905,16 +905,23 @@ class SubjectTest(TestCase): def test_labels(self): label = create_label(name='RFC') - self.assertEqual(list(parse_labels(['RFC'], label.project)), [label]) - self.assertEqual(list(parse_labels(['rfcx'], label.project)), []) + prefixes = ['RFC'] + self.assertEqual(list(parse_labels(prefixes, label.project)), [label]) + self.assertEqual(prefixes, []) - project = create_project() + prefixes = ['rfcx'] + self.assertEqual(list(parse_labels(prefixes, label.project)), []) + self.assertEqual(prefixes, ['rfcx']) - self.assertEqual(list(parse_labels(['RFC'], project)), []) + project = create_project() + prefixes = ['RFC'] + self.assertEqual(list(parse_labels(prefixes, project)), []) + self.assertEqual(prefixes, ['RFC']) label = create_label(name='stuff', project=None) - - self.assertEqual(list(parse_labels(['stuff'], project)), [label]) + prefixes = ['stuff'] + self.assertEqual(list(parse_labels(prefixes, project)), [label]) + self.assertEqual(prefixes, []]) class SubjectMatchTest(TestCase): From patchwork Sun Oct 14 12:45:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1bc16hbz9s8F for ; Sun, 14 Oct 2018 23:49:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="nSaGAa0U"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1bb6HnlzF3B0 for ; Sun, 14 Oct 2018 23:48:59 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="nSaGAa0U"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.8; helo=relay001.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="nSaGAa0U"; dkim-atps=neutral Received: from relay001.mxroute.com (relay001.mxroute.com [185.234.75.8]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YQ5jLjzF0ym for ; Sun, 14 Oct 2018 23:47:06 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay001.mxroute.com (Postfix) with ESMTP id 4F4393F4FD; Sun, 14 Oct 2018 12:46:34 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 376B33F53E; Sun, 14 Oct 2018 12:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=DX3Why4GA9FBxWF7VNvi96MhKyTHZLcRPKN1Giuvaro=; b=nSaGAa0Ul0v+v7Uv6cmpoMnrZK IGmH2s5lkd13tdAwFnJxmf3rXkci3PwXE5LgGjNZ/2764v2fXdwKFyijsVek+bdvPdfg+4SQwPvuD bv93a+AVzIfx+DPhic70fonksq/g+KItKiAB0Px9g03MN0bVIb4d6xWJN1v/RWEEHk2uc8jzDTYLC ECI+mUETTH4ps+BIUHlTIYsFwo9B3XBH6dceTlwrnXHp32U2xdaMP2hCrSj6McvoUid0G0Q97po6k N4jUbe54sBGac8BCymYY3YZ0cPCXKJ7eMnI+WNYM8WBPhWPNrUcV9AsVF880dmhNzbHmSAiKPQ56z YOTIqIbg==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 05/10] admin: Group register calls at bottom Date: Sun, 14 Oct 2018 13:45:36 +0100 Message-Id: <20181014124541.13393-6-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This seems more intuitive. Signed-off-by: Stephen Finucane --- patchwork/admin.py | 48 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/patchwork/admin.py b/patchwork/admin.py index f12b3387..0e9ccfa7 100644 --- a/patchwork/admin.py +++ b/patchwork/admin.py @@ -33,10 +33,6 @@ class UserAdmin(BaseUserAdmin): inlines = (UserProfileInline, ) -admin.site.unregister(User) -admin.site.register(User, UserAdmin) - - class DelegationRuleInline(admin.TabularInline): model = DelegationRule fields = ('path', 'user', 'priority') @@ -49,9 +45,6 @@ class ProjectAdmin(admin.ModelAdmin): ] -admin.site.register(Project, ProjectAdmin) - - class PersonAdmin(admin.ModelAdmin): list_display = ('__str__', 'has_account') search_fields = ('name', 'email') @@ -64,16 +57,10 @@ class PersonAdmin(admin.ModelAdmin): has_account.short_description = 'Account' -admin.site.register(Person, PersonAdmin) - - class StateAdmin(admin.ModelAdmin): list_display = ('name', 'action_required') -admin.site.register(State, StateAdmin) - - class SubmissionAdmin(admin.ModelAdmin): list_display = ('name', 'submitter', 'project', 'date') list_filter = ('project', ) @@ -81,10 +68,6 @@ class SubmissionAdmin(admin.ModelAdmin): date_hierarchy = 'date' -admin.site.register(Submission, SubmissionAdmin) -admin.site.register(CoverLetter, SubmissionAdmin) - - class PatchAdmin(admin.ModelAdmin): list_display = ('name', 'submitter', 'project', 'state', 'date', 'archived', 'is_pull_request') @@ -101,18 +84,12 @@ class PatchAdmin(admin.ModelAdmin): is_pull_request.short_description = 'Pull' -admin.site.register(Patch, PatchAdmin) - - class CommentAdmin(admin.ModelAdmin): list_display = ('submission', 'submitter', 'date') search_fields = ('submission__name', 'submitter__name', 'submitter__email') date_hierarchy = 'date' -admin.site.register(Comment, CommentAdmin) - - class PatchInline(admin.StackedInline): model = Series.patches.through extra = 0 @@ -135,16 +112,10 @@ class SeriesAdmin(admin.ModelAdmin): return qs.prefetch_related('patches',) -admin.site.register(Series, SeriesAdmin) - - class SeriesReferenceAdmin(admin.ModelAdmin): model = SeriesReference -admin.site.register(SeriesReference, SeriesReferenceAdmin) - - class CheckAdmin(admin.ModelAdmin): list_display = ('patch', 'user', 'state', 'target_url', 'description', 'context') @@ -153,20 +124,27 @@ class CheckAdmin(admin.ModelAdmin): date_hierarchy = 'date' -admin.site.register(Check, CheckAdmin) - - class BundleAdmin(admin.ModelAdmin): list_display = ('name', 'owner', 'project', 'public') list_filter = ('public', 'project') search_fields = ('name', 'owner') -admin.site.register(Bundle, BundleAdmin) - - class TagAdmin(admin.ModelAdmin): list_display = ('name',) +admin.site.unregister(User) +admin.site.register(User, UserAdmin) +admin.site.register(Project, ProjectAdmin) +admin.site.register(Person, PersonAdmin) +admin.site.register(State, StateAdmin) +admin.site.register(Submission, SubmissionAdmin) +admin.site.register(CoverLetter, SubmissionAdmin) +admin.site.register(Patch, PatchAdmin) +admin.site.register(Comment, CommentAdmin) +admin.site.register(Series, SeriesAdmin) +admin.site.register(SeriesReference, SeriesReferenceAdmin) +admin.site.register(Check, CheckAdmin) +admin.site.register(Bundle, BundleAdmin) admin.site.register(Tag, TagAdmin) From patchwork Sun Oct 14 12:45:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1c03BpPz9s8F for ; Sun, 14 Oct 2018 23:49:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="kDMo00o7"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1c01kk3zF3Bd for ; Sun, 14 Oct 2018 23:49:20 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="kDMo00o7"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.2; helo=relay-direct2.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="kDMo00o7"; dkim-atps=neutral Received: from relay-direct2.mxroute.com (relay-direct2.mxroute.com [185.234.75.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YR3qF1zDsRY for ; Sun, 14 Oct 2018 23:47:07 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct2.mxroute.com (Postfix) with ESMTP id 2EC193F0E0; Sun, 14 Oct 2018 12:46:35 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 139EE3F53E; Sun, 14 Oct 2018 12:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OqOD0xw3EcZRQD9FHimioLUbg/vxgawV/LPw/CEHJow=; b=kDMo00o7JF9kcUmqUbogSS5cZG 8PG4o2k/TuOuK6L0leZhkGyD/zIgJo7RxmyQbJE1v47nSEUAMo/8daBLOjEB74DGAbeMzA07dB/oJ qoMmUFuCJ5TAzs2JyBES9lHkjMyzBgJgJ7r9AF76vnKLtvBVLpkF5YrHNAJAhcSRSp+QPldHDovwy AS8Td5/AOUWSSdkPOn0hVvVm5UXHlzLP9N5Axi89/jZQokaClDkwnFpSWAlbAaPkmJ01NYVkmDy9Y OjfeeXg6mqTKXw1rPwBWN3kmigWD80VKH/f9ML/xNQJ71zYNYgqeTt9HOYDS211fOArWi0e8VDU02 TfplxtSQ==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 06/10] admin: Add label views Date: Sun, 14 Oct 2018 13:45:37 +0100 Message-Id: <20181014124541.13393-7-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" There are two added: a general labels view that includes both project and non-project labels, and an inline labels view that's part of the project. Signed-off-by: Stephen Finucane --- v2: - Only show labels that are not associated with a project for the label admin view - Add 'project' to list view --- patchwork/admin.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/patchwork/admin.py b/patchwork/admin.py index 0e9ccfa7..31103106 100644 --- a/patchwork/admin.py +++ b/patchwork/admin.py @@ -12,6 +12,7 @@ from patchwork.models import Check from patchwork.models import Comment from patchwork.models import CoverLetter from patchwork.models import DelegationRule +from patchwork.models import Label from patchwork.models import Patch from patchwork.models import Person from patchwork.models import Project @@ -38,10 +39,16 @@ class DelegationRuleInline(admin.TabularInline): fields = ('path', 'user', 'priority') +class LabelInline(admin.TabularInline): + model = Label + fields = ('name', 'description', 'color') + + class ProjectAdmin(admin.ModelAdmin): list_display = ('name', 'linkname', 'listid', 'listemail') inlines = [ DelegationRuleInline, + LabelInline, ] @@ -71,6 +78,7 @@ class SubmissionAdmin(admin.ModelAdmin): class PatchAdmin(admin.ModelAdmin): list_display = ('name', 'submitter', 'project', 'state', 'date', 'archived', 'is_pull_request') + readonly_fields = ('labels',) list_filter = ('project', 'state', 'archived') list_select_related = ('submitter', 'project', 'state') search_fields = ('name', 'submitter__name', 'submitter__email') @@ -134,6 +142,14 @@ class TagAdmin(admin.ModelAdmin): list_display = ('name',) +class LabelAdmin(admin.ModelAdmin): + list_display = ('name', 'color') + + def get_queryset(self, request): + qs = super(LabelAdmin, self).get_queryset(request) + return qs.filter(project=None) + + admin.site.unregister(User) admin.site.register(User, UserAdmin) admin.site.register(Project, ProjectAdmin) @@ -148,3 +164,4 @@ admin.site.register(SeriesReference, SeriesReferenceAdmin) admin.site.register(Check, CheckAdmin) admin.site.register(Bundle, BundleAdmin) admin.site.register(Tag, TagAdmin) +admin.site.register(Label, LabelAdmin) From patchwork Sun Oct 14 12:45:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1cT42gRz9s8F for ; Sun, 14 Oct 2018 23:49:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BhCSLzGN"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1cT2bVgzF2Dx for ; Sun, 14 Oct 2018 23:49:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BhCSLzGN"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.2; helo=relay-direct2.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BhCSLzGN"; dkim-atps=neutral Received: from relay-direct2.mxroute.com (relay-direct2.mxroute.com [185.234.75.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YT2gpYzF2Dx for ; Sun, 14 Oct 2018 23:47:09 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct2.mxroute.com (Postfix) with ESMTP id 73E263F348; Sun, 14 Oct 2018 12:46:36 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 360693F051; Sun, 14 Oct 2018 12:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xgu22hKpDbBPCIjPsC/E/5FcZ83L7q+np9PlfbXNPiI=; b=BhCSLzGNojs7f9vFWh79MtkfO+ ON87QBzFwFbwJdZMLhjkQwgimB5PDXfySELKYmdLw6cEoJEGdisXVYsdjDT51fvJCrDkfiIOgMXro 43u9mb8Ysgwrz6SMLpDIRDfM4MXAm9JXsOq6XYaoB9MfTyqp8ZUWzZzh83rBfGadOjjArNSMWj3xn nOYusMCQBV6ovNM+hmJBSmnbo/P6+bmiNssBZIYVIoo1s+qgu1HJzeKq9j97UiqOz9qyzVQmgsrRf bsxd5WRXZEgMEY6t4710/YVUtiGRcEqjT/FSFJe5yLtIVuxs9A/7U2naUxGy+mA7QCvhW2RnpSzZB 4KzBXDcQ==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 07/10] views: Populate 'project' attribute of PatchForm Date: Sun, 14 Oct 2018 13:45:38 +0100 Message-Id: <20181014124541.13393-8-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This is required to ensure we can filter delegates by project. If we don't do this, our