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
0a655dc6
Commit
0a655dc6
authored
Jan 27, 2011
by
Carl Whittaker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding magic attribute to fetch a flattened context
parent
8eac16d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
pystache/view.py
+13
-2
tests/test_view.py
+6
-0
No files found.
pystache/view.py
View file @
0a655dc6
...
...
@@ -74,8 +74,18 @@ class View(object):
val
=
self
.
get
(
attr
,
None
)
if
not
val
and
val
is
not
0
:
raise
KeyError
(
"No such key."
)
return
val
raise
KeyError
(
"No such key '
%
s'."
%
attr
)
return
val
def
__getattr__
(
self
,
attr
):
if
attr
==
'context'
:
context
=
{}
for
d
in
self
.
context_list
:
context
.
update
(
d
)
return
context
raise
AttributeError
(
"No such attribute '
%
s'."
%
attr
)
def
__str__
(
self
):
return
self
.
render
()
\ No newline at end of file
tests/test_view.py
View file @
0a655dc6
...
...
@@ -98,5 +98,11 @@ class TestView(unittest.TestCase):
self
.
assertEquals
(
view
.
render
(),
'derp'
)
def
test_context_returns_a_flattened_dict
(
self
):
view
=
Simple
()
view
.
context_list
=
[{
'one'
:
'1'
},
{
'two'
:
'2'
}]
self
.
assertEqual
(
view
.
context
,
{
'one'
:
'1'
,
'two'
:
'2'
})
if
__name__
==
'__main__'
:
unittest
.
main
()
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