AJAX-driven Calendar Widget
This commit is contained in:
commit
85f1515f82
@ -47,10 +47,9 @@ def make_map():
|
||||
map.connect('/archive/{year}/{month}', controller='blog', action='archive')
|
||||
map.connect('/archive/{year}/{month}/{day}', controller='blog', action='archive')
|
||||
map.connect('/archive/{year}/{month}/{day}/{url}', controller='blog', action='view')
|
||||
|
||||
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('/{controller}/{action}')
|
||||
map.connect('/{controller}/{action}/{id}')
|
||||
|
@ -167,3 +167,22 @@ class BlogController(BaseController):
|
||||
c.page_title = u'Search'
|
||||
return render(u'/blog/search.mako')
|
||||
|
||||
def calendar(self, year, month):
|
||||
#c.calendar = Calendar(6)
|
||||
#c.today = datetime.today()
|
||||
c.thismonth = datetime.now().replace(int(year), int(month))
|
||||
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)
|
||||
return render(u'/calendar.mako')
|
||||
|
||||
|
@ -160,6 +160,18 @@ ScribeEngine.Namespace.create("ScribeEngine.General", {
|
||||
{
|
||||
$(".jshidden").hide();
|
||||
},
|
||||
/**
|
||||
* Go to a particular month or year on the calendar.
|
||||
*/
|
||||
go_to_month: function (e)
|
||||
{
|
||||
var link = ScribeEngine.Events.getElement(e);
|
||||
$("#calendar_wrap").load(link.attr("href"), function() {
|
||||
ScribeEngine.Events.click("#next a", ScribeEngine.General.go_to_month);
|
||||
ScribeEngine.Events.click("#prev a", ScribeEngine.General.go_to_month);
|
||||
});
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* Do all the funny things required to toggle a fieldset
|
||||
*/
|
||||
@ -190,18 +202,6 @@ ScribeEngine.Namespace.create("ScribeEngine.General", {
|
||||
$ScribeEngine.General.perform_toggle(fieldset);
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* Sets the active project
|
||||
*/
|
||||
set_project: function ()
|
||||
{
|
||||
$('#project-selector > div.content').hide();
|
||||
$('#project-throbber').show();
|
||||
project_id = $("#CurrentProject").val();
|
||||
$.get('/dashboard/ajax_project/' + project_id, function () {
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Initialises collapsible fieldsets
|
||||
*/
|
||||
@ -234,4 +234,6 @@ ScribeEngine.Namespace.create("ScribeEngine.General", {
|
||||
* This function below will be executed on all page views.
|
||||
*/
|
||||
ScribeEngine.Events.load(function () {
|
||||
ScribeEngine.Events.click("#next a", ScribeEngine.General.go_to_month);
|
||||
ScribeEngine.Events.click("#prev a", ScribeEngine.General.go_to_month);
|
||||
});
|
||||
|
@ -15,9 +15,9 @@
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<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 abbr="${c.prev_month.strftime('%B')}" colspan="3" id="prev"><a href="/calendar/${c.prev_month.strftime('%Y/%m')}" title="View posts for ${c.prev_month.strftime('%B %Y')}">« ${c.prev_month.strftime('%b')}</a></td>
|
||||
<td class="pad"> </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>
|
||||
<td abbr="${c.next_month.strftime('%B')}" colspan="3" id="next"><a href="/calendar/${c.next_month.strftime('%Y/%m')}" title="View posts for ${c.next_month.strftime('%B %Y')}">${c.next_month.strftime('%b')} »</a></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
|
Reference in New Issue
Block a user