Only formalities.
[wolnelektury.git] / src / picture / tasks.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 import json
5 from celery import shared_task
6 from django.core.files.base import ContentFile
7 from django.template.loader import render_to_string
8
9
10 @shared_task
11 def generate_picture_html(picture_id):
12     import picture.models
13     pic = picture.models.Picture.objects.get(pk=picture_id)
14     areas_json = json.loads(pic.areas_json)
15
16     html_text = render_to_string('picture/picture_info.html', {
17                 'things': areas_json['things'],
18                 'themes': areas_json['themes'],
19                 })
20     pic.html_file.save("%s.html" % pic.slug, ContentFile(html_text))