# -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 ############################################################################### # ScribeEngine - Open Source Blog Software # # --------------------------------------------------------------------------- # # Copyright (c) 2010 Raoul Snyman # # --------------------------------------------------------------------------- # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the Free # # Software Foundation; version 2 of the License. # # # # This program is distributed in the hope that it will be useful, but WITHOUT # # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # # more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import logging from datetime import datetime import time from scribeengine.lib.base import * from scribeengine.lib import utils from scribeengine.model import Page from scribeengine.model.meta import Session log = logging.getLogger(__name__) class PageController(BaseController): def index(self): h.redirect_to('/') def view(self, url): c.page = Session.query(Page)\ .filter_by(url=url)\ .first() #.filter_by(status=u'published')\ c.page_title = c.page.title return render(u'/page/view.mako') @authenticate(u'Add Pages') def new(self): c.page_title = u'New Page' return render(u'/page/new.mako') @authenticate(u'Edit My Pages') def edit(self, id=None): if id is None: h.redirect_to(h.url_for(controller=u'page', action=u'new')) c.page = Session.query(Page).get(id) c.page_title = u'Edit Page: %s' % c.page.title return render(u'/post/edit.mako') @authenticate(u'Edit My Pages') def edit_POST(self, id=None): url = utils.generate_url(c.form_values[u'page-title']) if id is None: page = Page() page.user = c.current_user page.created = datetime.now() else: page = Session.query(Page).get(id) page.modified = datetime.now() page.title = c.form_values[u'page-title'] page.body = c.form_values[u'page-body'] page.url = url Session.add(page) Session.commit() h.redirect_to('/' + str(page.url))