1 from celery.task import task
2 from django.utils import translation
3 from django.conf import settings
7 def _refresh_by_pk(cls, pk, language=None):
8 prev_language = translation.get_language()
9 language and translation.activate(language)
11 cls._default_manager.get(pk=pk).refresh()
13 translation.activate(prev_language)
15 if settings.USE_CELERY:
16 def refresh_instance(instance):
17 _refresh_by_pk.delay(type(instance), instance.pk, translation.get_language())
19 def refresh_instance(instance):
24 def _publishable_error(book, language=None):
25 prev_language = translation.get_language()
26 language and translation.activate(language)
28 return book.assert_publishable()
29 except AssertionError, e:
34 translation.activate(prev_language)
36 if settings.USE_CELERY:
37 def publishable_error(book):
38 task = _publishable_error.delay(book, translation.get_language())
41 def publishable_error(book):
42 return _publishable_error(book)