From cd1d8d6aeed2bbb04467074d20e89fd1819994e5 Mon Sep 17 00:00:00 2001 From: Eevee Date: Sun, 15 Aug 2010 00:30:50 -0700 Subject: [PATCH 1/1] Draw a line marking new stuff. #332 --- splinext/frontpage/controllers/frontpage.py | 31 ++++++++++++++++++++++ splinext/frontpage/templates/css/frontpage.mako | 2 ++ .../frontpage/templates/front_page/updates.mako | 10 +++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/splinext/frontpage/controllers/frontpage.py b/splinext/frontpage/controllers/frontpage.py index 0990e81..a77edb2 100644 --- a/splinext/frontpage/controllers/frontpage.py +++ b/splinext/frontpage/controllers/frontpage.py @@ -1,3 +1,4 @@ +import datetime import logging from pylons import config, request, response, session, tmpl_context as c, url @@ -7,6 +8,7 @@ from sqlalchemy.orm.exc import NoResultFound from spline.lib import helpers as h from spline.lib.base import BaseController, render +from spline.model import meta from splinext.frontpage.sources import max_age_to_datetime log = logging.getLogger(__name__) @@ -66,6 +68,35 @@ class FrontPageController(BaseController): if updates and len(updates) == global_limit: global_max_age = updates[-1].time + # Find the oldest unseen item, to draw a divider after it. + # If this stays as None, the divider goes at the top + c.last_seen_item = None + # Could have a timestamp in the stash if this is a user, or in a cookie + # if this session has ever been logged out... + times = [] + for source in (c.user.stash, request.cookies): + try: + times.append( int(source['frontpage-last-seen-time']) ) + except (KeyError, ValueError): + pass + last_seen_time = datetime.datetime.fromtimestamp(max(times)) + + if last_seen_time: + for update in updates: + if update.time > last_seen_time: + c.last_seen_item = update + else: + break + + # Save ~now~ as the last-seen time + now = datetime.datetime.now().strftime('%s') + if c.user: + c.user.stash['frontpage-last-seen-time'] = now + meta.Session.add(c.user) + meta.Session.commit() + else: + response.set_cookie('frontpage-last-seen-time', now) + # Done! Feed to template c.updates = updates diff --git a/splinext/frontpage/templates/css/frontpage.mako b/splinext/frontpage/templates/css/frontpage.mako index 8f4718f..2374f72 100644 --- a/splinext/frontpage/templates/css/frontpage.mako +++ b/splinext/frontpage/templates/css/frontpage.mako @@ -1,3 +1,5 @@ +.frontpage-new-stuff { height: 16px; margin: 0.25em 0; padding: 0; border: none; background: url(${h.static_uri('spline', '/icons/new-text.png')}) center center repeat-x; } + .frontpage-update { position: relative; overflow: auto; margin: 1em 0; background: #f4f4f4; -moz-border-radius: 1em; -webkit-border-radius: 1em; } .frontpage-update:nth-child(2n) { background: #f0f0f0; } .frontpage-update .header { white-space: nowrap; padding: 0.5em 1em; border: 1px solid #b4c7e6; background: url(${h.static_uri('local', 'images/layout/th-background.png')}) left bottom repeat-x; -moz-border-radius-topleft: 1em; -moz-border-radius-topright: 1em; -webkit-border-top-left-radius: 0.5em; -webkit-border-top-right-radius: 0.5em; } diff --git a/splinext/frontpage/templates/front_page/updates.mako b/splinext/frontpage/templates/front_page/updates.mako index 9a6f584..257f0dd 100644 --- a/splinext/frontpage/templates/front_page/updates.mako +++ b/splinext/frontpage/templates/front_page/updates.mako @@ -1,8 +1,14 @@ +% if c.updates and not c.last_seen_item: +
+% endif % for update in c.updates: -<%include file="${update.source.template}" args="update=update" /> + <%include file="${update.source.template}" args="update=update" /> + % if update == c.last_seen_item: +
+ % endif % endfor % if not c.updates: -

No updates.

+

No updates.

% endif

Sources:

-- 2.7.4