add prefix requirement for some document types (BQR, CRI)

This commit is contained in:
Frédéric Péters 2021-06-01 09:45:50 +02:00
parent ed0a09de5c
commit 005e1810b1
1 changed files with 11 additions and 1 deletions

View File

@ -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]