2009-10-04 22:00:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2011-01-01 11:44:42 +00:00
|
|
|
from django.shortcuts import render_to_response
|
2009-10-04 22:00:08 +00:00
|
|
|
from django.template import RequestContext
|
2009-10-04 23:48:18 +00:00
|
|
|
from django.conf import settings
|
2009-10-04 22:00:08 +00:00
|
|
|
|
2010-11-23 09:53:12 +00:00
|
|
|
from ox.django.shortcuts import json_response, render_to_json_response, get_object_or_404_json
|
2011-01-21 15:44:46 +00:00
|
|
|
from ox.django.decorators import login_required_json
|
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
from ox.utils import json
|
2010-02-10 13:10:14 +00:00
|
|
|
|
|
|
|
import models
|
2009-10-04 22:00:08 +00:00
|
|
|
|
2010-12-22 07:45:37 +00:00
|
|
|
from api.actions import actions
|
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-08-24 17:16:33 +00:00
|
|
|
def intro(request):
|
2011-01-01 11:44:42 +00:00
|
|
|
context = RequestContext(request, {'settings': settings})
|
2010-08-24 17:16:33 +00:00
|
|
|
return render_to_response('intro.html', context)
|
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2009-10-04 22:00:08 +00:00
|
|
|
def index(request):
|
2011-01-01 11:44:42 +00:00
|
|
|
context = RequestContext(request, {'settings': settings})
|
2009-10-04 22:00:08 +00:00
|
|
|
return render_to_response('index.html', context)
|
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2011-01-04 06:03:00 +00:00
|
|
|
def embed(request):
|
|
|
|
context = RequestContext(request, {'settings': settings})
|
|
|
|
return render_to_response('embed.html', context)
|
|
|
|
|
|
|
|
|
2010-09-08 11:56:58 +00:00
|
|
|
def timeline(request):
|
2011-01-01 11:44:42 +00:00
|
|
|
context = RequestContext(request, {'settings': settings})
|
2010-09-08 11:56:58 +00:00
|
|
|
return render_to_response('timeline.html', context)
|
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-12-22 07:45:37 +00:00
|
|
|
def getPage(request):
|
2011-01-21 15:44:46 +00:00
|
|
|
'''
|
|
|
|
param data {
|
|
|
|
name: pagename
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
status: ...
|
|
|
|
data: {
|
|
|
|
name:
|
|
|
|
body:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
2010-02-10 13:10:14 +00:00
|
|
|
data = json.loads(request.POST['data'])
|
2011-01-22 17:38:53 +00:00
|
|
|
if isinstance(data, basestring):
|
|
|
|
name = data
|
|
|
|
else:
|
|
|
|
name = data['name']
|
2011-01-21 15:44:46 +00:00
|
|
|
page = get_object_or_404_json(models.Page, name=name)
|
2010-02-10 13:10:14 +00:00
|
|
|
response = json_response({'name': page.name, 'body': page.body})
|
|
|
|
return render_to_json_response(response)
|
2010-12-22 07:45:37 +00:00
|
|
|
actions.register(getPage)
|
2010-02-10 13:10:14 +00:00
|
|
|
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2011-01-21 15:44:46 +00:00
|
|
|
@login_required_json
|
|
|
|
def editPage(request):
|
|
|
|
'''
|
|
|
|
param data {
|
|
|
|
name: pagename
|
|
|
|
body: text
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
status: ...
|
|
|
|
data: {
|
|
|
|
name:
|
|
|
|
body:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
if not request.user.is_staff:
|
|
|
|
response = json_response(status=403, text='permission denied')
|
|
|
|
return render_to_json_response(response)
|
|
|
|
data = json.loads(request.POST['data'])
|
|
|
|
page, created = models.Page.objects.get_or_create(name=data['name'])
|
|
|
|
page.body = data['body']
|
|
|
|
page.save()
|
|
|
|
response = json_response({'name': page.name, 'page': page.body})
|
|
|
|
return render_to_json_response(response)
|
|
|
|
actions.register(getPage)
|
|
|
|
|