Allow blanking out field values in bulk change

If you're moving a short description value from DESCRIPTION to SUMMARY
then part of that is setting DESCRIPTION to blank, however that wasn't
possible - the code was assuming that a null value meant "keep the
original value". Change the logic so that the value in the bulk change
object is always set and is compared to the original value to see if it
is different. This provides less safety against bulk change data going
stale in the face of the metadata being updated, but without using an
additional "magic" field value that's the price we have to pay, and it's
unlikely to bother too many people I would imagine.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2016-05-19 08:51:24 +12:00
parent b80833e1c9
commit 48c0839482
4 changed files with 22 additions and 37 deletions

View File

@ -97,6 +97,7 @@ def patch_recipe(fn, relpath, values):
with tempfile.NamedTemporaryFile('w', delete=False) as tf:
def outputvalue(name):
if values[name]:
rawtext = '%s = "%s"\n' % (name, values[name])
if name in nowrap_vars:
tf.write(rawtext)

View File

@ -189,25 +189,6 @@ class BulkChangeEditForm(forms.ModelForm):
model = RecipeChange
fields = ('summary', 'description', 'homepage', 'bugtracker', 'section', 'license')
def __init__(self, *args, **kwargs):
instance = kwargs.get('instance', None)
initial = kwargs.get('initial', {})
if instance:
recipe = instance.recipe
if recipe:
for fieldname in self._meta.fields:
if not getattr(instance, fieldname):
initial[fieldname] = getattr(recipe, fieldname)
kwargs['initial'] = initial
super(BulkChangeEditForm, self).__init__(*args, **kwargs)
def clear_same_values(self):
for fieldname in self._meta.fields:
oldval = getattr(self.instance.recipe, fieldname)
newval = getattr(self.instance, fieldname)
if oldval == newval:
setattr(self.instance, fieldname, '')
BulkChangeEditFormSet = modelformset_factory(RecipeChange, form=BulkChangeEditForm, extra=0)

View File

@ -415,12 +415,16 @@ class RecipeChange(models.Model):
def changed_fields(self, mapped = False):
res = {}
for field in self._meta.fields:
if not field.name in ['id', 'changeset', 'recipe']:
value = getattr(self, field.name)
if value:
for fieldname in self.RECIPE_VARIABLE_MAP:
value = getattr(self, fieldname)
origvalue = getattr(self.recipe, fieldname)
if value != origvalue:
if mapped:
res[self.RECIPE_VARIABLE_MAP[field.name]] = value
res[self.RECIPE_VARIABLE_MAP[fieldname]] = value
else:
res[field.name] = value
res[fieldname] = value
return res
def reset_fields(self):
for fieldname in self.RECIPE_VARIABLE_MAP:
setattr(self, fieldname, getattr(self.recipe, fieldname))

View File

@ -200,8 +200,6 @@ def bulk_change_edit_view(request, template_name, pk):
if request.method == 'POST':
formset = BulkChangeEditFormSet(request.POST, queryset=changeset.recipechange_set.all())
if formset.is_valid():
for form in formset:
form.clear_same_values()
formset.save()
return HttpResponseRedirect(reverse('bulk_change_review', args=(changeset.id,)))
else:
@ -524,6 +522,7 @@ class BulkChangeSearchView(AdvancedRecipeSearchView):
change = RecipeChange()
change.changeset = changeset
change.recipe = recipe
change.reset_fields()
change.save()
if 'add_selected' in request.POST: