73 lines
3.4 KiB
Python
73 lines
3.4 KiB
Python
|
# -*- 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
|
||
|
|
||
|
from scribeengine.lib.base import *
|
||
|
from scribeengine.lib import utils
|
||
|
from scribeengine.model import Post
|
||
|
from scribeengine.model.meta import Session
|
||
|
|
||
|
log = logging.getLogger(__name__)
|
||
|
|
||
|
class BlogController(BaseController):
|
||
|
|
||
|
def index(self):
|
||
|
c.posts = Session.query(Post)\
|
||
|
.filter_by(status=u'published')\
|
||
|
.order_by(Post.created.desc())\
|
||
|
.all()
|
||
|
return render(u'/blog/index.mako')
|
||
|
|
||
|
def archive(self, year=None, month=None, day=None):
|
||
|
if day and month and year:
|
||
|
start_date = datetime(int(year), int(month), int(day), 0, 0, 0, 0)
|
||
|
end_date = datetime(int(year), int(month), int(day), 23, 59, 59, 99999)
|
||
|
c.page_title = u'Archive: %s' % start_date.strftime('%d %B %Y')
|
||
|
elif month and year and not day:
|
||
|
start_date = utils.month_first_day(datetime(int(year), int(month), 1))
|
||
|
end_date = utils.month_last_day(datetime(int(year), int(month), 1))
|
||
|
c.page_title = u'Archive: %s' % start_date.strftime('%B %Y')
|
||
|
elif year and not month:
|
||
|
start_date = datetime(int(year), 1, 1, 0, 0, 0, 0)
|
||
|
end_date = datetime(int(year), 12, 31, 23, 59, 59, 99999)
|
||
|
c.page_title = u'Archive: %s' % start_date.strftime('%Y')
|
||
|
else:
|
||
|
start_date = None
|
||
|
end_date = None
|
||
|
c.posts = Session.query(Post)
|
||
|
if start_date and end_date:
|
||
|
c.posts = c.posts\
|
||
|
.filter(Post.created >= start_date)\
|
||
|
.filter(Post.created <= end_date)
|
||
|
c.posts = c.posts.order_by(Post.created.desc()).all()
|
||
|
return render(u'/blog/archive.mako')
|
||
|
|
||
|
def view(self, url):
|
||
|
c.post = Session.query(Post)\
|
||
|
.filter_by(url=url)\
|
||
|
.filter_by(status=u'published')\
|
||
|
.first()
|
||
|
c.page_title = c.post.title
|
||
|
return render(u'/blog/view.mako')
|