diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2016-04-18 09:59:28 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2016-04-18 09:59:28 +0200 |
commit | 1ac457a21dff313387b612126234cba9f7b42467 (patch) | |
tree | 4838c86cf4ed7aa7bdf48ab02dd6e4bcc1fb497b /src/web | |
parent | Removed debug log. (diff) | |
download | newspipe-1ac457a21dff313387b612126234cba9f7b42467.tar.gz newspipe-1ac457a21dff313387b612126234cba9f7b42467.tar.bz2 newspipe-1ac457a21dff313387b612126234cba9f7b42467.zip |
handling date formating server side
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/js/components/MiddlePanel.react.js | 8 | ||||
-rw-r--r-- | src/web/js/components/RightPanel.react.js | 4 | ||||
-rw-r--r-- | src/web/js/components/time.react.js | 6 | ||||
-rw-r--r-- | src/web/views/home.py | 17 |
4 files changed, 20 insertions, 15 deletions
diff --git a/src/web/js/components/MiddlePanel.react.js b/src/web/js/components/MiddlePanel.react.js index f6e44777..2a8ab96e 100644 --- a/src/web/js/components/MiddlePanel.react.js +++ b/src/web/js/components/MiddlePanel.react.js @@ -16,7 +16,7 @@ var TableLine = React.createClass({ feed_title: React.PropTypes.string.isRequired, icon_url: React.PropTypes.string, title: React.PropTypes.string.isRequired, - timestamp: React.PropTypes.number.isRequired, + rel_date: React.PropTypes.string.isRequired, date: React.PropTypes.string.isRequired, read: React.PropTypes.bool.isRequired, selected: React.PropTypes.bool.isRequired, @@ -48,12 +48,10 @@ var TableLine = React.createClass({ if(this.props.selected) { clsses += " active"; } - // FIXME https://github.com/yahoo/react-intl/issues/189 - // use FormattedRelative when fixed, will have to upgrade to ReactIntlv2 return (<div className={clsses} onClick={this.loadArticle} title={this.props.title}> <h5><strong>{title}</strong></h5> <JarrTime text={this.props.date} - stamp={this.props.timestamp} /> + stamp={this.props.rel_date} /> <div>{read} {liked} {this.props.title}</div> </div> ); @@ -238,7 +236,7 @@ var MiddlePanel = React.createClass({ icon_url={article.icon_url} read={article.read} liked={article.liked} - timestamp={article.timestamp} + rel_date={article.rel_date} date={article.date} selected={article.selected} article_id={article.article_id} diff --git a/src/web/js/components/RightPanel.react.js b/src/web/js/components/RightPanel.react.js index 97a7c461..6322144f 100644 --- a/src/web/js/components/RightPanel.react.js +++ b/src/web/js/components/RightPanel.react.js @@ -310,11 +310,11 @@ var Feed = React.createClass({ return (<div className="panel-body"> <dl className="dl-horizontal"> <dt>Created on</dt> - <dd><JarrTime stamp={this.props.obj.created_stamp} + <dd><JarrTime stamp={this.props.obj.created_rel} text={this.props.obj.created_date} /> </dd> <dt>Last fetched</dt> - <dd><JarrTime stamp={this.props.obj.last_stamp} + <dd><JarrTime stamp={this.props.obj.last_rel} text={this.props.obj.last_retrieved} /> </dd> </dl> diff --git a/src/web/js/components/time.react.js b/src/web/js/components/time.react.js index 8b4d47d9..c293e638 100644 --- a/src/web/js/components/time.react.js +++ b/src/web/js/components/time.react.js @@ -1,13 +1,11 @@ var React = require('react'); -var ReactIntl = require('react-intl'); var JarrTime = React.createClass({ - mixins: [ReactIntl.IntlMixin], - propTypes: {stamp: React.PropTypes.number.isRequired, + propTypes: {stamp: React.PropTypes.string.isRequired, text: React.PropTypes.string.isRequired}, render: function() { return (<time dateTime={this.props.text} title={this.props.text}> - {this.formatRelative(this.props.stamp)} + {this.props.stamp} </time>); }, }); diff --git a/src/web/views/home.py b/src/web/views/home.py index 5a8312b4..88fb7594 100644 --- a/src/web/views/home.py +++ b/src/web/views/home.py @@ -1,10 +1,12 @@ +import pytz import logging -from calendar import timegm +from datetime import datetime from flask import current_app, render_template, \ request, flash, url_for, redirect from flask.ext.login import login_required, current_user from flask.ext.babel import gettext +from babel.dates import format_datetime, format_timedelta import conf from web.lib.utils import redirect_url @@ -16,6 +18,7 @@ from web.views.common import jsonify from web.controllers import FeedController, \ ArticleController, CategoryController +localize = pytz.utc.localize logger = logging.getLogger(__name__) @@ -31,6 +34,7 @@ def home(): @etag_match @jsonify def get_menu(): + now = datetime.utcnow() categories_order = [0] categories = {0: {'name': 'No category', 'id': 0}} for cat in CategoryController(current_user.id).read().order_by('name'): @@ -42,8 +46,10 @@ def get_menu(): categories[cat_id]['feeds'] = [] feeds = {feed.id: feed for feed in FeedController(current_user.id).read()} for feed_id, feed in feeds.items(): - feed['created_stamp'] = timegm(feed.created_date.timetuple()) * 1000 - feed['last_stamp'] = timegm(feed.last_retrieved.timetuple()) * 1000 + feed['created_rel'] = format_timedelta(now - feed.created_date) + feed['last_rel'] = format_timedelta(now - feed.last_retrieved) + feed['created_date'] = format_datetime(localize(feed.created_date)) + feed['last_retrieved'] = format_datetime(localize(feed.last_retrieved)) feed['category_id'] = feed.category_id or 0 feed['unread'] = unread.get(feed.id, 0) if not feed.filters: @@ -87,12 +93,14 @@ def _get_filters(in_dict): @jsonify def _articles_to_json(articles, fd_hash=None): + now = datetime.utcnow() return {'articles': [{'title': art.title, 'liked': art.like, 'read': art.readed, 'article_id': art.id, 'selected': False, 'feed_id': art.feed_id, 'category_id': art.category_id or 0, 'feed_title': fd_hash[art.feed_id]['title'] if fd_hash else None, 'icon_url': fd_hash[art.feed_id]['icon_url'] if fd_hash else None, - 'date': art.date, 'timestamp': timegm(art.date.timetuple()) * 1000} + 'date': format_datetime(localize(art.date)), + 'rel_date': format_timedelta(now - art.date)} for art in articles.limit(1000)]} @@ -125,6 +133,7 @@ def get_article(article_id, parse=False): feed = FeedController(current_user.id).get(id=article.feed_id) article['icon_url'] = url_for('icon.icon', url=feed.icon_url) \ if feed.icon_url else None + article['date'] = format_datetime(localize(article.date)) return article |