stoat / stoat /

# {{{
from django.conf import settings
from django.http import Http404, HttpResponsePermanentRedirect, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.views.decorators.csrf import csrf_protect
from django.contrib.auth.decorators import login_required

from forms import MovePageForm
from models import Page
from stemplates import get_path
# }}}

def page(request, url):
    if not url.startswith('/'):
        url = "/" + url
        p = get_object_or_404(Page, url__exact=url)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            new_url = url + "/"
            get_object_or_404(Page, url__exact=new_url)
            return HttpResponsePermanentRedirect("%s/" % request.path)
    return render_page(request, p)

def render_page(request, p):
    if p.template[-12:] == "Members Only":
        return render_members_only(request, p)
    return render_to_response(get_path(p.template), {
        'page': p,
    }, context_instance=RequestContext(request))

def render_members_only(request, p):
    return render_to_response(get_path(p.template), {
    }, context_instance=RequestContext(request))

def move_page(request):
    if not request.POST:
        return HttpResponseBadRequest()

    form = MovePageForm(request.POST)
    if form.is_valid():
        page = form.cleaned_data['page']
        page_id =
        target = form.cleaned_data['target']
        position = form.cleaned_data['position']

        if position == 'above':
            page.move(target, 'left')
        elif position == 'below':
            page.move(target, 'right')
        elif position == 'inside':
            page.move(target, 'last-child')

        page = Page.objects.get(id=page_id)

    # TODO: Make this dynamic.
    return HttpResponsePermanentRedirect('/admin/stoat/page/')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.