add support for document with no number
This commit is contained in:
parent
cf113ecba2
commit
b679c1fdb8
|
@ -113,6 +113,89 @@ USE_TZ = True
|
|||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# DOCUMENT TYPES
|
||||
TABELLIO_DOCUMENT_TYPES = {
|
||||
'accord-de-cooperation': 'ACCOP',
|
||||
'allocution-de-la-presidence': 'ALLOC',
|
||||
'amendements-en-commission': 'AMENDCOM',
|
||||
'amendements-en-seance': 'AMENDSCE',
|
||||
'annexe': 'ANNEXE',
|
||||
'arrete-de-reallocation': 'ARRREA',
|
||||
'avis': 'AVIS',
|
||||
'avis-d-une-commission-annexe': 'ACA',
|
||||
'avis-du-conseil-d-etat': 'CETAT',
|
||||
'budget-administratif': 'BUDADM',
|
||||
'budget-de-fonctionnement-du-parlement': 'BUDFONN',
|
||||
'budget-de-fonctionnement-du-parlement-sans-numero': 'BUDFON',
|
||||
'budget-de-fonctionnement-du-pcf': 'BUFONCPCF',
|
||||
'budget-de-fonctionnement-pcf': 'BUFONCPCF',
|
||||
'budget-divers': 'BUDDIVERS',
|
||||
'bulletin-des-questions-et-des-reponses': 'BQR',
|
||||
'bulletin-des-questions-et-reponses': 'BQR',
|
||||
'bulletin-des-travaux': 'BTR',
|
||||
'bureau': 'BUR',
|
||||
'cahier-d-observations': 'RP-COBS',
|
||||
'communication-de-la-presidence': 'COMMUNI',
|
||||
'composition-du-gouvernement': 'GOUVERNEM',
|
||||
'compte-rendu-analytique': 'CRA',
|
||||
'compte-rendu-de-reunion': 'CRI-RE',
|
||||
'compte-rendu-integral': 'CRI',
|
||||
'compte-rendu-integral-de-commission': 'CRICOM',
|
||||
'conference-des-presidents': 'CONFEPRE',
|
||||
'contrat-de-gestion': 'CONTRAGES',
|
||||
'controle-du-compte-general': 'CCG',
|
||||
'cri-commission': 'CRICOM',
|
||||
'debat-thematique': 'DT',
|
||||
'declaration-du-gouvernement': 'DECLAGOUV',
|
||||
'decret': 'DECCCF',
|
||||
'decret-ccf': 'DECCCF',
|
||||
'discussion-generale-conjointe': 'DICO',
|
||||
'divers': 'DIVERS',
|
||||
'eloges-funebres': 'ELOGE',
|
||||
'enquete-parlementaire': 'CREACOMEN',
|
||||
'entente': 'ENTENTE',
|
||||
'erratum': 'ERRATUM',
|
||||
'etat-des-travaux': 'ETATRA',
|
||||
'expose-general-du-budget': 'EXGEBU',
|
||||
'expose-particulier': 'EXPART',
|
||||
'interpellation': 'INTERP',
|
||||
'liste': 'LISTE',
|
||||
'liste-des-candidatures': 'LICA',
|
||||
'numero-non-attribue': 'NONO',
|
||||
'parchemin': 'PARCH',
|
||||
'plan': 'PLAN',
|
||||
'poursuite-a-charge-d-un-membre': 'PCM',
|
||||
'prefiguration-des-resultats': 'RP-PREF',
|
||||
'programme-justificatif': 'PROGJ',
|
||||
'programme-quinquennal': 'PROGQUINQ',
|
||||
'projet-de-decret': 'PJD',
|
||||
'projet-de-decret-budgetaire': 'PJDB',
|
||||
'projet-de-motion': 'DG-PJMS',
|
||||
'projet-de-resolution': 'DG-PJR',
|
||||
'proposition-de-decret': 'PPD',
|
||||
'proposition-de-modification-du-reglement': 'PPMR',
|
||||
'proposition-de-motion': 'DG-PPMS',
|
||||
'proposition-de-resolution': 'DG-PPR',
|
||||
'proposition-de-resolution-sans-numero': 'PRORESN',
|
||||
'question-d-actualite': 'QA',
|
||||
'question-ecrite': 'QE',
|
||||
'question-orale': 'QO',
|
||||
'rapport': 'RAPPORT',
|
||||
'rapport-d-activites': 'RP-RACT',
|
||||
'rapport-de-commission': 'RAPP',
|
||||
'rapport-de-verification-des-comptes': 'RAPVERI',
|
||||
'rapport-sans-numero': 'RASANU',
|
||||
'reglement-du-parlement': 'REGLPARL',
|
||||
'reglements-conjoints': 'REGLCONJ',
|
||||
'resolution': 'RESOLU',
|
||||
'resolution-adoptee-par-le-parlement': 'RESADOPT',
|
||||
'resolutions': 'RESO',
|
||||
'service-de-mediation-commun': 'SMC',
|
||||
'statut-des-agents-du-parlement': 'SAP',
|
||||
'texte-adopte': 'TEXADOPT',
|
||||
'texte-adopte-en-commission': 'TEXTCOM',
|
||||
}
|
||||
|
||||
|
||||
local_settings_file = os.environ.get(
|
||||
'PFWB_ARCHIVES_PROXY_SETTINGS_FILE', os.path.join(os.path.dirname(__file__), 'local_settings.py')
|
||||
|
|
|
@ -13,11 +13,31 @@ Including another URLconf
|
|||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.urls import path
|
||||
from django.urls import path, register_converter
|
||||
|
||||
from . import views
|
||||
from . import settings, views
|
||||
|
||||
|
||||
class DocumentTypeConverter:
|
||||
regex = '(%s)' % '|'.join(settings.TABELLIO_DOCUMENT_TYPES)
|
||||
to_python = lambda self, x: x
|
||||
to_url = lambda self, x: x
|
||||
|
||||
|
||||
class DateConverter:
|
||||
regex = '[0-9]{4}-[0-9]{2}-[0-9]{2}'
|
||||
to_python = lambda self, x: x
|
||||
to_url = lambda self, x: x
|
||||
|
||||
|
||||
register_converter(DocumentTypeConverter, 'doctype')
|
||||
register_converter(DateConverter, 'date')
|
||||
|
||||
urlpatterns = [
|
||||
path('documents/<str:sess>/<doctype:doctype>/<date:date>/', views.redirect),
|
||||
path('documents/<str:sess>/<doctype:doctype>/<str:no>/<int:nodoc>/annexe-<str:anx>/', views.redirect),
|
||||
path('documents/<str:sess>/<doctype:doctype>/<str:no>/<int:nodoc>/', views.redirect),
|
||||
path('documents/<str:sess>/<doctype:doctype>/<str:no>/', views.redirect),
|
||||
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),
|
||||
|
|
|
@ -4,31 +4,32 @@ from django.conf import settings
|
|||
from django.http import HttpResponseRedirect, Http404
|
||||
|
||||
|
||||
def redirect(request, sess, no, nodoc=None, anx=None):
|
||||
def redirect(request, sess, no=None, nodoc=None, anx=None, doctype=None, date=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'''
|
||||
AND sess = %(sess)s'''
|
||||
|
||||
if no:
|
||||
query += ' 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'
|
||||
|
||||
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'
|
||||
if doctype:
|
||||
doctype = settings.TABELLIO_DOCUMENT_TYPES.get(doctype)
|
||||
query += ' AND type = %(doctype)s'
|
||||
|
||||
if date:
|
||||
query += ' AND date = %(date)s'
|
||||
|
||||
cur.execute(
|
||||
query,
|
||||
|
@ -37,11 +38,13 @@ def redirect(request, sess, no, nodoc=None, anx=None):
|
|||
'no': no,
|
||||
'nodoc': nodoc,
|
||||
'anx': anx,
|
||||
'type': type_,
|
||||
'distinct_types': distinct_types,
|
||||
'doctype': doctype,
|
||||
'date': date,
|
||||
},
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
if len(rows) > 1:
|
||||
raise Http404('not unique')
|
||||
if rows:
|
||||
url = 'https://archives.pfwb.be/%s' % rows[0][0]
|
||||
if request.environ.get('QUERY_STRING'):
|
||||
|
|
Loading…
Reference in New Issue