+import datetime
import logging
from pylons import config, request, response, session, tmpl_context as c, url
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__)
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
+.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; }
+% if c.updates and not c.last_seen_item:
+ <hr class="frontpage-new-stuff">
+% 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:
+ <hr class="frontpage-new-stuff">
+ % endif
% endfor
% if not c.updates:
-<p>No updates.</p>
+ <p>No updates.</p>
% endif
<p>Sources:</p>