+def page(request):
+ path = request.path[1:]
+
+ if path in settings.STATIC_PAGE_REGISTRY:
+ try:
+ page = Page.objects.get(id=settings.STATIC_PAGE_REGISTRY[path])
+
+ if (not page.published) and (not request.user.is_superuser):
+ return HttpResponseNotFound(request)
+ except:
+ return HttpResponseNotFound(request)
+ else:
+ return HttpResponseNotFound(request)
+
+ template = page.extra.get('template', 'default')
+ sidebar = page.extra.get('sidebar', '')
+
+ if template == 'default':
+ base = 'base_content.html'
+ elif template == 'sidebar':
+ base = 'base.html'
+
+ sidebar_render = page.extra.get('render', 'markdown')
+
+ if sidebar_render == 'markdown':
+ sidebar = page._as_markdown(sidebar)
+ elif sidebar_render == 'html':
+ sidebar = mark_safe(sidebar)
+
+ else:
+ return HttpResponse(page.body, content_type=page.extra.get('mimetype', 'text/html'))
+
+ render = page.extra.get('render', 'markdown')
+
+ if render == 'markdown':
+ body = page.as_markdown()
+ elif render == 'html':
+ body = mark_safe(page.body)
+ else:
+ body = page.body
+
+ return render_to_response('page.html', {
+ 'page' : page,
+ 'body' : body,
+ 'sidebar': sidebar,
+ 'base': base,
+ }, context_instance=RequestContext(request))
+
+
+def error_handler(request):
+
+ stacktrace = "".join(["\t\t%s\n" % l for l in traceback.format_exc().split("\n")])
+
+ try:
+ log_msg = """
+ error executing request:
+ PATH: %(path)s
+ USER: %(user)s
+ METHOD: %(method)s
+ POST PARAMETERS:
+ %(post)s
+ GET PARAMETERS:
+ %(get)s
+ HTTP HEADERS:
+ %(headers)s
+ COOKIES:
+ %(cookies)s
+ EXCEPTION INFO:
+ %(stacktrace)s
+ """ % {
+ 'path': request.path,
+ 'user': request.user.is_authenticated() and ("%s (%s)" % (request.user.username, request.user.id)) or "<anonymous>",
+ 'method': request.method,
+ 'post': request.POST and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.POST.items()]) or "None",
+ 'get': request.GET and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.GET.items()]) or "None",
+ 'cookies': request.COOKIES and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.COOKIES.items()]) or "None",
+ 'headers': request.META and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.META.items()]) or "None",
+ 'stacktrace': stacktrace
+ }
+ except:
+ log_msg = "error executing request:\n%s" % stacktrace
+
+
+ logging.error(log_msg)
+ return HttpResponseIntServerError(request)