Browse Source

Deduplicate data on randomized order option, fix #933, fix #1026

pull/1072/head
Hironsan 3 years ago
parent
commit
366d66d43c
1 changed files with 5 additions and 1 deletions
  1. 6
      app/api/views.py

6
app/api/views.py

@ -1,5 +1,7 @@
import collections
import json
import random
from django.conf import settings
from django.contrib.auth.models import User
from django.db import transaction
@ -171,7 +173,9 @@ class DocumentList(generics.ListCreateAPIView):
queryset = project.documents
if project.randomize_document_order:
queryset = queryset.annotate(sort_id=F('id') % self.request.user.id).order_by('sort_id')
random.seed(self.request.user.id)
value = random.randrange(2, 20)
queryset = queryset.annotate(sort_id=F('id') % value).order_by('sort_id', 'id')
else:
queryset = queryset.order_by('id')

Loading…
Cancel
Save