diff --git a/apps/push/views.py b/apps/push/views.py index f9112e2e2..28864a03f 100644 --- a/apps/push/views.py +++ b/apps/push/views.py @@ -8,6 +8,7 @@ from django.shortcuts import get_object_or_404 from apps.push.models import PushSubscription from apps.push.signals import verified +from apps.rss_feeds.models import MFeedPushHistory def push_callback(request, push_id): if request.method == 'GET': @@ -42,6 +43,7 @@ def push_callback(request, push_id): # Don't give fat ping, just fetch. # subscription.feed.queue_pushed_feed_xml(request.raw_post_data) subscription.feed.queue_pushed_feed_xml("Fetch me") - + MFeedPushHistory.objects.create(feed_id=subscription.feed_id) + return HttpResponse('') return Http404 diff --git a/apps/rss_feeds/models.py b/apps/rss_feeds/models.py index 417a724cb..bae92896a 100644 --- a/apps/rss_feeds/models.py +++ b/apps/rss_feeds/models.py @@ -1306,7 +1306,7 @@ class MFeedFetchHistory(mongo.Document): for fetch in fetches: history = {} history['message'] = fetch.message - history['fetch_date'] = fetch.fetch_date + history['fetch_date'] = fetch.fetch_date.strftime("%Y-%m-%d %H:%M:%S") history['status_code'] = fetch.status_code history['exception'] = fetch.exception fetch_history.append(history) @@ -1339,12 +1339,35 @@ class MPageFetchHistory(mongo.Document): for fetch in fetches: history = {} history['message'] = fetch.message - history['fetch_date'] = fetch.fetch_date + history['fetch_date'] = fetch.fetch_date.strftime("%Y-%m-%d %H:%M:%S") history['status_code'] = fetch.status_code history['exception'] = fetch.exception fetch_history.append(history) return fetch_history - + + +class MFeedPushHistory(mongo.Document): + feed_id = mongo.IntField() + push_date = mongo.DateTimeField(default=datetime.datetime.now) + + meta = { + 'collection': 'feed_push_history', + 'allow_inheritance': False, + 'ordering': ['-push_date'], + 'indexes': ['feed_id', '-push_date'], + } + + @classmethod + def feed_history(cls, feed_id): + pushes = cls.objects(feed_id=feed_id).order_by('-push_date')[:5] + push_history = [] + for push in pushes: + history = {} + history['push_date'] = push.push_date.strftime("%Y-%m-%d %H:%M:%S") + push_history.append(history) + return push_history + + class FeedLoadtime(models.Model): feed = models.ForeignKey(Feed) date_accessed = models.DateTimeField(auto_now=True) diff --git a/apps/rss_feeds/views.py b/apps/rss_feeds/views.py index f72a5d05e..b0d2d905f 100644 --- a/apps/rss_feeds/views.py +++ b/apps/rss_feeds/views.py @@ -7,7 +7,7 @@ from django.contrib.auth.decorators import login_required from django.template import RequestContext # from django.db import IntegrityError from apps.rss_feeds.models import Feed, merge_feeds -from apps.rss_feeds.models import MFeedFetchHistory, MPageFetchHistory +from apps.rss_feeds.models import MFeedFetchHistory, MPageFetchHistory, MFeedPushHistory from apps.analyzer.models import get_classifiers_for_user from apps.reader.models import UserSubscription from utils.user_functions import ajax_login_required @@ -125,6 +125,7 @@ def load_feed_statistics(request, feed_id): # Fetch histories stats['feed_fetch_history'] = MFeedFetchHistory.feed_history(feed_id) stats['page_fetch_history'] = MPageFetchHistory.feed_history(feed_id) + stats['feed_push_history'] = MFeedPushHistory.feed_history(feed_id) logging.user(request, "~FBStatistics: ~SB%s ~FG(%s/%s/%s subs)" % (feed, feed.num_subscribers, feed.active_subscribers, feed.premium_subscribers,)) diff --git a/media/css/reader.css b/media/css/reader.css index 48141918f..86a8005fb 100644 --- a/media/css/reader.css +++ b/media/css/reader.css @@ -4588,8 +4588,11 @@ background: transparent; .NB-modal-statistics .NB-statistics-stat .NB-statistics-fetches-half { float: left; - width: 50%; text-align: center; + margin-right: 18px; +} +.NB-modal-statistics .NB-statistics-stat .NB-statistics-fetches-half:last-child { + margin-right: 0; } .NB-modal-statistics .NB-statistics-stat .NB-statistics-history-stat { @@ -4631,7 +4634,7 @@ background: transparent; } .NB-modal-statistics .NB-statistics-history-fetch .NB-statistics-history-fetch-message { padding-right: 4px; - margin-left: 120px; + margin-left: 110px; font-weight: bold; } .NB-modal-statistics .NB-statistics-history-fetch .NB-statistics-history-fetch-exception { diff --git a/media/js/newsblur/reader_statistics.js b/media/js/newsblur/reader_statistics.js index 4d40eceda..636f4c02d 100644 --- a/media/js/newsblur/reader_statistics.js +++ b/media/js/newsblur/reader_statistics.js @@ -126,13 +126,17 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, { ])), $.make('div', { className: 'NB-statistics-stat NB-statistics-fetches'}, [ $.make('div', { className: 'NB-statistics-fetches-half'}, [ - $.make('div', { className: 'NB-statistics-label' }, 'Feed'), - $.make('div', this.make_history(data, 'feed')) + $.make('div', { className: 'NB-statistics-label' }, 'Feed Fetch'), + $.make('div', this.make_history(data, 'feed_fetch')) ]), $.make('div', { className: 'NB-statistics-fetches-half'}, [ - $.make('div', { className: 'NB-statistics-label' }, 'Page'), - $.make('div', this.make_history(data, 'page')) - ]) + $.make('div', { className: 'NB-statistics-label' }, 'Page Fetch'), + $.make('div', this.make_history(data, 'page_fetch')) + ]), + (this.feed.is_push && $.make('div', { className: 'NB-statistics-fetches-half'}, [ + $.make('div', { className: 'NB-statistics-label' }, 'Feed Push'), + $.make('div', this.make_history(data, 'feed_push')) + ])) ]) ]); @@ -209,17 +213,17 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, { }, make_history: function(data, fetch_type) { - var fetches = data[fetch_type+'_fetch_history']; + var fetches = data[fetch_type+'_history']; if (!fetches) return; var $history = _.map(fetches, function(fetch) { - var feed_ok = _.contains([200, 304], fetch.status_code); + var feed_ok = _.contains([200, 304], fetch.status_code) || !fetch.status_code; var status_class = feed_ok ? ' NB-ok ' : ' NB-errorcode '; return $.make('div', { className: 'NB-statistics-history-fetch' + status_class, title: feed_ok ? '' : fetch.exception }, [ $.make('div', { className: 'NB-statistics-history-fetch-date' }, fetch.fetch_date), $.make('div', { className: 'NB-statistics-history-fetch-message' }, [ fetch.message, - $.make('div', { className: 'NB-statistics-history-fetch-code' }, ' ('+fetch.status_code+')') + (fetch.status_code && $.make('div', { className: 'NB-statistics-history-fetch-code' }, ' ('+fetch.status_code+')')) ]) ]); });