Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 69 lines (55 sloc) 1.945 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth import authenticate, login
from django.http import HttpResponse, HttpResponseRedirect
from django.utils import simplejson
from django.utils.translation import ugettext as _

from models import Page, ContentItem


def fiber_login(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)

    result = {}
    if user is not None:
        if user.is_active:
            login(request, user)
            result = {
                'status': 'success',
            }
        else:
            result = {
                'status': 'inactive',
                'message': _('This account is inactive.'),
            }
    else:
            result = {
                'status': 'failed',
                'message': _('Please enter a correct username and password. Note that both fields are case-sensitive.'),
            }
    json = simplejson.dumps(result)
    return HttpResponse(json, mimetype='application/json')


@staff_member_required
def page_move_up(request, id):
    page = Page.objects.get(pk=id)

    if page:
        previous_sibling_page = page.get_previous_sibling()
        if previous_sibling_page:
            page.move_to(previous_sibling_page, position='left')

    return HttpResponseRedirect('../../')


@staff_member_required
def page_move_down(request, id):
    page = Page.objects.get(pk=id)

    if page:
        next_sibling_page = page.get_next_sibling()
        if next_sibling_page:
            page.move_to(next_sibling_page, position='right')

    return HttpResponseRedirect('../../')


@staff_member_required
def pages_json(request):
    """
Returns page tree as json. The data is suitable for jqtree.
"""
    return HttpResponse(
        simplejson.dumps(
            Page.objects.create_jqtree_data()
        )
    )
Something went wrong with that request. Please try again.