diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index 39660e8..5836952 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -62,24 +62,40 @@ class BlogController(BaseController): 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') + c.datestring = start_date.strftime('%d %B %Y') + if c.datestring[0] == u'0': + c.datestring = c.datestring[1:] 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') + c.datestring = 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') + c.datestring = start_date.strftime('%Y') else: start_date = None end_date = None - c.posts = Session.query(Post) + c.datestring = u'all time' + c.page_title = u'Archive for %s.' % c.datestring + posts = Session.query(Post) if start_date and end_date: - c.posts = c.posts\ + posts = posts\ .filter(Post.created >= start_date)\ .filter(Post.created <= end_date) - c.posts = c.posts.order_by(Post.created.desc()).all() + posts = posts.order_by(Post.created.desc()) + pagination = utils.paginate(posts, 10, + int(request.GET.get(u'page', 1)), '/') + c.posts = pagination[u'records'] + if pagination[u'prev'] != pagination[u'page']: + c.first_page = pagination[u'first'] + c.prev_page = pagination[u'prev'] + if pagination[u'next'] != pagination[u'page']: + c.next_page = pagination[u'next'] + c.last_page = pagination[u'last'] + c.list_start = pagination[u'start'] + c.list_total = pagination[u'total'] + c.list_end = pagination[u'end'] return render(u'/blog/archive.mako') def view(self, url): diff --git a/scribeengine/lib/base.py b/scribeengine/lib/base.py index 339b356..d166a30 100644 --- a/scribeengine/lib/base.py +++ b/scribeengine/lib/base.py @@ -27,7 +27,7 @@ Provides the BaseController class for subclassing. """ from calendar import Calendar -from datetime import datetime +from datetime import datetime, timedelta from decorator import decorator import logging @@ -38,11 +38,12 @@ from pylons.controllers import WSGIController from pylons.templating import render_mako from sqlalchemy.sql.expression import asc, desc from formencode import Schema, Invalid +from monthdelta import monthdelta from scribeengine.lib import helpers as h from scribeengine.lib.validation import jsvalidate from scribeengine.model.meta import Session -from scribeengine.model import Variable, User, Category, Page +from scribeengine.model import Variable, User, Category, Page, Post log = logging.getLogger(__name__) @@ -59,6 +60,19 @@ class BaseController(WSGIController): c.today = datetime.today() if not c.thismonth: c.thismonth = datetime.now() + c.prev_month = c.thismonth - monthdelta(1) + c.next_month = c.thismonth + monthdelta(1) + month_start = datetime(c.thismonth.year, c.thismonth.month, 1, 0, 0, 0, 0) + month_end = c.next_month.replace(day=1, hour=23, minute=59, second=59, microsecond=9999) - timedelta(seconds=1) + posts = Session.query(Post)\ + .filter(Post.created >= month_start)\ + .filter(Post.created <= month_end)\ + .all() + c.month_posts = {} + for post in posts: + if post.created.day not in c.month_posts: + c.month_posts[post.created.day] = [] + c.month_posts[post.created.day].append(post) self._add_javascript(u'jquery.js') if c.jsvalidation: self._add_javascript(u'jquery.validate.js') diff --git a/scribeengine/public/styles/style.css b/scribeengine/public/styles/style.css index 2b8bf64..8a3f11a 100644 --- a/scribeengine/public/styles/style.css +++ b/scribeengine/public/styles/style.css @@ -339,6 +339,10 @@ hr { background: #111111; } +#calendar tbody td#today { + background: #333333; +} + #calendar a { text-decoration: none; font-weight: bold; diff --git a/scribeengine/templates/blog/archive.mako b/scribeengine/templates/blog/archive.mako new file mode 100644 index 0000000..993f363 --- /dev/null +++ b/scribeengine/templates/blog/archive.mako @@ -0,0 +1,29 @@ +<%inherit file="/base.mako"/> + <%include file="/flash.mako"/> +

Archives for ${c.datestring}

+ <%include file="/pagination.mako"/> +% for post in c.posts: +
+

${post.title}

+
+ ${h.literal(h.teaser(post.body))} +
+

+ + Read more +% if len(post.comments) == 0: + No comments +% elif len(post.comments) == 1: + 1 comment +% else: + ${len(post.comments)} comments +% endif +

+
+% endfor + <%include file="/pagination.mako"/> diff --git a/scribeengine/templates/calendar.mako b/scribeengine/templates/calendar.mako index 76d5975..5416e96 100644 --- a/scribeengine/templates/calendar.mako +++ b/scribeengine/templates/calendar.mako @@ -15,9 +15,9 @@ - « Oct + « ${c.prev_month.strftime('%b')}   - Dec » + ${c.next_month.strftime('%b')} » @@ -27,10 +27,18 @@ % if day == 0:   % elif day == c.today.day: +% if day in c.month_posts and len(c.month_posts[day]) > 0: + ${day} +% else: ${day} +% endif +% else: +% if day in c.month_posts and len(c.month_posts[day]) > 0: + ${day} % else: ${day} % endif +% endif % endfor % endfor diff --git a/setup.py b/setup.py index b630fab..4342c9f 100644 --- a/setup.py +++ b/setup.py @@ -25,9 +25,10 @@ setup( author_email='', url='', install_requires=[ - "Pylons>=0.9.7", - "SQLAlchemy>=0.5", - "TurboMail>=3.0" + "Pylons==0.9.7", + "SQLAlchemy>=0.5,<0.6", + "TurboMail>=3.0,<3.1", + "MonthDelta>=0.9,<0.10" ], setup_requires=["PasteScript>=1.6.3"], packages=find_packages(exclude=['ez_setup']),