Skip to content

Commit

Permalink
Add in an example of using a class-based panel with arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pauleveritt committed Dec 6, 2012
1 parent cbd6d7b commit 02e4d45
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
28 changes: 28 additions & 0 deletions demo/demo/panels.py
Expand Up @@ -69,3 +69,31 @@ def headings(context, request):
@panel_config(name='footer')
def footer(context, request):
return '<p>&copy; Pylons Project 2012</p>'

# Example of class-based panel
class UserPanel(object):
def __init__(self, context, request):
self.context = context
self.request = request

@panel_config(name='usermenu',
renderer='demo:templates/panels/usermenu.pt')
def __call__(self, user_info=None):
""" Show the username of the passed in user. If None,
get the current user off the request. """

if user_info is None:
# Presumes request.user has some info, just a demo
user = self.request.user
user_info = dict(
first_name=user['firstname'],
last_name=user['lastname'],
username=user['username']
)

label = user_info['first_name'] + ' ' + user_info['last_name']
href = '/profiles/' + user_info['username']
return dict(
label=label,
href=href
)
9 changes: 8 additions & 1 deletion demo/demo/templates/home.pt
Expand Up @@ -6,7 +6,14 @@

<!-- Example row of columns -->
<div class="row">
${panel('headings')}
<p>${panel('headings')}</p>
<h2>User Info</h2>
<p>${panel('usermenu',
user_info={
'first_name': 'Jane',
'last_name': 'Doe',
'username': 'jdoe'}
)}</p>
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions demo/demo/templates/panels/usermenu.pt
@@ -0,0 +1,3 @@
<div>
<a href="${href}">${label}</a>
</div>

0 comments on commit 02e4d45

Please sign in to comment.