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