Added guards against duplicate m2m entries.

- Legacy-Id: 16304
This commit is contained in:
Henrik Levkowetz 2019-06-25 11:01:25 +00:00
parent 32a06473bb
commit f5f838ddf8
2 changed files with 14 additions and 7 deletions

View file

@ -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")

View file

@ -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')