# HG changeset patch # User cavaliet # Date 1363090409 -3600 # Node ID fc3203831322dfffdcc4fdf78a084596c30ada35 # Parent 303eca26bcc094ea2fd12ce1a9961e53268c1171 svg file and picture file are created for senseetive diff -r 303eca26bcc0 -r fc3203831322 src/egonomy/config.py.tmpl --- a/src/egonomy/config.py.tmpl Tue Mar 05 10:30:02 2013 +0100 +++ b/src/egonomy/config.py.tmpl Tue Mar 12 13:13:29 2013 +0100 @@ -136,3 +136,6 @@ } IMAGES_PER_PAGE = 32 + +BATIK_RASTERIZER_PATH = "path/to/batik-rasterizer.jar" +BATIK_RASTERIZER_TEMP_FOLDER = "path/to/tmp_folder" diff -r 303eca26bcc0 -r fc3203831322 src/egonomy/views.py --- a/src/egonomy/views.py Tue Mar 05 10:30:02 2013 +0100 +++ b/src/egonomy/views.py Tue Mar 12 13:13:29 2013 +0100 @@ -14,6 +14,9 @@ from egonomy.search_indexes.query import ModelRelatedSearchQuerySet from haystack.query import RelatedSearchQuerySet import json +import os +import uuid +import subprocess import logging logger = logging.getLogger(__name__) @@ -221,8 +224,39 @@ frg_path = request.GET.get("path") or "MZ" if not image_id or frg_path=="MZ": return HttpResponseForbidden("The request needs an image and a not null path parameters.") - # This is a TEMPORARY algorithm. In the future, this function build a picture from the fragment and will request the senseetive api - img = get_object_or_404(Image, id=image_id) + + img = get_object_or_404(Image.objects.select_related('info', 'metadata'), id=image_id) + frg = Fragment() + frg.image = img + frg.coordinates = frg_path + # We build the svg xml + file = os.path.join(settings.MEDIA_ROOT, str(img.info.image_file)) + logger.debug(file) + svg = '\n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ +' + # We save the svg file + uid = str(uuid.uuid1()) + svg_file = open(os.path.join(settings.BATIK_RASTERIZER_TEMP_FOLDER, uid + '.svg'),'w') + svg_file.write(svg) + svg_file.close() + # We execute the batik command + args = ["java", "-jar", settings.BATIK_RASTERIZER_PATH, svg_file.name] + p = subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE) + out, err = p.communicate() + if p.returncode!=0: + HttpResponse("Batik error : " + str(err)) + # The picture png is now created + + + + # This is a TEMPORARY algorithm. In the future, this function build a picture from the fragment and will request the senseetive api frg_list = Fragment.objects.filter(image=img) tag_list = [] for frg in frg_list: @@ -230,7 +264,7 @@ for t in tags: t = t.strip() if t != "": - logger.debug(t) + #logger.debug(t) tag_list.append(t) from time import sleep sleep(2)