From 005e1810b14b5e45a5cf29fa5a91e7f6c9465600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 1 Jun 2021 09:45:50 +0200 Subject: [PATCH] add prefix requirement for some document types (BQR, CRI) --- pfwb_archives_proxy/views.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pfwb_archives_proxy/views.py b/pfwb_archives_proxy/views.py index 5a9a205..253b3c9 100644 --- a/pfwb_archives_proxy/views.py +++ b/pfwb_archives_proxy/views.py @@ -20,7 +20,17 @@ def redirect(request, sess, no, nodoc=None, anx=None): else: query += ' AND anx IS NULL' - cur.execute(query, {'sess': sess, 'no': no, 'nodoc': nodoc, 'anx': anx}) + distinct_types = ('BQR', 'CRI') + type_ = None + for prefix in distinct_types: + if no.startswith(prefix + '-'): + type_, no = no.split('-', 1) + if type_: + query += ' AND type = %(type)s' + else: + query += ' AND type NOT IN %(distinct_types)s' + + cur.execute(query, {'sess': sess, 'no': no, 'nodoc': nodoc, 'anx': anx, 'type': type_, 'distinct_types': distinct_types}) rows = cur.fetchall() if rows: url = 'https://archives.pfwb.be/%s' % rows[0][0]