Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
def merge(url):
full_url=[]
for i, el in enumerate(url):
if i%2==0:
full_url.append(el)
full_url = ''.join(full_url)
return full_url
def combineflatten(seq):
items= tuple(item for item in seq if not isinstance(item, tuple))
yield items
for item in seq:
if isinstance(item, tuple):
for yielded in combineflatten(item):
yield items+yielded
def generate_flat_urls(tree_urls):
"""
>>> tree_urls = ('', 'list',
... ('edit/', 'edit', ('auto/', 'edit_auto')),
... ('^add/', 'add'),
... ('delete/', 'delete', ('delete/', 'delete_hard'))
... )
>>> generate_flat_urls(tree_urls)
[('^$', 'list'), ('^edit/$', 'edit'), ('^edit/auto/$', 'edit_auto'), ('^^add/$', 'add'), ('^delete/$', 'delete'), ('^delete/delete/$', 'delete_hard')]
"""
return [('^%s$'%merge(el), el[-1]) for el in tuple(combineflatten(tree_urls))]
from django.shortcuts import render_to_response
def render_with_auth_check(request, payload, request_context, *args, **kwrags):
for el in payload.itervalues():
try:
has_auth = el.check_auth(request.user)
if not has_auth:
raise AuthFailException
except ValueError:
pass #Not all objects have check_auth
return render_to_response(request, payload, request_context, *args, **kwrags)
class AuthFailHandlerMiddleware:
def process_exception(self, request, exception):
if type(exception) == AuthFailException:
return render_to_response('accounts/login/', {}, RequestContext(request))
def render_jinja_to_response(template_name, payload):
#This should probably go in settings.py
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('yourapplication', 'templates'))
template = env.get_template(template_name)
response = template.render(**payload)
return HttpResponse(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.