forms: clear out comparison recipe/layerbranch if status doesn't accept them

If the cover status for a comparison recipe is Unknown, Not available,
or Distro-specific, then we disable the recipe and layerbranch fields in
the form (using Javascript), however the form could still be saved and
any existing values would persist. Clear out the fields upon saving if
they are set under these circumstances.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-06-29 11:08:21 +12:00
parent fca74f3ac3
commit a40a5350e4

View File

@ -166,6 +166,17 @@ class ClassicRecipeForm(forms.ModelForm):
model = ClassicRecipe model = ClassicRecipe
fields = ('cover_layerbranch', 'cover_pn', 'cover_status', 'cover_verified', 'cover_comment', 'classic_category') fields = ('cover_layerbranch', 'cover_pn', 'cover_status', 'cover_verified', 'cover_comment', 'classic_category')
def clean(self):
cleaned_data = super(ClassicRecipeForm, self).clean()
cover_pn = cleaned_data.get('cover_pn')
cover_layerbranch = cleaned_data.get('cover_layerbranch')
if cleaned_data.get('cover_status') in ['U', 'N', 'S']:
if cover_layerbranch:
cleaned_data['cover_layerbranch'] = None
if cover_pn:
cleaned_data['cover_pn'] = ''
return cleaned_data
class AdvancedRecipeSearchForm(forms.Form): class AdvancedRecipeSearchForm(forms.Form):
FIELD_CHOICES = ( FIELD_CHOICES = (