From 499670990635b79146f57a1a643107a6cc46ab06 Mon Sep 17 00:00:00 2001 From: Raymond Penners Date: Sun, 20 Nov 2011 21:55:15 +0100 Subject: [PATCH 1/2] There is no need to save default NoticeSetting instances. Under some rare circumstances (impatient users firing off multiple requests in parallel) the .save() here could also result in: IntegrityError: duplicate key value violates unique constraint "notification_noticesetting_user_id_key" --- notification/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/notification/models.py b/notification/models.py index f4490474..720bd0cf 100644 --- a/notification/models.py +++ b/notification/models.py @@ -80,7 +80,6 @@ def get_notification_setting(user, notice_type, medium): except NoticeSetting.DoesNotExist: default = (NOTICE_MEDIA_DEFAULTS[medium] <= notice_type.default) setting = NoticeSetting(user=user, notice_type=notice_type, medium=medium, send=default) - setting.save() return setting def should_send(user, notice_type, medium): From 68a681d52c371a6eb36b3d02322a0aa1d7e8633f Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Mon, 31 Oct 2011 18:21:27 +0100 Subject: [PATCH 2/2] Basic work to make it django-1.4 compatible (django.contrib.syndication.views.feed was removed). Some bugs remains (HTML seems to be escaped where it shouldn't), but at least it doesn't fail completely. --- notification/atomformat.py | 2 +- notification/views.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/notification/atomformat.py b/notification/atomformat.py index a307eddb..756feeb8 100644 --- a/notification/atomformat.py +++ b/notification/atomformat.py @@ -81,7 +81,7 @@ class Feed(object): VALIDATE = True - def __init__(self, slug, feed_url): + def __init__(self, slug=None, feed_url=None): # @@@ slug and feed_url are not used yet pass diff --git a/notification/views.py b/notification/views.py index e27a8592..37684f7c 100644 --- a/notification/views.py +++ b/notification/views.py @@ -1,9 +1,8 @@ from django.core.urlresolvers import reverse from django.shortcuts import render_to_response, get_object_or_404 -from django.http import HttpResponseRedirect, Http404 +from django.http import HttpResponseRedirect, Http404, HttpResponse from django.template import RequestContext from django.contrib.auth.decorators import login_required -from django.contrib.syndication.views import feed from notification.models import * from notification.decorators import basic_auth_required, simple_basic_auth_callback @@ -15,11 +14,10 @@ def feed_for_user(request): """ An atom feed for all unarchived :model:`notification.Notice`s for a user. """ - url = "feed/%s" % request.user.username - return feed(request, url, { - "feed": NoticeUserFeed, - }) - + feedgen = NoticeUserFeed().get_feed(request.user.username) + response = HttpResponse(mimetype=feedgen.mime_type) + feedgen.write(response, 'utf-8') + return response @login_required def notices(request):