wall coloured and split in days,
[redakcja.git] / apps / catalogue / tasks.py
1 from celery.task import task
2 from django.utils import translation
3 from django.conf import settings
4
5
6 @task
7 def _refresh_by_pk(cls, pk, language=None):
8     prev_language = translation.get_language()
9     language and translation.activate(language)
10     try:
11         cls._default_manager.get(pk=pk).refresh()
12     finally:
13         translation.activate(prev_language)
14
15 def refresh_instance(instance):
16     _refresh_by_pk.delay(type(instance), instance.pk, translation.get_language())
17
18
19 @task
20 def _publishable_error(book, language=None):
21     prev_language = translation.get_language()
22     language and translation.activate(language)
23     try:
24         return book.assert_publishable()
25     except AssertionError, e:
26         return e
27     else:
28        return None
29     finally:
30         translation.activate(prev_language)
31
32 def publishable_error(book):
33     return _publishable_error.delay(book, 
34         translation.get_language()).wait()