Example #1
0
def page_factory(request):

    path = request.path
    resource_dict = resources.load_yaml(open(settings.URLS_FILE))

    resource = resource_dict.get(path)
    if not resource:
        return django.http.HttpResponseNotFound("Can't find your page, bro.")

    response = resource.render(request)

    # slug = "/" + slug
    # slug = slug.lower()
    # resource = None

    # if getattr(request, "site", None) is not None:
    #     resource = resources.Resource.objects(site=request.site, slug=slug).first()

    #     if resource is None:  # Try full path for advanced redirects.
    #         path = request.get_full_path().lower()
    #         resource = resources.Resource.objects(site=request.site, slug=path).first()

    # if resource is None:
    #     reqdict = {"domain": request.domain, "slug": slug}
    #     return shortcut.render(request, "404.html", reqdict, status=404)

    # response = resource.render(request)

    # Tell the browser they should be the latest they can be!
    c_type = response.get('Content-Type', '').split(';', 1)[0].lower()
    if c_type in ['text/html', 'application/xhtml+xml', 'application/xml']:
        if not 'X-UA-Compatible' in response:
            response['X-UA-Compatible'] = 'IE=edge, chrome=1'
    return response
Example #2
0
def resource_list(request):
    resource_dict = resources.load_yaml(open(settings.URLS_FILE))
    urls_yaml = resources.dump_yaml(resource_dict)
    return django.http.HttpResponse("<pre>{}</pre>".format(urls_yaml))