Step one in the calendar widget.
This commit is contained in:
parent
9012aff1de
commit
d015214ba4
@ -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):
|
||||
|
@ -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')
|
||||
|
@ -339,6 +339,10 @@ hr {
|
||||
background: #111111;
|
||||
}
|
||||
|
||||
#calendar tbody td#today {
|
||||
background: #333333;
|
||||
}
|
||||
|
||||
#calendar a {
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
|
29
scribeengine/templates/blog/archive.mako
Normal file
29
scribeengine/templates/blog/archive.mako
Normal file
@ -0,0 +1,29 @@
|
||||
<%inherit file="/base.mako"/>
|
||||
<%include file="/flash.mako"/>
|
||||
<h2 class="title">Archives for ${c.datestring}</h2>
|
||||
<%include file="/pagination.mako"/>
|
||||
% for post in c.posts:
|
||||
<div class="post">
|
||||
<h2 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h2>
|
||||
<div class="entry">
|
||||
${h.literal(h.teaser(post.body))}
|
||||
</div>
|
||||
<p class="meta">
|
||||
<span class="byline">
|
||||
Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}
|
||||
% if c.current_user and c.current_user.id == post.user.id and c.current_user.has_permission(u'Edit My Posts'):
|
||||
[<a href="${h.url_for(controller=u'post', action=u'edit', id=post.id)}">Edit</a>]
|
||||
% endif
|
||||
</span>
|
||||
<a href="${h.url_for_post(post)}" class="read-more">Read more</a>
|
||||
% if len(post.comments) == 0:
|
||||
<a href="${h.url_for_post(post)}#comments" class="comments">No comments</a>
|
||||
% elif len(post.comments) == 1:
|
||||
<a href="${h.url_for_post(post)}#comments" class="comments">1 comment</a>
|
||||
% else:
|
||||
<a href="${h.url_for_post(post)}#comments" class="comments">${len(post.comments)} comments</a>
|
||||
% endif
|
||||
</p>
|
||||
</div>
|
||||
% endfor
|
||||
<%include file="/pagination.mako"/>
|
@ -15,9 +15,9 @@
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td abbr="October" colspan="3" id="prev"><a href="#" title="View posts for October 2007">« Oct</a></td>
|
||||
<td abbr="${c.prev_month.strftime('%B')}" colspan="3" id="prev"><a href="#" title="View posts for ${c.prev_month.strftime('%B %Y')}">« ${c.prev_month.strftime('%b')}</a></td>
|
||||
<td class="pad"> </td>
|
||||
<td abbr="December" colspan="3" id="next"><a href="#" title="View posts for October 2007">Dec »</a></td>
|
||||
<td abbr="${c.next_month.strftime('%B')}" colspan="3" id="next"><a href="#" title="View posts for ${c.next_month.strftime('%B %Y')}">${c.next_month.strftime('%b')} »</a></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
@ -27,10 +27,18 @@
|
||||
% if day == 0:
|
||||
<td class="pad"> </td>
|
||||
% elif day == c.today.day:
|
||||
% if day in c.month_posts and len(c.month_posts[day]) > 0:
|
||||
<td id="today"><a href="${h.url_for(controller='blog', action='archive', year=c.thismonth.year, month=c.thismonth.month, day=day)}">${day}</a></td>
|
||||
% else:
|
||||
<td id="today">${day}</td>
|
||||
% endif
|
||||
% else:
|
||||
% if day in c.month_posts and len(c.month_posts[day]) > 0:
|
||||
<td><a href="${h.url_for(controller='blog', action='archive', year=c.thismonth.year, month=c.thismonth.month, day=day)}">${day}</a></td>
|
||||
% else:
|
||||
<td>${day}</td>
|
||||
% endif
|
||||
% endif
|
||||
% endfor
|
||||
</tr>
|
||||
% endfor
|
||||
|
7
setup.py
7
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']),
|
||||
|
Reference in New Issue
Block a user