readjust slug to producer code to work with formdata (#22542)

This commit is contained in:
Frédéric Péters 2018-03-15 17:44:48 +01:00
parent 206fdf46e8
commit 2872cf9081
1 changed files with 17 additions and 14 deletions

View File

@ -283,22 +283,25 @@ def as_producer(slug):
producer = None
if ':' in slug: # formdef_reference
slug = slug.split(':')[0]
if slug.startswith('_'):
producer = slug.split('_')[1].replace('hobo-', '')
if slug == 'eservices':
# handle collectivity sites, they are individually named
# "eservices" but have the collectivity slug as a template
# variable.
producer = settings.TEMPLATE_VARS.get('gnm_commune')
if producer and settings.TEMPLATE_VARS.get('gnm_commune_name'):
return {'slug': producer,
'label': settings.TEMPLATE_VARS.get('gnm_commune_name')}
if slug.startswith('_'):
producer = slug.split('_')[1].replace('hobo-', '')
else:
producer = slugify(slug)
try:
producer = re.search(r'(^|\W)producer-(\w*)(\W|$)', producer).group(2).strip()
except AttributeError:
pass
if slug == 'eservices':
# handle collectivity sites, they are individually named
# "eservices" but have the collectivity slug as a template
# variable.
producer = settings.TEMPLATE_VARS.get('gnm_commune', 'grandlyon')
if producer and settings.TEMPLATE_VARS.get('gnm_commune_name'):
return {'slug': producer,
'label': settings.TEMPLATE_VARS.get('gnm_commune_name')}
try:
producer = re.search(r'(^|\W)producer-(\w*)(\W|$)', producer).group(2).strip()
except AttributeError:
pass
if settings.KNOWN_SERVICES['hobo'].get('hobo-%s' % producer):
return {'slug': producer,