genshi

RDBMS & OOP-friendly Python web app framework?

Suppose your boss told you to choose a Python web application framework, and you would be wedded to it for at least the next 3 years. What would you recommend? Ground rules: Python: Yes, required. (Ruby+ not an option for reasons irrelevant. Case closed.) Custom/Hybrid Setups: Sure... if they are defensible on technical grounds. Up...

How do I use genshi.builder to programmatically build an HTML document?

I recently discovered the genshi.builder module. It reminds me of Divmod Nevow's Stan module. How would one use genshi.builder.tag to build an HTML document with a particular doctype? Or is this even a good thing to do? If not, what is the right way? ...

What causes this Genshi's Template Syntax Error?

A Genshi template raises the following error: TemplateSyntaxError: invalid syntax in expression "${item.error}" of "choose" directive The part of the template code that the error specifies is the following ('feed' is a list of dictionary which is passed to the template): <item py:for="item in feed"> <py:choose error="${item.error}...

How do I test if a string exists in a Genshi stream?

I'm working on a plugin for Trac and am inserting some javascript into the rendered HTML by manipulating the Genshi stream. I need to test if a javascript function is already in the HTML and if it is then overwrite it with a new version, if it isn't then add it to the HTML. How do I perform a search to see if the function is already th...

Resolving a relative path from py:match in a genshi template

<py:match path="foo"> <?python import os href = select('@href').render() SOMEWHERE = ... # what file contained the foo tag? path = os.path.abspath(os.path.join(os.path.dirname(SOMEWHERE), href) f = file(path,'r') # (do something interesting with f) ?> </py:match> ... <foo href="../...

Customizing Trac: remove standard footer

We use hosted Trac. It uses Genshi templates. I think we can submit our own site.html. We want to get rid of Trac standard footer. What is the most elegant way of doing that? I suspect that the answer is in some nice Genshi trick. I don't know Genshi nor Trac's additions to it. I tried couple of things on a hunch, none worked. I tried...

Genshi - how to print out all variables in scope

Quite simply I'd like to print out all variables that are in scope in my genshi template, as a debugging and discovery measure. Is there a way to do it? ...

ToscaWidgets Recaptcha - Error Rendering Recaptcha => Page cuts off

Hello everyone, I am using the TW for recaptcha, integrated everything as shown in the examples. When sending the ReCaptcha to my template, my whole page output just cuts off. I have traced back the problem to the javascript code in the widget. It looks like this: <script ....></script> Only the dotted area contains some data, but t...

python/genshi newline to html <p> paragraphs

I'm trying to output the content of a comment with genshi, but I can't figure out how to transform the newlines into HTML paragraphs. Here's a test case of what it should look like: input: 'foo\n\n\n\n\nbar\nbaz' output: <p>foo</p><p>bar</p><p>baz</p> I've looked everywhere for this function. I couldn't find it in genshi or in python...

Should I use Mako for Templating?

I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako. I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe? Wouldn't templating JUST suffice wi...

Why single textarea mess all following xhtml?

I encounter a problem in my web program. I got a textarea in my form, sometimes there is nothing in textarea, so genshi template engine just output it as <textarea xxxx /> and here comes the problem, all following tags are in the textarea. Why all browser can't handle single textarea correctly? If I write it as <textarea xxxx></tex...

How to keep query parameters during pagination with webhelpers.paginate

I look an example of paginating from http://rapidprototype.ch/bg2docs/tg2pagination.html for my Turbogears 2 project and it works great but, I have a problem regarding my query parameters when I change the page I'm looking. This is what I have in my controller when listing. def list(self, page=1, **kw): q = "" if kw.has_key('q...

How to initialize global variables in TurboGears 2 with values from a table

I need a global variable that I can call from the templates. I edited app_globals.py in lib directory to declare PATH_TO_IMAGES like this class Globals(object): """Container for objects available throughout the life of the application. One instance of Globals is created during application initialization and is available du...

Can one prevent Genshi from parsing HTML entities?

I have the following Python code using Genshi (simplified): with open(pathToHTMLFile, 'r') as f: template = MarkupTemplate(f.read()) finalPage = template.generate().render('html', doctype = 'html') The source HTML file contains entities such as &copy;, &trade; and &reg;. Genshi replaces these with their UTF-8 character, which cau...

Genshi: Nested for loops

I need to generate a HTML using a Genshi template. The Html is, basicaly a very long html with tables. The data comes in a simple CSV, so, i read it with python, i put it into a list[] and then i call the template and send the variable (the list) Actually i solved it by doing something like this in the template: <html> <?python> fo...

Genshi table loop

What is wrong with this Genshi template: <html xmlns:py="http://genshi.edgewall.org/"&gt; <head> <title py:content="title"></title> </head> <body> <left> <table py: for="i in range(1, len(ctabl))"> <li py: for="e in ctabl[i]"> ${e} </li> </table> </body> </html> I get this er...

How do I get the remote user agent inside a Genshi template when using Trac, and WSGI?

I'm trying to do some customization of a Trac project management website and have run into an interesting problem. The project has a set of images that are both SVG and PNG. The SVG images have numerous advantages including multiple hyperlinks and a smaller transmitted size against PNG which is bigger and can only link to a single docu...

Trac: How to change order of menu items

How do I change a Trac project so the timeline is the first menu entry, and the default page when entering the project? I can alter the order of entries in the project's conf file but I will still end up in the Wiki when entering. I can disable the Wiki entry in [mainnav] but will still end up on the wiki page when entering. I can't ...

Pylons "global name 'c' is not defined"

hiyas. i had setup Pylons v0.9.7, and create project. and using genshi. and i coding to easy test code , but that code dont working. code: member.py coding: utf-8 import logging import foo.model from foo.lib.base import * log = logging.getLogger(__name__) class MemberController(BaseController): def index(self): c.tit...

What is the method of doing nl2br in Genshi?

hiyas. I using Genshi+Pylons. please teach me, how use \n to <br/>tag in Genshi? I hope to obtain the same result as "nl2br" in php to change line. Or, does not the solution exist? i'm assign template to some text. (genshi template) <p>${c.message}</p> Im tried. case 1: (python code) c.message = """ foo bar """ NG. display res...