You forgot XML.
[wolnelektury.git] / src / picture / tasks.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from traceback import print_exc
6
7 from celery.task import task
8 from django.core.files.base import ContentFile
9 from django.template.loader import render_to_string
10
11
12 @task
13 def generate_picture_html(picture_id):
14     import picture.models
15     pic = picture.models.Picture.objects.get(pk=picture_id)
16
17     html_text = unicode(render_to_string('picture/picture_info.html', {
18                 'things': pic.areas_json['things'],
19                 'themes': pic.areas_json['themes'],
20                 }))
21     pic.html_file.save("%s.html" % pic.slug, ContentFile(html_text))
22
23
24 @task
25 def index_picture(picture_id, picture_info=None, **kwargs):
26     from picture.models import Picture
27     try:
28         return Picture.objects.get(id=picture_id).search_index(picture_info, **kwargs)
29     except Exception, e:
30         print "Exception during index: %s" % e
31         print_exc()
32         raise e