1 # BC CMS - Content Management System
2 # Copyright (c) 2008, Carlos Daniel Ruvalcaba Valenzuela
5 # Redistribution and use in source and binary forms, with or without modification,
6 # are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright notice, this
9 # list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright notice, this
11 # list of conditions and the following disclaimer in the documentation and/or other
12 # materials provided with the distribution.
13 # * Neither the name of the BlackChair Software nor the names of its contributors may be
14 # used to endorse or promote products derived from this software without specific prior
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 from django
.http
import HttpResponse
27 from django
.template
import RequestContext
28 from django
.template
.loader
import render_to_string
30 # with thanks to Peter Hunt (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465427)
31 decorator_with_args
= lambda decorator
: lambda *args
, **kwargs
: lambda func
: \
32 decorator(func
, *args
, **kwargs
)
34 # with thanks to Robert Thomson (http://www.djangosnippets.org/snippets/459/)
36 def template_django(func
, template
=None):
37 def DJANGO_TEMPLATE(request
, *args
, **kwargs
):
38 res
= func(request
, *args
, **kwargs
)
43 return HttpResponse(render_to_string(template
, res
, RequestContext(request
)))
46 #return HttpResponse("Templating Error", status=500)
50 DJANGO_TEMPLATE
.__name
__ = func
.__name
__
51 DJANGO_TEMPLATE
.__doc
__ = func
.__doc
__
52 DJANGO_TEMPLATE
.__dict
__ = func
.__dict
__
53 return DJANGO_TEMPLATE