extend as_commune to work with a page slug (#23897)
(this will be used to get portal url from a collectivity page)
This commit is contained in:
parent
2c19958dc6
commit
284b4006be
|
@ -506,6 +506,16 @@ def as_producer(slug):
|
|||
def as_commune(user_data):
|
||||
if not user_data:
|
||||
return None
|
||||
|
||||
if isinstance(user_data, basestring):
|
||||
# user_data is expected to be (page) slug
|
||||
collectivities = get_gnm_collectivities()
|
||||
for collectivity in collectivities:
|
||||
if slugify(collectivity['label']) in user_data:
|
||||
collectivity['gnm'] = True
|
||||
return collectivity
|
||||
return None
|
||||
|
||||
city = user_data.get('city') or user_data.get('address_city')
|
||||
if city:
|
||||
# first look for known portals
|
||||
|
@ -515,7 +525,8 @@ def as_commune(user_data):
|
|||
return {
|
||||
'label': city,
|
||||
'slug': slugify(city),
|
||||
'url': collectivity['url']
|
||||
'url': collectivity['url'],
|
||||
'gnm': True,
|
||||
}
|
||||
# if not found look in mairie pages
|
||||
pages = Page.objects.filter(parent__slug='mairie',
|
||||
|
|
Loading…
Reference in New Issue