0001-dashboard-skip-invalid-cells-in-dashboards-41226.patch
combo/apps/dashboard/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import datetime |
|
18 | ||
17 | 19 |
from django.conf import settings |
18 | 20 |
from django.contrib.contenttypes.models import ContentType |
19 | 21 |
from django.contrib.contenttypes import fields |
20 | 22 |
from django.db import models |
23 |
from django.utils.timezone import now |
|
21 | 24 |
from django.utils.translation import ugettext_lazy as _ |
22 | 25 | |
23 |
from combo.data.models import CellBase |
|
26 |
from combo.data.models import CellBase, ValidityInfo
|
|
24 | 27 |
from combo.data.library import register_cell_class |
25 | 28 | |
26 | 29 | |
... | ... | |
45 | 48 |
return True |
46 | 49 | |
47 | 50 |
def render(self, context): |
48 |
context['tiles'] = Tile.objects.filter(dashboard=self, user=context['user']) |
|
51 |
tiles = Tile.objects.filter(dashboard=self, user=context['user']) |
|
52 |
validity_info_dict = {(x.content_type_id, x.object_id): True for x in |
|
53 |
ValidityInfo.objects.filter(invalid_since__lt=now() - datetime.timedelta(days=2))} |
|
54 |
context['tiles'] = [x for x in tiles if (x.cell_type_id, x.cell_pk) not in validity_info_dict] |
|
49 | 55 |
return super(DashboardCell, self).render(context) |
50 | 56 | |
51 | 57 |
tests/test_dashboard.py | ||
---|---|---|
1 |
import datetime |
|
1 | 2 |
import json |
2 | 3 |
import mock |
3 | 4 |
import os |
... | ... | |
211 | 212 |
def test_clean_autotiles(app, site): |
212 | 213 |
appconfig = apps.get_app_config('dashboard') |
213 | 214 |
appconfig.clean_autotiles() |
215 | ||
216 | ||
217 |
def test_dashboard_invalid_cells(app, site): |
|
218 |
app = login(app) |
|
219 |
cell = TextCell.objects.get(order=100) |
|
220 |
dashboard = DashboardCell.objects.all()[0] |
|
221 |
user = User.objects.all()[0] |
|
222 |
resp = app.get(reverse('combo-dashboard-add-tile', |
|
223 |
kwargs={'cell_reference': cell.get_reference()})) |
|
224 |
assert Tile.objects.all()[0].cell.id != cell.id |
|
225 |
assert Tile.objects.all()[0].cell.text == cell.text |
|
226 |
assert Tile.objects.all()[0].dashboard_id == dashboard.id |
|
227 |
assert Tile.objects.all()[0].user_id == user.id |
|
228 |
assert Tile.objects.all()[0].order == 0 |
|
229 | ||
230 |
app = login(app) |
|
231 |
resp = app.get('/two/', status=200) |
|
232 |
assert 'hello world' in resp.text |
|
233 | ||
234 |
cell = Tile.objects.all()[0].cell |
|
235 |
cell.mark_as_invalid(reason_code='plop') |
|
236 |
resp = app.get('/two/', status=200) |
|
237 |
assert 'hello world' in resp.text |
|
238 | ||
239 |
validity_info = cell.get_validity_info() |
|
240 |
validity_info.invalid_since = validity_info.invalid_since - datetime.timedelta(days=3) |
|
241 |
validity_info.save() |
|
242 | ||
243 |
resp = app.get('/two/', status=200) |
|
244 |
assert 'hello world' not in resp.text |
|
214 |
- |