- Merged adminmenu and account.

- Added "Add Page" to menu.
- Added "New Page" page.
This commit is contained in:
Raoul Snyman 2010-03-11 23:18:40 +02:00
parent ea72b9e6e6
commit 462d1e6130
9 changed files with 140 additions and 9 deletions

View File

@ -50,6 +50,8 @@ def make_map():
map.connect('/search', controller='blog', action='search') map.connect('/search', controller='blog', action='search')
map.connect('/tag/{id}', controller='blog', action='tag') map.connect('/tag/{id}', controller='blog', action='tag')
map.connect('/calendar/{year}/{month}', controller='blog', action='calendar') 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}')
map.connect('/{controller}/{action}') map.connect('/{controller}/{action}')

View File

@ -172,7 +172,7 @@ class BlogController(BaseController):
#c.calendar = Calendar(6) #c.calendar = Calendar(6)
#c.today = datetime.today() #c.today = datetime.today()
server_tz = timezone(config.get(u'server.timezone', u'UTC')) 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)) now = datetime.now(server_tz).astimezone(timezone(user_tz))
c.thismonth = now.replace(int(year), int(month)) c.thismonth = now.replace(int(year), int(month))
c.prev_month = c.thismonth - monthdelta(1) c.prev_month = c.thismonth - monthdelta(1)

View File

@ -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))

View File

@ -59,7 +59,7 @@ class BaseController(WSGIController):
c.pages = Session.query(Page).all() c.pages = Session.query(Page).all()
c.calendar = Calendar(6) c.calendar = Calendar(6)
server_tz = timezone(config.get(u'server.timezone', u'UTC')) 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)) c.today = datetime.now(server_tz).astimezone(timezone(user_tz))
if not c.thismonth: if not c.thismonth:
c.thismonth = c.today #datetime.utcnow().astimezone(timezone(c.current_user.timezone)) c.thismonth = c.today #datetime.utcnow().astimezone(timezone(c.current_user.timezone))

View File

@ -32,14 +32,7 @@
<li><a href="${page.url}">${page.name}</a></li> <li><a href="${page.url}">${page.name}</a></li>
% endfor % endfor
% if c.current_user: % if c.current_user:
% if c.current_user.has_permission('Add Posts'):
<li><a href="${h.url_for(controller=u'post', action=u'new')}">New Post</a></li>
<li><a href="${h.url_for(controller=u'post', action=u'draft')}">Draft Posts</a></li>
% endif
<li><a href="${h.url_for(controller=u'account', action=u'logout')}">Logout</a></li>
<li>Logged in as <em>${c.current_user.nick}</em></li> <li>Logged in as <em>${c.current_user.nick}</em></li>
% else:
<li><a href="${h.url_for(controller=u'account', action=u'login')}">Login</a></li>
% endif % endif
</ul> </ul>
</div> </div>

View File

@ -0,0 +1,22 @@
<%inherit file="/base.mako"/>
<%include file="/flash.mako"/>
<div class="page">
<h2 class="title">New Page</h2>
<%include file="/errors.mako"/>
<form id="page-new" action="${h.url_for('/page/edit')}" method="page">
<fieldset>
<div class="form-item">
<!-- <label for="page-title">Title:</label> -->
<input type="text" name="page-title" id="page-title" class="form-text" />
</div>
<div class="form-item">
<!-- <label for="page-body">Body:</label> -->
<textarea name="page-body" id="page-body" class="form-textarea"></textarea>
</div>
<div class="form-item">
<input type="submit" name="page-action" value="Save Draft" class="form-button"/>
<input type="submit" name="page-action" value="Save &amp; Publish" class="form-button"/>
</div>
</fieldset>
</form>
</div>

View File

@ -0,0 +1,12 @@
<%inherit file="/base.mako"/>
<%include file="/flash.mako"/>
<div class="page">
% if c.current_user and c.current_user.id == c.page.user.id and c.current_user.has_permission(u'Edit My Pages'):
<h2 class="title">${c.page.title} <span class="page-edit">[<a href="${h.url_for(controller=u'page', action=u'edit', id=c.page.id)}">Edit</a>]</span></h2>
% else:
<h2 class="title">${c.page.title}</h2>
% endif
<div class="entry">
${h.literal(c.page.body)}
</div>
</div>

View File

@ -25,6 +25,26 @@
</ul> </ul>
</li> </li>
% endif % endif
<li>
<h2>Account</h2>
<ul>
% if c.current_user:
<li><a href="${h.url_for(controller=u'account')}">My Account</a></li>
% if c.current_user.has_permission('Add Posts'):
<li><a href="${h.url_for(controller=u'post', action=u'new')}">New Post</a></li>
% endif
% if c.current_user.has_permission('Add Pages'):
<li><a href="${h.url_for(controller=u'page', action=u'new')}">New Page</a></li>
% endif
% if c.current_user.has_permission('Edit My Posts'):
<li><a href="${h.url_for(controller=u'post', action=u'draft')}">Draft Posts</a></li>
% endif
<li><a href="${h.url_for(controller=u'account', action=u'logout')}">Logout</a></li>
% else:
<li><a href="${h.url_for(controller=u'account', action=u'login')}">Login</a></li>
% endif
</ul>
</li>
</ul> </ul>
<div style="clear: both; height: 40px;">&nbsp;</div> <div style="clear: both; height: 40px;">&nbsp;</div>
</div> </div>

View File

@ -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...