Commit 8dc52294 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler Committed by Damien Lespiau
Browse files

models: Add a method to get a series for a patch



We had find_series_for_patch() in two separate places doing exactely the
same thing.

Let's move the logic to the model itself, and get rid of the clones.
Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent d27e62dc
......@@ -21,18 +21,10 @@ from email.parser import HeaderParser
import sys
from django.core.management.base import BaseCommand
from patchwork.models import Patch, Project, SeriesRevisionPatch
from patchwork.models import Patch, Project
from patchwork.bin.parsemail import find_project
def find_series_for_patch(patch):
try:
revision = SeriesRevisionPatch.objects.filter(patch=patch)[0].revision
return revision.series
except:
return None
class Command(BaseCommand):
help = 'Reassign project of patches and series when ' \
'subject_prefix_tags changes'
......@@ -65,7 +57,7 @@ class Command(BaseCommand):
patch.project = new_project
patch.save()
series = find_series_for_patch(patch)
series = patch.series()
if not series:
continue
series.project = new_project
......
......@@ -334,6 +334,13 @@ class Patch(models.Model):
answers"""
return Comment.objects.filter(patch=self)
def series(self):
try:
rev = SeriesRevisionPatch.objects.filter(patch=self)[0].revision
return rev.series
except:
return None
def _set_tag(self, tag, count):
if count == 0:
self.patchtag_set.filter(tag=tag).delete()
......@@ -821,14 +828,6 @@ class PatchChangeNotification(models.Model):
orig_state = models.ForeignKey(State)
def find_series_for_patch(patch):
try:
revision = SeriesRevisionPatch.objects.filter(patch=patch)[0].revision
return revision.series
except:
return None
def _patch_change_log_event(old_patch, new_patch):
# If state changed, log the event
event_state_change = Event.objects.get(name='patch-state-change')
......@@ -838,7 +837,7 @@ def _patch_change_log_event(old_patch, new_patch):
# Do not log patch-state-change events for Patches that are not part of a
# Series (ie patches older than the introduction of Series)
series = find_series_for_patch(old_patch)
series = old_patch.series()
if series:
log = EventLog(event=event_state_change,
user=curr_user,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment