From 462d1e61309427baf820d897156b7d0dce1cad9b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 11 Mar 2010 23:18:40 +0200 Subject: [PATCH] - Merged adminmenu and account. - Added "Add Page" to menu. - Added "New Page" page. --- scribeengine/config/routing.py | 2 + scribeengine/controllers/blog.py | 2 +- scribeengine/controllers/page.py | 75 ++++++++++++++++++++++ scribeengine/lib/base.py | 2 +- scribeengine/templates/base.mako | 7 -- scribeengine/templates/page/new.mako | 22 +++++++ scribeengine/templates/page/view.mako | 12 ++++ scribeengine/templates/sidebar.mako | 20 ++++++ scribeengine/tests/functional/test_page.py | 7 ++ 9 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 scribeengine/controllers/page.py create mode 100644 scribeengine/templates/page/new.mako create mode 100644 scribeengine/templates/page/view.mako create mode 100644 scribeengine/tests/functional/test_page.py diff --git a/scribeengine/config/routing.py b/scribeengine/config/routing.py index 3837749..634fd0d 100644 --- a/scribeengine/config/routing.py +++ b/scribeengine/config/routing.py @@ -50,6 +50,8 @@ def make_map(): map.connect('/search', controller='blog', action='search') map.connect('/tag/{id}', controller='blog', action='tag') map.connect('/calendar/{year}/{month}', controller='blog', action='calendar') + map.connect('/page/new', controller='page', action='new') + map.connect('/{url}', controller='page', action='view') map.connect('/{controller}') map.connect('/{controller}/{action}') diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index da389c3..7b610d2 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -172,7 +172,7 @@ class BlogController(BaseController): #c.calendar = Calendar(6) #c.today = datetime.today() server_tz = timezone(config.get(u'server.timezone', u'UTC')) - user_tz = c.current_user.timezone if c.current_user.timezone else u'UTC' + user_tz = c.current_user.timezone if c.current_user and c.current_user.timezone else u'UTC' now = datetime.now(server_tz).astimezone(timezone(user_tz)) c.thismonth = now.replace(int(year), int(month)) c.prev_month = c.thismonth - monthdelta(1) diff --git a/scribeengine/controllers/page.py b/scribeengine/controllers/page.py new file mode 100644 index 0000000..d5ef804 --- /dev/null +++ b/scribeengine/controllers/page.py @@ -0,0 +1,75 @@ +# -*- 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)\ + .filter_by(status=u'published')\ + .first() + 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'post-title'] + page.body = c.form_values[u'post-body'] + page.url = url + Session.add(page) + Session.commit() + h.redirect_to('/' + str(page.url)) diff --git a/scribeengine/lib/base.py b/scribeengine/lib/base.py index e20f8f6..0071e79 100644 --- a/scribeengine/lib/base.py +++ b/scribeengine/lib/base.py @@ -59,7 +59,7 @@ class BaseController(WSGIController): c.pages = Session.query(Page).all() c.calendar = Calendar(6) server_tz = timezone(config.get(u'server.timezone', u'UTC')) - user_tz = c.current_user.timezone if c.current_user.timezone else u'UTC' + user_tz = c.current_user.timezone if c.current_user and c.current_user.timezone else u'UTC' c.today = datetime.now(server_tz).astimezone(timezone(user_tz)) if not c.thismonth: c.thismonth = c.today #datetime.utcnow().astimezone(timezone(c.current_user.timezone)) diff --git a/scribeengine/templates/base.mako b/scribeengine/templates/base.mako index e81957c..c9bb25c 100644 --- a/scribeengine/templates/base.mako +++ b/scribeengine/templates/base.mako @@ -32,14 +32,7 @@
  • ${page.name}
  • % endfor % if c.current_user: -% if c.current_user.has_permission('Add Posts'): -
  • New Post
  • -
  • Draft Posts
  • -% endif -
  • Logout
  • Logged in as ${c.current_user.nick}
  • -% else: -
  • Login
  • % endif diff --git a/scribeengine/templates/page/new.mako b/scribeengine/templates/page/new.mako new file mode 100644 index 0000000..fb32062 --- /dev/null +++ b/scribeengine/templates/page/new.mako @@ -0,0 +1,22 @@ +<%inherit file="/base.mako"/> + <%include file="/flash.mako"/> +
    +

    New Page

    + <%include file="/errors.mako"/> +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    diff --git a/scribeengine/templates/page/view.mako b/scribeengine/templates/page/view.mako new file mode 100644 index 0000000..c2b2281 --- /dev/null +++ b/scribeengine/templates/page/view.mako @@ -0,0 +1,12 @@ +<%inherit file="/base.mako"/> + <%include file="/flash.mako"/> +
    +% if c.current_user and c.current_user.id == c.page.user.id and c.current_user.has_permission(u'Edit My Pages'): +

    ${c.page.title} [Edit]

    +% else: +

    ${c.page.title}

    +% endif +
    + ${h.literal(c.page.body)} +
    +
    diff --git a/scribeengine/templates/sidebar.mako b/scribeengine/templates/sidebar.mako index 27243e6..04283a2 100644 --- a/scribeengine/templates/sidebar.mako +++ b/scribeengine/templates/sidebar.mako @@ -25,6 +25,26 @@ % endif +
  • +

    Account

    + +
  •  
    diff --git a/scribeengine/tests/functional/test_page.py b/scribeengine/tests/functional/test_page.py new file mode 100644 index 0000000..08c7e76 --- /dev/null +++ b/scribeengine/tests/functional/test_page.py @@ -0,0 +1,7 @@ +from scribeengine.tests import * + +class TestPageController(TestController): + + def test_index(self): + response = self.app.get(url(controller='page', action='index')) + # Test response...