1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from traceback import print_exc
7 from celery import shared_task
8 from django.core.files.base import ContentFile
9 from django.template.loader import render_to_string
13 def generate_picture_html(picture_id):
15 pic = picture.models.Picture.objects.get(pk=picture_id)
16 areas_json = json.loads(pic.areas_json)
18 html_text = render_to_string('picture/picture_info.html', {
19 'things': areas_json['things'],
20 'themes': areas_json['themes'],
22 pic.html_file.save("%s.html" % pic.slug, ContentFile(html_text))
26 def index_picture(picture_id, picture_info=None, **kwargs):
27 from picture.models import Picture
29 return Picture.objects.get(id=picture_id).search_index(picture_info, **kwargs)
30 except Exception as e:
31 print("Exception during index: %s" % e)