From 686a585b03ffd693a04c3fccd0eac05592afbf72 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 21 Jan 2011 21:14:46 +0530 Subject: [PATCH] page --- pandora/app/models.py | 1 + pandora/app/views.py | 45 ++++++++++++++++++++++++++++++++++++++++-- pandora/item/models.py | 1 - 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/pandora/app/models.py b/pandora/app/models.py index 752c0bb3..3b70e5cd 100644 --- a/pandora/app/models.py +++ b/pandora/app/models.py @@ -6,6 +6,7 @@ from django.db import models from django.conf import settings from ox.utils import json + class Page(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) diff --git a/pandora/app/views.py b/pandora/app/views.py index 6779fe3c..e3f6fb08 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -5,6 +5,8 @@ from django.template import RequestContext from django.conf import settings from ox.django.shortcuts import json_response, render_to_json_response, get_object_or_404_json +from ox.django.decorators import login_required_json + from ox.utils import json import models @@ -33,14 +35,53 @@ def timeline(request): def getPage(request): + ''' + param data { + name: pagename + } + return { + status: ... + data: { + name: + body: + } + } + ''' data = json.loads(request.POST['data']) - name = data['page'] - page = get_object_or_404_json(models.Archive, name=name) + name = data['name'] + page = get_object_or_404_json(models.Page, name=name) response = json_response({'name': page.name, 'body': page.body}) return render_to_json_response(response) actions.register(getPage) +@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) + + def site_json(request): ''' return render_to_json_response(siteJson()) diff --git a/pandora/item/models.py b/pandora/item/models.py index 53aafcbf..6d3860f3 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -789,7 +789,6 @@ class Item(models.Model): if frame: icon = self.path('icon.jpg') self.icon.name = icon - frame = frames[int(len(frames)/2)] timeline = self.path('timeline.64.png') timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline)) if os.path.exists(timeline):