I have been trying to understand web2py's builtins for some fun features I
am working on.
Basically I am trying to make a renderer for svg files and want to convert
escaped charactors like quot; back to there actual charactors.
This would encable me to create SVG's that can use the templating that is
found in web2py.
Think of the following:
1: Designer uploads svg to site with python controller file to web2py site
I have made.
2: Call is made to render the SVG as a PNG
3: SVG is checked for the delimiter tags
4: we convert the quot; tags back to originals
5: we then send the newly created content to the parse and use the
designers controller as the controller for that view.
6: Send the newly rendered template content to a headless inskape
application to render it as a png
7: Stream it to the view.
3 and 4 are the parts I need the help on. All other parts work.
Now the cheep way is to go in and try to make my own tag finder for {{}}
tags and then find the escaped characters from there, but I wonder if I
could use web2py's built in functionality in gluon/template.py
Any thought here?
I hacked to gether some code here:
def render_app(context, template_file):
"""
Backend feature that renders the view and save it to a location.
The location is returned
"""
from subprocess import call
import os
template_file = os.path.join(request.folder, 'uploads', template_file)
#Need to process the svg and remove any charactor encoding and put it
back to normal for the final rendering.
prepared_template = prepare_template(template_file)
rendered_svg = os.path.join(request.folder, 'private', 'temp_svg.svg')
temp_image = os.path.join(request.folder, 'static', 'temp_image.png')
final_svg = response.render(template_file, context)
svg_file = open(rendered_svg, "w")
svg_file.write(final_svg)
svg_file.close()
call(['inkscape', '--export-png='+temp_image, rendered_svg])
return temp_image
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.