fix refresh task when the object is deleted
[redakcja.git] / apps / catalogue / tasks.py
1 # -*- coding: utf-8 -*-
2 from celery.task import task
3 from django.utils import translation
4
5
6 @task(ignore_result=True)
7 def _refresh_by_pk(cls, pk, language=None):
8     prev_language = translation.get_language()
9     if language:
10         translation.activate(language)
11     try:
12         cls._default_manager.get(pk=pk).refresh()
13     except cls.DoesNotExist:
14         pass
15     finally:
16         translation.activate(prev_language)
17
18
19 def refresh_instance(instance):
20     _refresh_by_pk.delay(type(instance), instance.pk, translation.get_language())
21
22
23 @task(ignore_result=True)
24 def book_content_updated(book):
25     book.refresh_dc_cache()