Changes between Version 8 and Version 9 of ShortcutSyntaxIdeas
- Timestamp:
- Sep 21, 2005, 1:03:58 PM (19 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ShortcutSyntaxIdeas
v8 v9 86 86 {{{ 87 87 #!python 88 class PageException(Exception): 89 def __init__(self, arg): 90 self.arg = arg 91 92 def __call__(self): 93 pass 94 95 class HttpResponseRedirect(PageException): 96 def __call__(self): 97 return httpwrappers.HttpResponseRedirect(self.arg) 98 99 def page(template, **decorator_args): 88 def page(template, context=None, **decorator_args): 100 89 def _wrapper(fn): 101 90 def _innerWrapper(request, **args): 102 if (template): 103 tmplt = template_loader.get_template(template) 104 context_dict = decorator_args.copy() 105 try: 106 for i in fn(request, **args): 107 context_dict.update(i) 108 context = Context(request, context_dict) 109 return httpwrappers.HttpResponse(tmplt.render(context)) 110 except PageException, e: 111 return e() 91 for i in fn(request, **args): 92 if isinstance(i, httpwrappers.HttpResponse): 93 return i 94 if type(i) == type(()): 95 context_dict[i[0]] = i[1] 96 else: 97 context_dict.update(i) 98 return load_and_render(template, context_dict, context=context) 112 99 113 100 return _innerWrapper 114 101 return _wrapper 102 115 103 }}} 116 104