From 86958bca41b8ef96b5108d74b8883aaed8384c4a Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 28 Feb 2010 23:15:33 +0200 Subject: [PATCH] Added AJAX previous and next links on the calendar. --- scribeengine/config/routing.py | 3 +-- scribeengine/controllers/blog.py | 19 +++++++++++++++ scribeengine/public/scripts/ScribeEngine.js | 26 +++++++++++---------- scribeengine/templates/calendar.mako | 4 ++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/scribeengine/config/routing.py b/scribeengine/config/routing.py index 87c4ec7..a5cbf09 100644 --- a/scribeengine/config/routing.py +++ b/scribeengine/config/routing.py @@ -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}') diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index 5836952..774c05f 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -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') + diff --git a/scribeengine/public/scripts/ScribeEngine.js b/scribeengine/public/scripts/ScribeEngine.js index fa84f37..4e1e3c9 100644 --- a/scribeengine/public/scripts/ScribeEngine.js +++ b/scribeengine/public/scripts/ScribeEngine.js @@ -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); }); diff --git a/scribeengine/templates/calendar.mako b/scribeengine/templates/calendar.mako index 5416e96..dc77a42 100644 --- a/scribeengine/templates/calendar.mako +++ b/scribeengine/templates/calendar.mako @@ -15,9 +15,9 @@ - « ${c.prev_month.strftime('%b')} + « ${c.prev_month.strftime('%b')}   - ${c.next_month.strftime('%b')} » + ${c.next_month.strftime('%b')} »