From f606ee998d60cdec9b993451b334d1f33c95c4ab Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 10 Feb 2010 18:40:14 +0530 Subject: [PATCH] add js pages --- oxdb/app/models.py | 10 ++++++++++ oxdb/app/views.py | 18 ++++++++++++++++-- oxdb/settings.py | 1 + oxdb/templates/site.js | 5 +++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/oxdb/app/models.py b/oxdb/app/models.py index 71a8362..ce8d17d 100644 --- a/oxdb/app/models.py +++ b/oxdb/app/models.py @@ -1,3 +1,13 @@ from django.db import models # Create your models here. + + +class Page(models.Model): + created = models.DateTimeField(auto_now_add=True) + modified = models.DateTimeField(auto_now=True) + name = models.CharField(max_length=1024, unique=True) + body = models.TextField(blank=True) + + def __unicode__(self): + return self.name diff --git a/oxdb/app/views.py b/oxdb/app/views.py index a23851c..640d1dd 100644 --- a/oxdb/app/views.py +++ b/oxdb/app/views.py @@ -4,11 +4,25 @@ from django.shortcuts import render_to_response, get_object_or_404, get_list_or_ from django.template import RequestContext from django.conf import settings +from oxdjango.shortcuts import json_response, render_to_json_response, get_object_or_404_json + +import models def index(request): context = RequestContext(request, {'settings':settings}) return render_to_response('index.html', context) -def site_js(request): - context = RequestContext(request, {'settings':settings}) +def api_getPage(request): + data = json.loads(request.POST['data']) + name = data['page'] + page = get_object_or_404_json(models.Archive, name=name) + response = json_response({'name': page.name, 'body': page.body}) + return render_to_json_response(response) + + return render_to_response('site.js', context, mimetype="application/javascript") + + +def site_js(request): + pages = models.Page.objects.all() + context = RequestContext(request, {'settings':settings, 'pages': pages}) return render_to_response('site.js', context, mimetype="application/javascript") diff --git a/oxdb/settings.py b/oxdb/settings.py index 7970e06..3c39c06 100644 --- a/oxdb/settings.py +++ b/oxdb/settings.py @@ -105,6 +105,7 @@ INSTALLED_APPS = ( 'devserver', # 'south', + 'app', 'backend', 'oxuser', ) diff --git a/oxdb/templates/site.js b/oxdb/templates/site.js index 0aa91ca..03e14a6 100644 --- a/oxdb/templates/site.js +++ b/oxdb/templates/site.js @@ -1,3 +1,8 @@ var site = {}; site.url = "{{settings.URL}}"; site.name = "{{settings.SITENAME}}"; + +site.pages = {}; +{% for page in pages %} +site.pages['{{page.name}}'] = '{{page.body|escapejs}}'; +{% endfor %}