mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Using timezone-aware relative dates (Today, Yesterdays).
This commit is contained in:
parent
0d3e904e35
commit
db74119842
4 changed files with 30 additions and 19 deletions
|
@ -607,8 +607,9 @@ def load_single_feed(request, feed_id):
|
|||
if not include_story_content:
|
||||
del story['story_content']
|
||||
story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, now)
|
||||
nowtz = localtime_for_timezone(now, user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date, nowtz)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, nowtz)
|
||||
if usersub:
|
||||
story['read_status'] = 1
|
||||
if (read_filter == 'all' or query) and usersub:
|
||||
|
@ -782,12 +783,13 @@ def load_starred_stories(request):
|
|||
comments=story.comments))
|
||||
for story in shared_stories])
|
||||
|
||||
nowtz = localtime_for_timezone(now, user.profile.timezone)
|
||||
for story in stories:
|
||||
story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, now)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date, nowtz)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, nowtz)
|
||||
starred_date = localtime_for_timezone(story['starred_date'], user.profile.timezone)
|
||||
story['starred_date'] = format_story_link_date__long(starred_date, now)
|
||||
story['starred_date'] = format_story_link_date__long(starred_date, nowtz)
|
||||
story['read_status'] = 1
|
||||
story['starred'] = True
|
||||
story['intelligence'] = {
|
||||
|
@ -939,6 +941,7 @@ def load_river_stories__redis(request):
|
|||
|
||||
|
||||
# Just need to format stories
|
||||
nowtz = localtime_for_timezone(now, user.profile.timezone)
|
||||
for story in stories:
|
||||
story['read_status'] = 0
|
||||
if read_filter == 'all':
|
||||
|
@ -946,8 +949,8 @@ def load_river_stories__redis(request):
|
|||
story['story_hash'] not in unread_feed_story_hashes):
|
||||
story['read_status'] = 1
|
||||
story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, now)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date, nowtz)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, nowtz)
|
||||
if story['story_hash'] in starred_stories:
|
||||
story['starred'] = True
|
||||
starred_date = localtime_for_timezone(starred_stories[story['story_hash']],
|
||||
|
|
|
@ -119,12 +119,13 @@ def load_social_stories(request, user_id, username=None):
|
|||
comments=story.comments))
|
||||
for story in shared_stories])
|
||||
|
||||
nowtz = localtime_for_timezone(now, user.profile.timezone)
|
||||
for story in stories:
|
||||
story['social_user_id'] = social_user_id
|
||||
# story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
|
||||
shared_date = localtime_for_timezone(story['shared_date'], user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(shared_date)
|
||||
story['long_parsed_date'] = format_story_link_date__long(shared_date)
|
||||
story['short_parsed_date'] = format_story_link_date__short(shared_date, nowtz)
|
||||
story['long_parsed_date'] = format_story_link_date__long(shared_date, nowtz)
|
||||
|
||||
story['read_status'] = 1
|
||||
if (read_filter == 'all' or query) and socialsub:
|
||||
|
@ -270,13 +271,14 @@ def load_river_blurblog(request):
|
|||
classifier_tags = []
|
||||
|
||||
# Just need to format stories
|
||||
nowtz = localtime_for_timezone(now, user.profile.timezone)
|
||||
for story in stories:
|
||||
story['read_status'] = 0
|
||||
if story['story_hash'] not in unread_feed_story_hashes:
|
||||
story['read_status'] = 1
|
||||
story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, now)
|
||||
story['short_parsed_date'] = format_story_link_date__short(story_date, nowtz)
|
||||
story['long_parsed_date'] = format_story_link_date__long(story_date, nowtz)
|
||||
if story['story_hash'] in starred_stories:
|
||||
story['starred'] = True
|
||||
starred_date = localtime_for_timezone(starred_stories[story['story_hash']], user.profile.timezone)
|
||||
|
@ -521,7 +523,9 @@ def mark_story_as_shared(request):
|
|||
source_user_id = request.POST.get('source_user_id')
|
||||
relative_user_id = request.POST.get('relative_user_id') or request.user.pk
|
||||
post_to_services = request.POST.getlist('post_to_services')
|
||||
format = request.REQUEST.get('format', 'json')
|
||||
format = request.REQUEST.get('format', 'json')
|
||||
now = datetime.datetime.now()
|
||||
nowtz = localtime_for_timezone(now, request.user.profile.timezone)
|
||||
|
||||
MSocialProfile.get_user(request.user.pk)
|
||||
|
||||
|
@ -576,8 +580,8 @@ def mark_story_as_shared(request):
|
|||
story['shared_by_user'] = True
|
||||
story['shared'] = True
|
||||
shared_date = localtime_for_timezone(shared_story['shared_date'], request.user.profile.timezone)
|
||||
story['short_parsed_date'] = format_story_link_date__short(shared_date)
|
||||
story['long_parsed_date'] = format_story_link_date__long(shared_date)
|
||||
story['short_parsed_date'] = format_story_link_date__short(shared_date, nowtz)
|
||||
story['long_parsed_date'] = format_story_link_date__long(shared_date, nowtz)
|
||||
|
||||
if post_to_services:
|
||||
for service in post_to_services:
|
||||
|
|
|
@ -19,7 +19,7 @@ gunicorn==0.17.2
|
|||
httplib2==0.8
|
||||
iconv==1.0
|
||||
kombu==2.5.7
|
||||
lxml==3.1.0
|
||||
# lxml==3.1.0
|
||||
mongoengine==0.8.2
|
||||
nltk==2.0.4
|
||||
oauth2==1.5.211
|
||||
|
|
|
@ -17,8 +17,10 @@ from vendor import reseekfile
|
|||
# COMMENTS_RE = re.compile('\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>')
|
||||
COMMENTS_RE = re.compile('\<!--.*?--\>')
|
||||
|
||||
def midnight_today():
|
||||
return datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
def midnight_today(now=None):
|
||||
if not now:
|
||||
now = datetime.datetime.now()
|
||||
return now.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
|
||||
|
||||
def midnight_yesterday(midnight=None):
|
||||
if not midnight:
|
||||
|
@ -28,9 +30,11 @@ def midnight_yesterday(midnight=None):
|
|||
def beginning_of_this_month():
|
||||
return datetime.datetime.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
def format_story_link_date__short(date):
|
||||
def format_story_link_date__short(date, now=None):
|
||||
if not now:
|
||||
now = datetime.datetime.now()
|
||||
date = date.replace(tzinfo=None)
|
||||
midnight = midnight_today()
|
||||
midnight = midnight_today(now)
|
||||
if date > midnight:
|
||||
return date.strftime('%I:%M%p').lstrip('0').lower()
|
||||
elif date > midnight_yesterday(midnight):
|
||||
|
|
Loading…
Add table
Reference in a new issue