wcs: add db cache refresh to formdef/category cells (#28043)

This commit is contained in:
Frédéric Péters 2018-11-15 11:49:03 +01:00
parent 64ea265733
commit 4ea3c2c920
2 changed files with 18 additions and 0 deletions

View File

@ -34,4 +34,14 @@ class AppConfig(django.apps.AppConfig):
from . import urls from . import urls
return urls.urlpatterns return urls.urlpatterns
def hourly(self):
self.update_db_cache()
def update_db_cache(self):
from combo.data.models import CellBase
from .models import WcsFormCell, WcsCategoryCell, WcsFormsOfCategoryCell
for cell in CellBase.get_cells(
cell_filter=lambda x: x in (WcsFormCell, WcsCategoryCell, WcsFormsOfCategoryCell)):
cell.save()
default_app_config = 'combo.apps.wcs.AppConfig' default_app_config = 'combo.apps.wcs.AppConfig'

View File

@ -11,6 +11,7 @@ import tempfile
import time import time
import os import os
from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from django.test import override_settings from django.test import override_settings
@ -267,6 +268,13 @@ def test_form_cell_save_cache():
'url': 'http://127.0.0.1:8999/form-title/', 'url': 'http://127.0.0.1:8999/form-title/',
'text': ''}] 'text': ''}]
# artificially change title
WcsFormCell.objects.filter(id=cell.id).update(cached_title='XXX')
assert WcsFormCell.objects.get(id=cell.id).cached_title == 'XXX'
# run update db cache
appconfig = apps.get_app_config('wcs')
appconfig.update_db_cache()
assert WcsFormCell.objects.get(id=cell.id).cached_title == 'form title'
@wcsctl_present @wcsctl_present
def test_form_cell_load(): def test_form_cell_load():