dashboard: skip invalid cells in dashboards (#41226)
This commit is contained in:
parent
43c8ec28ca
commit
9786d9b387
|
@ -14,13 +14,16 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import fields
|
||||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from combo.data.models import CellBase
|
||||
from combo.data.models import CellBase, ValidityInfo
|
||||
from combo.data.library import register_cell_class
|
||||
|
||||
|
||||
|
@ -45,7 +48,10 @@ class DashboardCell(CellBase):
|
|||
return True
|
||||
|
||||
def render(self, context):
|
||||
context['tiles'] = Tile.objects.filter(dashboard=self, user=context['user'])
|
||||
tiles = Tile.objects.filter(dashboard=self, user=context['user'])
|
||||
validity_info_dict = {(x.content_type_id, x.object_id): True for x in
|
||||
ValidityInfo.objects.filter(invalid_since__lt=now() - datetime.timedelta(days=2))}
|
||||
context['tiles'] = [x for x in tiles if (x.cell_type_id, x.cell_pk) not in validity_info_dict]
|
||||
return super(DashboardCell, self).render(context)
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import datetime
|
||||
import json
|
||||
import mock
|
||||
import os
|
||||
|
@ -211,3 +212,33 @@ def test_auto_tile(app, site):
|
|||
def test_clean_autotiles(app, site):
|
||||
appconfig = apps.get_app_config('dashboard')
|
||||
appconfig.clean_autotiles()
|
||||
|
||||
|
||||
def test_dashboard_invalid_cells(app, site):
|
||||
app = login(app)
|
||||
cell = TextCell.objects.get(order=100)
|
||||
dashboard = DashboardCell.objects.all()[0]
|
||||
user = User.objects.all()[0]
|
||||
resp = app.get(reverse('combo-dashboard-add-tile',
|
||||
kwargs={'cell_reference': cell.get_reference()}))
|
||||
assert Tile.objects.all()[0].cell.id != cell.id
|
||||
assert Tile.objects.all()[0].cell.text == cell.text
|
||||
assert Tile.objects.all()[0].dashboard_id == dashboard.id
|
||||
assert Tile.objects.all()[0].user_id == user.id
|
||||
assert Tile.objects.all()[0].order == 0
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/two/', status=200)
|
||||
assert 'hello world' in resp.text
|
||||
|
||||
cell = Tile.objects.all()[0].cell
|
||||
cell.mark_as_invalid(reason_code='plop')
|
||||
resp = app.get('/two/', status=200)
|
||||
assert 'hello world' in resp.text
|
||||
|
||||
validity_info = cell.get_validity_info()
|
||||
validity_info.invalid_since = validity_info.invalid_since - datetime.timedelta(days=3)
|
||||
validity_info.save()
|
||||
|
||||
resp = app.get('/two/', status=200)
|
||||
assert 'hello world' not in resp.text
|
||||
|
|
Loading…
Reference in New Issue