Re: pylons with chameleon?
create a template object, which attach to app_globals in config/envrionment.py, then create a render function, using pylons_globals() and cached_template() functions, all after, add it to app_globals to render the template by using template lookup method. 2009/9/20 Iain Duncan iaindun...@telus.net Wichert, thank you so much for your explicit example! I'll try that out this week. =) Iain On Sat, 2009-09-19 at 09:40 +0200, Wichert Akkerman wrote: On 2009-9-16 21:06, Iain Duncan wrote: Hi folks, I have not built enough pylons to be know how to switch templating languages beyond mako and genshi, but I'm interested in using Chameleon. Has anyone got any examples up of what one needs to do to use Chameleon? In config/environment.py: from genshi.template import TemplateLoader as GenshiTemplateLoader def load_environment(global_conf, app_conf): ... ... # Create the chameleon TemplateLoader config['pylons.app_globals'].pt_loader = TemplateLoader( paths['templates'], auto_reload=True) Add a new file in lib (mine is called lib/pt.py): from pylons.templating import pylons_globals from pylons.templating import cached_template def render_pt(template_name, cache_key=None, cache_type=None, cache_expire=None): Render a page template with z3c.pt. def render_template(): globs = pylons_globals() template = globs[app_globals].pt_loader.load(template_name) return template(**globs) return cached_template(template_name, render_template, cache_key=cache_key, cache_type=cache_type, cache_expire=cache_expire) def render_text(template_name, cache_key=None, cache_type=None, cache_expire=None): Render a text template with z3c.pt. def render_template(): globs = pylons_globals() template = globs[app_globals].pt_loader.load(template_name, format=text) return template(**globs) return cached_template(template_name, render_template, cache_key=cache_key, cache_type=cache_type, cache_expire=cache_expire) you can then use render_pt to render html/xml templates, and render_text to render text templates, exactly like you use other templating languages. Wichert. -- To be pythoner My blog: http://www.cnblogs.com/ubunoon/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Form validator with dependency
Hi Everyone: I have an HTML form that I'd like to validate using formencode, if possible. The form has three main options represented by radio buttons. If one of those options is selected, there are four sub- options to choose from, represented by checkboxes. For example, suppose the three main options were football, baseball and basketball; and baseball has four sub-options: pitcher, catcher, infield, outfield). The trick here is that at least one of sub-options (checkboxes) must be selected if baseball is selected. The other main options have no suboptions. But, none of baseball's sub-options should be selected if football or basketball were selected. How can formencode validator(s) be used to set up this kind of validation? Thanks. Edgar --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Re: Form validator with dependency
On Mon, Sep 21, 2009 at 11:11 AM, edgarsmolow edgarsmo...@gmail.com wrote: Hi Everyone: I have an HTML form that I'd like to validate using formencode, if possible. The form has three main options represented by radio buttons. If one of those options is selected, there are four sub- options to choose from, represented by checkboxes. For example, suppose the three main options were football, baseball and basketball; and baseball has four sub-options: pitcher, catcher, infield, outfield). The trick here is that at least one of sub-options (checkboxes) must be selected if baseball is selected. The other main options have no suboptions. But, none of baseball's sub-options should be selected if football or basketball were selected. How can formencode validator(s) be used to set up this kind of validation? First of all, don't create part-time controls with Javascript and expect them to be sometimes in the result. Make static controls for everything and hide the ones that are irrelevant. That way your validator will always return a fixed set of variables, and the irrelevant ones will have their default values. If a group of controls has a dependency relationship, you'll have to test that either in a chained validator or nested validator. If your HTML fields are all flat (not nested), you can do the type checking in the main validators (integer, one of list), but allow part-time controls to be empty (don't require them). Then in the chained validator, determined which sub-options are required and and raise an error if they're empty. You may also have to do additional work in the chained operator depending on the constraints you wish to impose. A nested validator is a little group of controls. E.g., the baseball controls, the football controls. Each sub-validator has a dict value, and the HTML names of the controls must follow the NestedVariables rules. The resulting form parameters will be a dict in a dict. If the sub-groups are totally unique, you can use a different validator for each one. If there's some commonality between them (e.g., all have three pulldowns which differ only in their options), you may be able to write one validator class that can be instantiated differently for each one. -- Mike Orr sluggos...@gmail.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Always get new Beaker Sessions with SQLAlchemy
I have been using the dbm approach to sessions and recently wanted to transfer to having the sessions stored in a table in the DB. I have beaker setup at least partially correctly, because I am seeing new sessions getting created in the postgresql table. However, each time I refresh the page, I get a new session and see a new row get created in the session's table. Keep in mind the only thing that changed was the beaker config and before that my application worked fine. Any suggestions? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Re: cron Paster Command
There's also a paster request command that is GREAT for cron jobs. GREAT! On Fri, Sep 18, 2009 at 3:52 PM, Raoul Snyman raoul.sny...@gmail.comwrote: Hi guys, I've recently been investigating how to run cron jobs for my Pylons applications, and followed the example I found on the wiki by creating a paster command. I've blogged about it, and uploaded the script to my blog. http://is.gd/3qpl6 One of the cool things about it (if I may brag a little!) is that you don't have to do much to get it up and running. The command class will find all your controllers, and will run a cron command if it exists in your controller. Constructive criticism is welcome! -- Raoul Snyman B.Tech Information Technology (Software Engineering) E-Mail: raoul.sny...@gmail.com Web: http://www.saturnlaboratories.co.za/ Blog: http://blog.saturnlaboratories.co.za/ Mobile: 082 550 3754 Registered Linux User #333298 (http://counter.li.org) -- Ian Bicking | http://blog.ianbicking.org | http://topplabs.org/civichacker --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---