misc: clear validity info when changing feed/json cells (#45842)

This commit is contained in:
Frédéric Péters 2020-08-11 21:07:44 +02:00
parent 95cb806044
commit 05f16b523a
2 changed files with 24 additions and 0 deletions

View File

@ -1382,6 +1382,14 @@ class FeedCell(CellBase):
def is_visible(self, **kwargs):
return bool(self.url) and super(FeedCell, self).is_visible(**kwargs)
def save(self, *args, **kwargs):
result = super().save(*args, **kwargs)
if 'update_fields' not in kwargs:
# always mark cell as valid when it is saved, it will be checked
# for real when it is rendered
self.mark_as_valid()
return result
def get_cell_extra_context(self, context):
extra_context = super(FeedCell, self).get_cell_extra_context(context)
@ -1497,6 +1505,14 @@ class JsonCellBase(CellBase):
class Meta:
abstract = True
def save(self, *args, **kwargs):
result = super().save(*args, **kwargs)
if 'update_fields' not in kwargs:
# always mark cell as valid when it is saved, it will be checked
# for real when it is rendered
self.mark_as_valid()
return result
def is_visible(self, **kwargs):
return bool(self.url) and super(JsonCellBase, self).is_visible(**kwargs)

View File

@ -332,6 +332,10 @@ def test_feed_cell_validity(context):
assert validity_info.invalid_reason_code == 'data_url_invalid'
assert validity_info.invalid_since is not None
# check validity info is cleared when the cell is saved
cell.save()
assert ValidityInfo.objects.exists() is False
def test_menu_cell():
Page.objects.all().delete()
@ -614,6 +618,10 @@ def test_json_cell_validity(context):
cell.get_cell_extra_context(context)
assert ValidityInfo.objects.exists() is True
# check validity info is cleared when the cell is saved
cell.save()
assert ValidityInfo.objects.exists() is False
# url with two variables
context['var2'] = 'bar'
cell.varnames_str = 'var1, var2'