Browse Source

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

pull/1072/head
Hironsan 4 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 collections
import json import json
import random
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import transaction from django.db import transaction
@ -171,7 +173,9 @@ class DocumentList(generics.ListCreateAPIView):
queryset = project.documents queryset = project.documents
if project.randomize_document_order: 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: else:
queryset = queryset.order_by('id') queryset = queryset.order_by('id')

Loading…
Cancel
Save