From 4f14b923fa942f1e8e7574aba0d752ac8ca0a512 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 3 Mar 2017 18:40:52 +0100 Subject: [PATCH] avoid double entries in accessed table --- pandora/user/views.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pandora/user/views.py b/pandora/user/views.py index 8368e349..8c0a3cf2 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -794,12 +794,13 @@ def setUI(request, data): if data.get('item'): item = get_object_or_404_json(Item, public_id=data['item']) - if request.user.is_authenticated(): - access, created = Access.objects.get_or_create(item=item, user=request.user) - else: - access, created = Access.objects.get_or_create(item=item, user=None) - if not created: - access.save() + with transaction.atomic(): + if request.user.is_authenticated(): + access, created = Access.objects.get_or_create(item=item, user=request.user) + else: + access, created = Access.objects.get_or_create(item=item, user=None) + if not created: + access.save() if data.get('document'): import document.models doc = get_object_or_404_json(document.models.Document, id=ox.fromAZ(data['document']))