annotate roundup/cgi/engine_chameleon.py @ 5192:302e3a1a7190

Three sets of changes: 1) Make sure that a user doesn't create a query with the same name as an existing query that the user owns. 2) When submitting a new named query, display the name of the query on the index page. 3) Allow optional arguments to indexargs_url by setting their value to None. This will show the argument only if there is a valid value. To match these, changed the template for all search templates so if an error is thrown due to #1 the user stays on the search page so they can fix the issue. Note that I did not add automated tests for these because I couldn't find existing tests for these code paths that I could adapt. I don't understand how the existing Action tests work and there is no doc for them.
author rouilj@uland
date Wed, 08 Mar 2017 22:04:15 -0500
parents 0421390b3094
children 56c9bcdea47f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
1 """Templating engine adapter for the Chameleon."""
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
2
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
3 __docformat__ = 'restructuredtext'
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
4
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
5 import os.path
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4719
diff changeset
6 import chameleon
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
7
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
8 from roundup.cgi.templating import StringIO, context, TALLoaderBase
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
9
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
10 class Loader(TALLoaderBase):
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
11 def __init__(self, dir):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
12 self.dir = dir
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4719
diff changeset
13 self.loader = chameleon.PageTemplateLoader(dir)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
14
4740
fe9568a6cbd6 Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents: 4739
diff changeset
15 def load(self, tplname):
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
16 src, filename = self._find(tplname)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
17 return RoundupPageTemplate(self.loader.load(src))
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
18
4635
45ac4cd1a381 Fixes for RoundupPageTemplate in engine_chameleon.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 4587
diff changeset
19 class RoundupPageTemplate(object):
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
20 def __init__(self, pt):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
21 self._pt = pt
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
22
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
23 def render(self, client, classname, request, **options):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
24 c = context(client, self, classname, request)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
25 c.update({'options': options})
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
26
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
27 def translate(msgid, domain=None, mapping=None, default=None):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
28 result = client.translator.translate(domain, msgid,
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
29 mapping=mapping, default=default)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
30 return unicode(result, client.translator.OUTPUT_ENCODING)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
31
4635
45ac4cd1a381 Fixes for RoundupPageTemplate in engine_chameleon.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 4587
diff changeset
32 output = self._pt.render(None, translate, **c)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
33 return output.encode(client.charset)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
34
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
35 def __getitem__(self, name):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
36 return self._pt[name]
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
37
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
38 def __getattr__(self, name):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
39 return getattr(self._pt, name)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
40

Roundup Issue Tracker: http://roundup-tracker.org/