Merge branch 'master' into nanterre-recette

This commit is contained in:
Thomas NOËL 2018-01-12 18:38:27 +01:00
commit 3e81ae23ce
6 changed files with 57 additions and 5 deletions

View File

@ -107,6 +107,7 @@ setup(
'pytz',
'python-dateutil',
'django-admin-rangefilter',
'requests',
],
zip_safe=False,
cmdclass={

View File

@ -54,6 +54,19 @@ def test_list_doublons(nanterre_classic_family, app):
second_data = response.json['data'][1]
third_data = response.json['data'][2]
# verify pagination respect ordering by decreasing score and increasing id
next_url = url
all_datas = []
while next_url:
response = app.get(next_url)
all_datas.extend(response.json['data'])
next_url = response.json.get('more')
if next_url:
assert response.json['data']
assert len(all_datas) == 91, 'some duplicates are missing'
l = [(-x['score'], x['id']) for x in all_datas]
assert sorted(l) == l, 'data is not properly ordered'
url = reverse('rsu-api-doublons') + '?limit=100'
response = app.get(url)
assert response.json['err'] == 0

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-01-12 15:01
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('zoo_data', '0006_auto_20170714_0833'),
]
operations = [
migrations.RemoveField(
model_name='log',
name='url',
),
]

View File

@ -1879,7 +1879,7 @@ class DoublonsView(DoublonMixin, APIView):
try:
cookie = request.GET.get('cookie', '')
cookie = cookie.split('_', 1)
since = isodate.parse_datetime(cookie[0])
score = Decimal(cookie[0])
last_id = int(cookie[1])
except:
cookie = None
@ -1919,7 +1919,7 @@ class DoublonsView(DoublonMixin, APIView):
if cookie:
qs = qs.filter(
Q(created__gt=since) | Q(created=since, id__gt=last_id)
Q(score__lt=score) | Q(score=score, id__gt=last_id)
)
qs = qs.prefetch_related(
'first__left_relations__schema', 'first__left_relations__right',
@ -1947,9 +1947,9 @@ class DoublonsView(DoublonMixin, APIView):
content.update(params)
if len(data) > limit:
since = qs[limit - 1].created.isoformat()
score = qs[limit - 1].score
max_id = qs[limit - 1].id
cookie = '%s_%s' % (since, max_id)
cookie = '%s_%s' % (score, max_id)
content['cookie'] = params['cookie'] = cookie
content['more'] = request.build_absolute_uri(reverse('rsu-api-doublons')) + '?' + urlencode(params)

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-01-12 15:01
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('zoo_nanterre', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='duplicate',
options={'ordering': ('-score', 'id'), 'verbose_name': 'duplicate', 'verbose_name_plural': 'duplicates'},
),
]

View File

@ -75,5 +75,5 @@ class Duplicate(models.Model):
class Meta:
verbose_name = _('duplicate')
verbose_name_plural = _('duplicates')
ordering = ('created',)
ordering = ('-score', 'id')
unique_together = (('first', 'second'),)