add redirect view
This commit is contained in:
parent
9a712d0414
commit
7cb8a23afc
|
@ -15,5 +15,11 @@ Including another URLconf
|
|||
"""
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('documents/<str:sess>/<str:no>/<int:nodoc>/annexe-<str:anx>/', views.redirect),
|
||||
path('documents/<str:sess>/<str:no>/<int:nodoc>/', views.redirect),
|
||||
path('documents/<str:sess>/<str:no>/annexe-<str:anx>/', views.redirect),
|
||||
path('documents/<str:sess>/<str:no>/', views.redirect),
|
||||
]
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import psycopg2
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponseRedirect, Http404
|
||||
|
||||
|
||||
def redirect(request, sess, no, nodoc=None, anx=None):
|
||||
with psycopg2.connect(**settings.TABELLIO_PROCEDURE_DB) as conn:
|
||||
with conn.cursor() as cur:
|
||||
query = '''SELECT imageid FROM t_document
|
||||
WHERE imageid IS NOT NULL
|
||||
AND sess = %(sess)s
|
||||
AND no = %(no)s'''
|
||||
if nodoc:
|
||||
query += ' AND nodoc = %(nodoc)s'
|
||||
else:
|
||||
query += ' AND nodoc IS NULL'
|
||||
if anx:
|
||||
query += ' AND anx = %(anx)s'
|
||||
else:
|
||||
query += ' AND anx IS NULL'
|
||||
|
||||
cur.execute(query, {'sess': sess, 'no': no, 'nodoc': nodoc, 'anx': anx})
|
||||
rows = cur.fetchall()
|
||||
if rows:
|
||||
url = 'https://archives.pfwb.be/%s' % rows[0][0]
|
||||
if request.environ.get('QUERY_STRING'):
|
||||
url += '?%s' % request.environ.get('QUERY_STRING')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
raise Http404()
|
Loading…
Reference in New Issue