From 1d077bb32599883c083f8a75bc5586dc2075972e Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 25 Aug 2010 21:02:21 -0400 Subject: [PATCH] Merge feeds that are found to be dupes during the exception handling manual process. --- apps/rss_feeds/views.py | 24 ++++++++++++++++++++---- utils/munin/newsblur_feeds.py | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/apps/rss_feeds/views.py b/apps/rss_feeds/views.py index c2b85e53a..7d8dc3f1c 100644 --- a/apps/rss_feeds/views.py +++ b/apps/rss_feeds/views.py @@ -1,7 +1,7 @@ from utils import log as logging from django.shortcuts import get_object_or_404 from django.http import HttpResponseForbidden -from apps.rss_feeds.models import Feed +from apps.rss_feeds.models import Feed, merge_feeds from utils.user_functions import ajax_login_required from utils import json, feedfinder from utils.feed_functions import relative_timeuntil, relative_timesince @@ -50,6 +50,7 @@ def exception_retry(request): def exception_change_feed_address(request): feed_id = request.POST['feed_id'] feed = get_object_or_404(Feed, pk=feed_id) + feed_address = request.POST['feed_address'] if not feed.has_exception: logging.info(" ***********> [%s] Incorrect feed address change: %s" % (request.user, feed)) @@ -58,8 +59,15 @@ def exception_change_feed_address(request): feed.has_exception = False feed.active = True feed.fetched_once = False - feed.feed_address = request.POST['feed_address'] - feed.save() + feed.feed_address = feed_address + try: + feed.save() + except: + original_feed = Feed.objects.get(feed_address=feed_address) + original_feed.has_exception = False + original_feed.active = True + original_feed.save() + merge_feeds(original_feed.pk, feed.pk) return {'code': 1} @@ -73,6 +81,7 @@ def exception_change_feed_link(request): if not feed.has_exception: logging.info(" ***********> [%s] Incorrect feed address change: %s" % (request.user, feed)) + # This Forbidden-403 throws an error, which sounds pretty good to me right now return HttpResponseForbidden() feed_address = feedfinder.feed(feed_link) @@ -83,7 +92,14 @@ def exception_change_feed_link(request): feed.fetched_once = False feed.feed_link = feed_link feed.feed_address = feed_address - feed.save() + try: + feed.save() + except: + original_feed = Feed.objects.get(feed_address=feed_address) + original_feed.has_exception = False + original_feed.active = True + original_feed.save() + merge_feeds(original_feed.pk, feed.pk) return {'code': code} diff --git a/utils/munin/newsblur_feeds.py b/utils/munin/newsblur_feeds.py index 7e8ffa54a..d7fa7775f 100755 --- a/utils/munin/newsblur_feeds.py +++ b/utils/munin/newsblur_feeds.py @@ -11,11 +11,13 @@ graph_config = { 'feeds.label': 'feeds', 'subscriptions.label': 'subscriptions', 'update_queue.label': 'update_queue', + 'exception_feeds.label': 'exception_feeds', } metrics = { 'feeds': Feed.objects.count(), 'subscriptions': UserSubscription.objects.count(), + 'exception_feeds': Feed.objects.count(has_exception=True).count(), 'update_queue': Feed.objects.filter(next_scheduled_update__lte=datetime.datetime.now()).count(), }