Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
69406c08
Commit
69406c08
authored
Jan 13, 2011
by
Carl Whittaker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing regression on 0 values not being rendered.
parent
bd0c7cc0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
pystache/template.py
+13
-2
pystache/view.py
+1
-1
No files found.
pystache/template.py
View file @
69406c08
...
...
@@ -19,6 +19,17 @@ def modifier(symbol):
return
func
return
set_modifier
def
get_or_attr
(
obj
,
name
,
default
=
None
):
try
:
return
obj
[
name
]
except
KeyError
:
return
default
except
:
try
:
return
getattr
(
obj
,
name
)
except
AttributeError
:
return
default
class
Template
(
object
):
tag_re
=
None
...
...
@@ -60,7 +71,7 @@ class Template(object):
section
,
section_name
,
inner
=
match
.
group
(
0
,
1
,
2
)
section_name
=
section_name
.
strip
()
it
=
view
.
get
(
section_name
,
None
)
it
=
get_or_attr
(
view
,
section_name
,
None
)
replacer
=
''
# Callable
...
...
@@ -113,7 +124,7 @@ class Template(object):
@modifier
(
None
)
def
_render_tag
(
self
,
tag_name
,
view
):
raw
=
view
.
get
(
tag_name
,
''
)
raw
=
get_or_attr
(
view
,
tag_name
,
''
)
# For methods with no return value
if
not
raw
and
raw
is
not
0
:
...
...
pystache/view.py
View file @
69406c08
...
...
@@ -56,7 +56,7 @@ class View(object):
def
__getitem__
(
self
,
attr
):
val
=
self
.
get
(
attr
,
None
)
if
not
val
:
if
not
val
and
val
is
not
0
:
raise
KeyError
(
"No such key."
)
return
val
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment