From f5f838ddf835e91a410ae517b0c0287218f46e63 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Tue, 25 Jun 2019 11:01:25 +0000 Subject: [PATCH] Added guards against duplicate m2m entries. - Legacy-Id: 16304 --- ietf/community/tests.py | 15 ++++++++++----- ietf/community/views.py | 6 ++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ietf/community/tests.py b/ietf/community/tests.py index b730697c3..e622ef56a 100644 --- a/ietf/community/tests.py +++ b/ietf/community/tests.py @@ -87,7 +87,8 @@ class CommunityListTests(TestCase): # with list clist = CommunityList.objects.create(user=User.objects.get(username="plain")) - clist.added_docs.add(draft) + if not draft in clist.added_docs.all(): + clist.added_docs.add(draft) SearchRule.objects.create( community_list=clist, rule_type="name_contains", @@ -249,7 +250,8 @@ class CommunityListTests(TestCase): # with list clist = CommunityList.objects.create(user=User.objects.get(username="plain")) - clist.added_docs.add(draft) + if not draft in clist.added_docs.all(): + clist.added_docs.add(draft) SearchRule.objects.create( community_list=clist, rule_type="name_contains", @@ -284,7 +286,8 @@ class CommunityListTests(TestCase): # with list clist = CommunityList.objects.create(user=User.objects.get(username="plain")) - clist.added_docs.add(draft) + if not draft in clist.added_docs.all(): + clist.added_docs.add(draft) SearchRule.objects.create( community_list=clist, rule_type="name_contains", @@ -325,7 +328,8 @@ class CommunityListTests(TestCase): # subscription with list clist = CommunityList.objects.create(user=User.objects.get(username="plain")) - clist.added_docs.add(draft) + if not draft in clist.added_docs.all(): + clist.added_docs.add(draft) SearchRule.objects.create( community_list=clist, rule_type="name_contains", @@ -368,7 +372,8 @@ class CommunityListTests(TestCase): draft = WgDraftFactory() clist = CommunityList.objects.create(user=User.objects.get(username="plain")) - clist.added_docs.add(draft) + if not draft in clist.added_docs.all(): + clist.added_docs.add(draft) EmailSubscription.objects.create(community_list=clist, email=Email.objects.filter(person__user__username="plain").first(), notify_on="significant") diff --git a/ietf/community/views.py b/ietf/community/views.py index 1ee16bd8e..4572e5e34 100644 --- a/ietf/community/views.py +++ b/ietf/community/views.py @@ -53,7 +53,8 @@ def manage_list(request, username=None, acronym=None, group_type=None): clist.save() for d in add_doc_form.cleaned_data['documents']: - clist.added_docs.add(d) + if not d in clist.added_docs.all(): + clist.added_docs.add(d) return HttpResponseRedirect("") else: @@ -130,7 +131,8 @@ def track_document(request, name, username=None, acronym=None): if clist.pk is None: clist.save() - clist.added_docs.add(doc) + if not doc in clist.added_docs.all(): + clist.added_docs.add(doc) if request.is_ajax(): return HttpResponse(json.dumps({ 'success': True }), content_type='text/plain')