mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 12:49:01 +02:00
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>
This commit is contained in:
parent
2eedc87399
commit
5db8759b4f
24
rrs/admin.py
24
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user