mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 12:49:01 +02:00
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:
parent
fbc6a058d3
commit
79282350f8
|
@ -97,14 +97,15 @@ def patch_recipe(fn, relpath, values):
|
|||
|
||||
with tempfile.NamedTemporaryFile('w', delete=False) as tf:
|
||||
def outputvalue(name):
|
||||
rawtext = '%s = "%s"\n' % (name, values[name])
|
||||
if name in nowrap_vars:
|
||||
tf.write(rawtext)
|
||||
else:
|
||||
wrapped = textwrap.wrap(rawtext)
|
||||
for wrapline in wrapped[:-1]:
|
||||
tf.write('%s \\\n' % wrapline)
|
||||
tf.write('%s\n' % wrapped[-1])
|
||||
if values[name]:
|
||||
rawtext = '%s = "%s"\n' % (name, values[name])
|
||||
if name in nowrap_vars:
|
||||
tf.write(rawtext)
|
||||
else:
|
||||
wrapped = textwrap.wrap(rawtext)
|
||||
for wrapline in wrapped[:-1]:
|
||||
tf.write('%s \\\n' % wrapline)
|
||||
tf.write('%s\n' % wrapped[-1])
|
||||
|
||||
tfn = tf.name
|
||||
with open(fn, 'r') as f:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -418,12 +418,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:
|
||||
if mapped:
|
||||
res[self.RECIPE_VARIABLE_MAP[field.name]] = value
|
||||
else:
|
||||
res[field.name] = 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[fieldname]] = value
|
||||
else:
|
||||
res[fieldname] = value
|
||||
return res
|
||||
|
||||
def reset_fields(self):
|
||||
for fieldname in self.RECIPE_VARIABLE_MAP:
|
||||
setattr(self, fieldname, getattr(self.recipe, fieldname))
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user