meblog / pages /

# Django module
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, Http404
from django.template import RequestContext
from django.conf import settings

# App module
from pages import models
from pageform import PageForm
from contactform import ContactForm

# Appengine module
from google.appengine.api import memcache
from google.appengine.api import mail


def render(request, name):
    page = models.Page.get_by_key_name(name)
    if page:
        return render_to_response('pages/'+page.template, {'page':page},
        raise Http404

def listPages(request):
    if request.GET.get('page'):
        page = int(request.GET.get('page'))
        page = 1

    offset = PAGESIZE *(page - 1)

    if memcache.get('pagespage-'+str(page)):
        pages = memcache.get('pagespage-'+str(page))
        pages = models.Page.all().fetch(PAGESIZE, offset)
        memcache.set('pagespage-'+str(page), pages)

    # check if there is next page
    offset = PAGESIZE *(page)
    next_page = models.Page.all().fetch(PAGESIZE, offset)
    if next_page:
        p_next = page + 1
        p_next = None

    paging = {'prev': page - 1, 'next':p_next}

    return render_to_response('admin/pagelist.html', {'pages':pages,

def newPage(request):
    pageForm = None
    if request.method == 'POST':
        newPage = PageForm(request.POST)
        if newPage.is_valid():
            return HttpResponseRedirect('/pages/')
            pageForm = PageForm(request.POST)

    if pageForm is None:
        pageForm = PageForm()

    return render_to_response('admin/newpage.html', {

def editPage(request, key_name):
    pageForm = None
    if request.method == 'POST':
        form = PageForm(request.POST)
        page = page = models.Page.get_by_key_name(key_name.replace('-',' '))
        if form.is_valid():
            return HttpResponseRedirect('/pages/')
            pageForm = PageForm(request.POST)

    if pageForm is None:
        page = models.Page.get_by_key_name(key_name.replace('-',' '))
        if page:
            pageForm = PageForm(initial={'name',
    return render_to_response('admin/newpage.html', {'pageForm':pageForm,

def delPage(request, key_name):
    page = models.Page.get_by_key_name(key_name.replace('-',' '))
    if page:
    return HttpResponseRedirect('/pages/')

def contact(request):
    form = None
    msg = None
    if request.method == 'POST':
        newMessage = ContactForm(request.POST)
        if newMessage.is_valid():
            data = newMessage.cleaned_data
            #send message
            mail.send_mail(sender=" <>",
                              to="Hudarsono <>",
                              subject="New Message from "+data['name'],
                              body="Sender Email : "+data['email']+"\n Message : "+data['message'])

            msg = 'Thanks for your message, will get back to you soon.'
            form = ContactForm(request.POST)

    if form is None: form = ContactForm()

    return render_to_response('pages/contact.html', {'form':form, 'msg':msg},
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.