Skip to content

Commit

Permalink
use python built in for updating a dict
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Oct 1, 2008
1 parent 896992b commit 2c62a20
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions faq/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
from models import Question
import datetime

def dict_to_dict(origin, new):
"""
A utility method to add items from one dictionary to an already existing dictionary.
Primary use is for extra_context population.
"""

for key, value in new.items():
if callable(value):
origin[key] = value()
else:
origin[key] = value

def question_detail(request, slug, template_name='faq/question_detail.html', extra_context={}):
"""
Expand Down Expand Up @@ -42,11 +29,10 @@ def question_list( request, template_name='faq/question_list.html', extra_contex
#for people to see how they could "extend" their existing extra_context using a parameter value to
#allow developers to make their app more reusable
#we set the below dict value and then allow the user to pass along their own
#if they we then populate the user supplied extra_context using the dict_to_dict method
#if they we then populate the user supplied extra_context using the update method
extra = { 'created_on': datetime.datetime.now() }

if extra_context:
dict_to_dict( extra, extra_context )
extra.update( extra_context )

return object_list(
request,
Expand Down

0 comments on commit 2c62a20

Please sign in to comment.