summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2018-04-18 09:43:41 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2018-05-04 23:57:53 +1200
commit5db8759b4fb34fe5fba88f962a40ce0f92c8152a (patch)
treebca75e9ae00613d9e19349cc1f33bb8888ae9e83
parent2eedc873990a5571cbe98b525118d243bd313012 (diff)
downloadopenembedded-core-contrib-5db8759b4fb34fe5fba88f962a40ce0f92c8152a.tar.gz
openembedded-core-contrib-5db8759b4fb34fe5fba88f962a40ce0f92c8152a.tar.bz2
openembedded-core-contrib-5db8759b4fb34fe5fba88f962a40ce0f92c8152a.zip
rrs: validate that a layerbranch is only part of one plan
The processing code can't currently handle if a layerbranch is part of more than one plan, so disallow that. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--rrs/admin.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/rrs/admin.py b/rrs/admin.py
index 0831a9001d..682a5a6c04 100644
--- a/rrs/admin.py
+++ b/rrs/admin.py
@@ -9,6 +9,7 @@ from django.utils.functional import curry
from django.contrib import admin
from django.contrib.admin import DateFieldListFilter
from django.forms.models import BaseInlineFormSet
+from django.core.exceptions import ValidationError
from rrs.models import Release, Milestone, Maintainer, RecipeMaintainerHistory, \
RecipeMaintainer, RecipeDistro, RecipeUpgrade, RecipeUpstream, \
@@ -41,6 +42,29 @@ class MaintenancePlanLayerBranchFormSet(BaseInlineFormSet):
form.fields['python3_environment'].initial = py3env
return form
+ def clean(self):
+ super(MaintenancePlanLayerBranchFormSet, self).clean()
+ total_checked = 0
+
+ for form in self.forms:
+ if not form.is_valid():
+ return
+ if form.cleaned_data and not form.cleaned_data.get('DELETE'):
+ layerbranch = form.cleaned_data['layerbranch']
+ if not layerbranch:
+ raise ValidationError('You must select a layerbranch')
+ # Only allow one plan per layer
+ # NOTE: This restriction is in place because we don't have enough safeguards in the
+ # processing code to avoid processing a layer multiple times if it's part of
+ # more than one plan, and there may be other challenges. For now, just keep it simple.
+ mplayerbranches = layerbranch.maintenanceplanlayerbranch_set.all()
+ if form.instance.pk is not None:
+ mplayerbranches = mplayerbranches.exclude(id=form.instance.id)
+ if mplayerbranches.exists():
+ raise ValidationError('A layer branch can only be part of one maintenance plan - layer branch %s is already part of maintenance plan %s' % (layerbranch, mplayerbranches.first().plan.name))
+ total_checked += 1
+
+
class MaintenancePlanLayerBranchInline(admin.StackedInline):
model = MaintenancePlanLayerBranch
formset = MaintenancePlanLayerBranchFormSet