Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (58 sloc) 2.103 kb
f83d0d3 Updated django simplejson to python json.
Niels van Dijk authored
1 import json
2
dc32df0 @mvdwaeter Cleaned up code of Fiber admin
mvdwaeter authored
3 from django.contrib.admin.views.decorators import staff_member_required
09f279a @dbunskoek Correctly reverse admin urls instead of relying on relative paths
dbunskoek authored
4 from django.core.urlresolvers import reverse
4ce0096 @ramonakira Add decorator to block non-POST requests on login
ramonakira authored
5 from django.views.decorators.http import require_POST
2aae1e2 @dbunskoek first commit
dbunskoek authored
6 from django.contrib.auth import authenticate, login
7 from django.http import HttpResponse, HttpResponseRedirect
8 from django.utils.translation import ugettext as _
9
3416c75 @mvdwaeter Improved import statements, fixes issue #46
mvdwaeter authored
10 from .models import Page
2aae1e2 @dbunskoek first commit
dbunskoek authored
11
12
4ce0096 @ramonakira Add decorator to block non-POST requests on login
ramonakira authored
13 @require_POST
2aae1e2 @dbunskoek first commit
dbunskoek authored
14 def fiber_login(request):
15 username = request.POST['username']
16 password = request.POST['password']
17 user = authenticate(username=username, password=password)
18
19 result = {}
20 if user is not None:
21 if user.is_active:
22 login(request, user)
23 result = {
24 'status': 'success',
25 }
26 else:
27 result = {
28 'status': 'inactive',
29 'message': _('This account is inactive.'),
30 }
31 else:
32 result = {
33 'status': 'failed',
34 'message': _('Please enter a correct username and password. Note that both fields are case-sensitive.'),
35 }
ab59c73 Fixed fiber_login view local variable name collision.
Niels van Dijk authored
36 json_reponse = json.dumps(result)
a41b476 @cscheng Fixed login issue with Django 1.7
cscheng authored
37 return HttpResponse(json_reponse, content_type='application/json')
2aae1e2 @dbunskoek first commit
dbunskoek authored
38
39
40 @staff_member_required
41 def page_move_up(request, id):
42 page = Page.objects.get(pk=id)
43
6e6ec7a @vdboor PIP8 fixes.
vdboor authored
44 if page:
2aae1e2 @dbunskoek first commit
dbunskoek authored
45 previous_sibling_page = page.get_previous_sibling()
6e6ec7a @vdboor PIP8 fixes.
vdboor authored
46 if previous_sibling_page:
2aae1e2 @dbunskoek first commit
dbunskoek authored
47 page.move_to(previous_sibling_page, position='left')
48
d7db26f @dbunskoek Forgot to add the reverse() call
dbunskoek authored
49 return HttpResponseRedirect(reverse('admin:fiber_page_changelist'))
2aae1e2 @dbunskoek first commit
dbunskoek authored
50
51
52 @staff_member_required
53 def page_move_down(request, id):
54 page = Page.objects.get(pk=id)
55
6e6ec7a @vdboor PIP8 fixes.
vdboor authored
56 if page:
2aae1e2 @dbunskoek first commit
dbunskoek authored
57 next_sibling_page = page.get_next_sibling()
6e6ec7a @vdboor PIP8 fixes.
vdboor authored
58 if next_sibling_page:
2aae1e2 @dbunskoek first commit
dbunskoek authored
59 page.move_to(next_sibling_page, position='right')
60
d7db26f @dbunskoek Forgot to add the reverse() call
dbunskoek authored
61 return HttpResponseRedirect(reverse('admin:fiber_page_changelist'))
25cd958 @mbraak Replace jstree with jqtree
mbraak authored
62
63
64 @staff_member_required
65 def pages_json(request):
66 """
67 Returns page tree as json. The data is suitable for jqtree.
68 """
69 return HttpResponse(
f83d0d3 Updated django simplejson to python json.
Niels van Dijk authored
70 json.dumps(
c5793bd @dbunskoek Tweaking and polishing
dbunskoek authored
71 Page.objects.create_jqtree_data(request.user)
25cd958 @mbraak Replace jstree with jqtree
mbraak authored
72 )
73 )
Something went wrong with that request. Please try again.