From patchwork Wed Sep 18 06:17:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1163767 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Y8yJ352tz9sNw for ; Wed, 18 Sep 2019 16:21:44 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="Jv0cQqvd"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46Y8yJ1T9jzF4TM for ; Wed, 18 Sep 2019 16:21:44 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::431; helo=mail-pf1-x431.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="Jv0cQqvd"; dkim-atps=neutral Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46Y8vx361rzF4Cp for ; Wed, 18 Sep 2019 16:19:41 +1000 (AEST) Received: by mail-pf1-x431.google.com with SMTP id 205so3676686pfw.2 for ; Tue, 17 Sep 2019 23:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N/ZOdYdpvZxK4n8AU3Dh4Gvk15+h4IeM3wBb3FDfaec=; b=Jv0cQqvdvSRgextdRxDwo/w94x+kuz2bGVpGqqwqtD//BvsqE6tzb/5s3MRHCDMUEL J4ZEAt7qFbryjitmLdAlZ2ePLSorwhe8LsoqeU3cAKVaAj1WV+sKtNlRJN2AuHX/ftze p7Eix/PFJw6GfMiBooPdhA7jPAj/UNNgJoqhg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N/ZOdYdpvZxK4n8AU3Dh4Gvk15+h4IeM3wBb3FDfaec=; b=o8F4lIkceAG52hNOldEp7W3XysbMonZDPF6yeImwk0PM8BT1RNVufO/iByUuuXfs5+ SbdWMZ1onpbUgyNJ2hm51ztRhHO7/ZgxMh7dgbk9EJECI11l7mEnVHNaG7iLVMSPsZFb bGJeSyp/vwF7I/2Hn05B1hlcKj4/+r6bQkzxKcWa0pNHFkeHddvGeYWLXQ1RtzhHBS7j lpJsBFigE6xkkA7l31tWwG98bT2TRXdd2jg4u3mzwikritHGyaMUFdav8NqXH6NgY0i3 hlrSRAZRhgPbicV1JIkfC1AxOKK+j18L7X7mI5cfmbBmgHM2I5i0KWpRq/YU0EiwLCe4 cQGQ== X-Gm-Message-State: APjAAAV+CfyB09LZK5z+19p3R6Ubq2IAXOM/MslRbY9fD4byjx53iCc4 7/N9g6FYWCJPx5WC0DJDqf3NuklPSrU= X-Google-Smtp-Source: APXvYqxJ8qXqu6FAAjahvVlHbVzwZ1eOC77+kDXSrE8Zkjmol1aIO7Pl+LMi+7C3q/3thZRyY+VciQ== X-Received: by 2002:a17:90a:3acf:: with SMTP id b73mr2032163pjc.88.1568787577515; Tue, 17 Sep 2019 23:19:37 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id bx18sm1063326pjb.26.2019.09.17.23.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2019 23:19:36 -0700 (PDT) From: Daniel Axtens To: patchwork@lists.ozlabs.org Subject: [PATCH 6/6] Burninate CoverLetter Date: Wed, 18 Sep 2019 16:17:31 +1000 Message-Id: <20190918061731.19142-7-dja@axtens.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190918061731.19142-1-dja@axtens.net> References: <20190918061731.19142-1-dja@axtens.net> MIME-Version: 1.0 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: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" A patch must have a diff or a pull_url. If a Submission does not have a diff or a pull_url, it must be a CoverLetter. This is enough to get rid of the CoverLetter model. We do have some work to do around the interactions with Series, which is currently super ugly, but it's good enough for a proof of concept. Signed-off-by: Daniel Axtens --- patchwork/admin.py | 3 -- patchwork/api/cover.py | 16 +++++----- patchwork/api/embedded.py | 2 +- patchwork/api/filters.py | 13 +++++++-- patchwork/management/commands/parsearchive.py | 4 +-- patchwork/migrations/0041_drop_coverletter.py | 29 +++++++++++++++++++ patchwork/models.py | 19 +++++------- patchwork/parser.py | 9 +++--- patchwork/signals.py | 4 +-- patchwork/templates/patchwork/submission.html | 10 +++---- patchwork/tests/api/test_cover.py | 5 ++-- patchwork/tests/test_series.py | 14 ++++----- patchwork/tests/utils.py | 6 ++-- patchwork/views/cover.py | 25 +++++++++++----- patchwork/views/patch.py | 1 + 15 files changed, 100 insertions(+), 60 deletions(-) create mode 100644 patchwork/migrations/0041_drop_coverletter.py diff --git a/patchwork/admin.py b/patchwork/admin.py index f9a94c6f5c07..48fe43b93c99 100644 --- a/patchwork/admin.py +++ b/patchwork/admin.py @@ -11,7 +11,6 @@ from django.db.models import Prefetch from patchwork.models import Bundle from patchwork.models import Check from patchwork.models import Comment -from patchwork.models import CoverLetter from patchwork.models import DelegationRule from patchwork.models import Patch from patchwork.models import Person @@ -83,8 +82,6 @@ class SubmissionAdmin(admin.ModelAdmin): admin.site.register(Submission, SubmissionAdmin) -admin.site.register(CoverLetter, SubmissionAdmin) - class PatchAdmin(admin.ModelAdmin): list_display = ('name', 'submitter', 'project', 'state', 'date', diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py index caf9a386efa5..8eb65f8cb942 100644 --- a/patchwork/api/cover.py +++ b/patchwork/api/cover.py @@ -15,7 +15,7 @@ from patchwork.api.filters import CoverLetterFilterSet from patchwork.api.embedded import PersonSerializer from patchwork.api.embedded import ProjectSerializer from patchwork.api.embedded import SeriesSerializer -from patchwork.models import CoverLetter +from patchwork.models import Submission class CoverLetterListSerializer(BaseHyperlinkedModelSerializer): @@ -24,7 +24,7 @@ class CoverLetterListSerializer(BaseHyperlinkedModelSerializer): project = ProjectSerializer(read_only=True) submitter = PersonSerializer(read_only=True) mbox = SerializerMethodField() - series = SeriesSerializer(read_only=True) + series = SeriesSerializer(source='cl_series', read_only=True) comments = SerializerMethodField() def get_web_url(self, instance): @@ -49,7 +49,7 @@ class CoverLetterListSerializer(BaseHyperlinkedModelSerializer): return data class Meta: - model = CoverLetter + model = Submission fields = ('id', 'url', 'web_url', 'project', 'msgid', 'list_archive_url', 'date', 'name', 'submitter', 'mbox', 'series', 'comments') @@ -82,7 +82,7 @@ class CoverLetterDetailSerializer(CoverLetterListSerializer): return headers class Meta: - model = CoverLetter + model = Submission fields = CoverLetterListSerializer.Meta.fields + ( 'headers', 'content') read_only_fields = fields @@ -100,8 +100,8 @@ class CoverLetterList(ListAPIView): ordering = 'id' def get_queryset(self): - return CoverLetter.objects.all()\ - .select_related('project', 'submitter', 'series')\ + return Submission.objects.filter(new_diff__isnull=True, new_pull_url__isnull=True)\ + .select_related('project', 'submitter', 'cl_series')\ .defer('content', 'headers') @@ -111,5 +111,5 @@ class CoverLetterDetail(RetrieveAPIView): serializer_class = CoverLetterDetailSerializer def get_queryset(self): - return CoverLetter.objects.all()\ - .select_related('project', 'submitter', 'series') + return Submission.objects.filter(new_diff__isnull=True, new_pull_url__isnull=True)\ + .select_related('project', 'submitter', 'cl_series') diff --git a/patchwork/api/embedded.py b/patchwork/api/embedded.py index de4f31165ee7..a0196128bad4 100644 --- a/patchwork/api/embedded.py +++ b/patchwork/api/embedded.py @@ -107,7 +107,7 @@ class CoverLetterSerializer(SerializedRelatedField): class _Serializer(MboxMixin, WebURLMixin, BaseHyperlinkedModelSerializer): class Meta: - model = models.CoverLetter + model = models.Submission fields = ('id', 'url', 'web_url', 'msgid', 'list_archive_url', 'date', 'name', 'mbox') read_only_fields = fields diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py index 37aca82d9ab2..4690fcab7479 100644 --- a/patchwork/api/filters.py +++ b/patchwork/api/filters.py @@ -15,13 +15,13 @@ from django.forms.widgets import MultipleHiddenInput from patchwork.compat import NAME_FIELD from patchwork.models import Bundle from patchwork.models import Check -from patchwork.models import CoverLetter from patchwork.models import Event from patchwork.models import Patch from patchwork.models import Person from patchwork.models import Project from patchwork.models import Series from patchwork.models import State +from patchwork.models import Submission # custom fields, filters @@ -161,8 +161,13 @@ class CoverLetterFilterSet(TimestampMixin, FilterSet): widget=MultipleHiddenInput) submitter = PersonFilter(queryset=Person.objects.all()) + @property + def qs(self): + parent = super(CoverLetterFilterSet, self).qs + return parent.filter(new_diff__isnull=True, new_pull_url__isnull=True) + class Meta: - model = CoverLetter + model = Submission fields = ('project', 'series', 'submitter') @@ -191,6 +196,8 @@ class CheckFilterSet(TimestampMixin, FilterSet): model = Check fields = ('user', 'state', 'context') +def get_coverletter_qs(request): + return Submission.objects.all().filter(new_diff__isnull=True, new_pull_url__isnull=True) class EventFilterSet(TimestampMixin, FilterSet): @@ -203,7 +210,7 @@ class EventFilterSet(TimestampMixin, FilterSet): widget=MultipleHiddenInput) patch = BaseFilter(queryset=Patch.objects.all(), widget=MultipleHiddenInput) - cover = BaseFilter(queryset=CoverLetter.objects.all(), + cover = BaseFilter(queryset=get_coverletter_qs, widget=MultipleHiddenInput) class Meta: diff --git a/patchwork/management/commands/parsearchive.py b/patchwork/management/commands/parsearchive.py index b7f1ea7313c2..39c640ccee8b 100644 --- a/patchwork/management/commands/parsearchive.py +++ b/patchwork/management/commands/parsearchive.py @@ -32,7 +32,7 @@ class Command(BaseCommand): def handle(self, *args, **options): results = { models.Patch: 0, - models.CoverLetter: 0, + models.Submission: 0, models.Comment: 0, } duplicates = 0 @@ -118,7 +118,7 @@ class Command(BaseCommand): ' %(errors)4d errors\n' 'Total: %(new)s new entries' % { 'total': count, - 'covers': results[models.CoverLetter], + 'covers': results[models.Submission], 'patches': results[models.Patch], 'comments': results[models.Comment], 'duplicates': duplicates, diff --git a/patchwork/migrations/0041_drop_coverletter.py b/patchwork/migrations/0041_drop_coverletter.py new file mode 100644 index 000000000000..d504676fd7fc --- /dev/null +++ b/patchwork/migrations/0041_drop_coverletter.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.24 on 2019-09-17 17:56 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0040_drop_old_diff_pull_url'), + ] + + operations = [ + migrations.AlterField( + model_name='event', + name='cover', + field=models.ForeignKey(blank=True, help_text=b'The cover letter that this event was created for.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='patchwork.Submission'), + ), + migrations.AlterField( + model_name='series', + name='cover_letter', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='cl_series', to='patchwork.Submission'), + ), + migrations.DeleteModel( + name='CoverLetter', + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index a96018004f75..4b6466614fd3 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -389,6 +389,12 @@ class Submission(FilenameMixin, EmailMixin, models.Model): def __str__(self): return self.name + def get_absolute_url(self): + return reverse('cover-detail', kwargs={'cover_id': self.id}) + + def get_mbox_url(self): + return reverse('cover-mbox', kwargs={'cover_id': self.id}) + class Meta: ordering = ['date'] unique_together = [('msgid', 'project')] @@ -402,15 +408,6 @@ class Submission(FilenameMixin, EmailMixin, models.Model): ] -class CoverLetter(Submission): - - def get_absolute_url(self): - return reverse('cover-detail', kwargs={'cover_id': self.id}) - - def get_mbox_url(self): - return reverse('cover-mbox', kwargs={'cover_id': self.id}) - - @python_2_unicode_compatible class Patch(Submission): # patch metadata @@ -739,7 +736,7 @@ class Series(FilenameMixin, models.Model): blank=True, on_delete=models.CASCADE) # content - cover_letter = models.OneToOneField(CoverLetter, related_name='series', + cover_letter = models.OneToOneField(Submission, related_name='cl_series', null=True, on_delete=models.CASCADE) @@ -1030,7 +1027,7 @@ class Event(models.Model): on_delete=models.CASCADE, help_text='The series that this event was created for.') cover = models.ForeignKey( - CoverLetter, related_name='+', null=True, blank=True, + Submission, related_name='+', null=True, blank=True, on_delete=models.CASCADE, help_text='The cover letter that this event was created for.') diff --git a/patchwork/parser.py b/patchwork/parser.py index 7dc66bc05a5b..a122839f3f73 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -19,7 +19,6 @@ from django.db.utils import IntegrityError 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 Patch @@ -1088,11 +1087,11 @@ def parse_mail(mail, list_id=None): if not is_comment: if not refs == []: try: - CoverLetter.objects.all().get(name=name) - except CoverLetter.DoesNotExist: + Submission.objects.get(name=name, new_diff__isnull=True, new_pull_url__isnull=True) + except Submission.DoesNotExist: # if no match, this is a new cover letter is_cover_letter = True - except CoverLetter.MultipleObjectsReturned: + except Submission.MultipleObjectsReturned: # if multiple cover letters are found, just ignore pass else: @@ -1135,7 +1134,7 @@ def parse_mail(mail, list_id=None): " in project %s!" % (msgid, project.name)) try: - cover_letter = CoverLetter.objects.create( + cover_letter = Submission.objects.create( msgid=msgid, project=project, name=name[:255], diff --git a/patchwork/signals.py b/patchwork/signals.py index 666199b68161..bbfdc0106fd7 100644 --- a/patchwork/signals.py +++ b/patchwork/signals.py @@ -10,11 +10,11 @@ from django.db.models.signals import pre_save from django.dispatch import receiver from patchwork.models import Check -from patchwork.models import CoverLetter from patchwork.models import Event from patchwork.models import Patch from patchwork.models import PatchChangeNotification from patchwork.models import Series +from patchwork.models import Submission @receiver(pre_save, sender=Patch) @@ -54,7 +54,7 @@ def patch_change_callback(sender, instance, raw, **kwargs): notification.save() -@receiver(post_save, sender=CoverLetter) +@receiver(post_save, sender=Submission) def create_cover_created_event(sender, instance, created, raw, **kwargs): def create_event(cover): diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index e79dd92497a4..c4175a30e9c5 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -68,12 +68,12 @@ function toggle_div(link_id, headers_id) -{% if submission.series %} +{% if series %} Series - - {{ submission.series }} + + {{ series }} @@ -85,7 +85,7 @@ function toggle_div(link_id, headers_id) >show