annotate roundup/cgi/engine_chameleon.py @ 7867:1774fdf2010a

doc: vale fixes, update TAL repeat object section. For repeat object/variable, added back first() and last() methods now that they are fixed. Moved start/end properties to separate property table along with index. Added details on how even works (e.g. even() is True when number() is 1 because the index is 0 which is even). Document returns from methods are mostly truthy and not true.
author John Rouillard <rouilj@ieee.org>
date Sun, 07 Apr 2024 20:58:58 -0400
parents ac0802452818
children 310e19beba3e
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
4720
fd72576e07ed API break: rename Templates to Loader for zopetal and chameleon
anatoly techtonik <techtonik@gmail.com>
parents: 4719
diff changeset
5 import chameleon
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
6
5418
55f09ca366c4 Python 3 preparation: StringIO.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5416
diff changeset
7 from roundup.cgi.templating import context, TALLoaderBase
5416
56c9bcdea47f Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4749
diff changeset
8 from roundup.anypy.strings import s2u
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
9
6063
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
10
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
11 class Loader(TALLoaderBase):
7775
b8e63e65d9a8 chore: replace use of dir with template_dir.
John Rouillard <rouilj@ieee.org>
parents: 6063
diff changeset
12 def __init__(self, template_dir):
b8e63e65d9a8 chore: replace use of dir with template_dir.
John Rouillard <rouilj@ieee.org>
parents: 6063
diff changeset
13 self.template_dir = template_dir
7790
ac0802452818 fix: typo in var name inan unused (mostly) chameleon engine.
John Rouillard <rouilj@ieee.org>
parents: 7775
diff changeset
14 self.loader = chameleon.PageTemplateLoader(template_dir)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
15
4740
fe9568a6cbd6 Untangle template selection logic from template loading functionality.
anatoly techtonik <techtonik@gmail.com>
parents: 4739
diff changeset
16 def load(self, tplname):
4749
0421390b3094 templating: Move common TAL methods to TALLoaderBase class
anatoly techtonik <techtonik@gmail.com>
parents: 4740
diff changeset
17 src, filename = self._find(tplname)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
18 return RoundupPageTemplate(self.loader.load(src))
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
19
6063
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
20
4635
45ac4cd1a381 Fixes for RoundupPageTemplate in engine_chameleon.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 4587
diff changeset
21 class RoundupPageTemplate(object):
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
22 def __init__(self, pt):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
23 self._pt = pt
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
24
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
25 def render(self, client, classname, request, **options):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
26 c = context(client, self, classname, request)
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
27 c.update({'options': options})
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
28
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
29 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
30 result = client.translator.translate(domain, msgid,
6063
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
31 mapping=mapping,
4d20d8251bf2 flake8 whitespace; removed unused import os.path.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
32 default=default)
5416
56c9bcdea47f Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4749
diff changeset
33 return s2u(result)
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
34
4635
45ac4cd1a381 Fixes for RoundupPageTemplate in engine_chameleon.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 4587
diff changeset
35 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
36 return output.encode(client.charset)
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 __getitem__(self, name):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
39 return self._pt[name]
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
40
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
41 def __getattr__(self, name):
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
42 return getattr(self._pt, name)

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