add option to configure URL transpositions (#44363)
This commit is contained in:
parent
3addd2746d
commit
c3e91b09b5
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.17 on 2020-07-01 14:41
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('grandlyon_cartads_cs', '0003_auto_20190919_1211'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='glcartadscs',
|
||||
name='cerfa_pdf_url_substitutions',
|
||||
field=models.TextField(blank=True, help_text='On each line, published URL prefix;actual URL prefix', verbose_name='URL substitutions for CERFA downloads'),
|
||||
),
|
||||
]
|
|
@ -53,6 +53,10 @@ class GLCartaDSCS(AbstractCartaDSCS):
|
|||
max_length=256, blank=True)
|
||||
verify_cert = models.BooleanField(default=True,
|
||||
verbose_name=_('Check HTTPS Certificate validity'))
|
||||
cerfa_pdf_url_substitutions = models.TextField(
|
||||
_('URL substitutions for CERFA downloads'),
|
||||
help_text=_('On each line, published URL prefix;actual URL prefix'),
|
||||
blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Cart@DS CS (@ Grand Lyon)'
|
||||
|
@ -66,6 +70,10 @@ class GLCartaDSCS(AbstractCartaDSCS):
|
|||
url = url.replace('http://ads-rec.grandlyon.fr/', 'https://api-rec.grandlyon.com/ads-rec/')
|
||||
url = url.replace('https://ads-rec.grandlyon.fr/', 'https://api-rec.grandlyon.com/ads-rec/')
|
||||
url = url.replace('https://ads.grandlyon.fr/', 'https://api.grandlyon.com/ads-pro/')
|
||||
if self.cerfa_pdf_url_substitutions:
|
||||
for line in self.cerfa_pdf_url_substitutions.splitlines():
|
||||
old_prefix, new_prefix = line.strip().split(';')
|
||||
url = url.replace(old_prefix, new_prefix)
|
||||
return self.requests.get(url, auth=HttpBearerAuth(self.get_api_manager_token()))
|
||||
|
||||
def get_api_manager_token(self, renew=False):
|
||||
|
|
Reference in New Issue