add possibility to get list of collectivities (#18955)
This commit is contained in:
parent
5370bc5669
commit
bf7201a7b8
|
@ -151,13 +151,23 @@ def as_commune(user_data):
|
|||
return None
|
||||
city = user_data.get('city') or user_data.get('address_city')
|
||||
if city:
|
||||
# first look for known portals
|
||||
collectivities = get_gnm_collectivities()
|
||||
for collectivity in collectivities:
|
||||
if collectivity.get('label') == city:
|
||||
return {
|
||||
'label': city,
|
||||
'slug': slugify(city),
|
||||
'url': collectivity['url']
|
||||
}
|
||||
# if not found look in mairie pages
|
||||
pages = Page.objects.filter(parent__slug='mairie',
|
||||
slug__icontains=slugify(city)).exclude(slug__icontains='annexe')
|
||||
if pages.exists():
|
||||
return {
|
||||
'label': city,
|
||||
'slug': slugify(city),
|
||||
'page': pages[0]
|
||||
'url': pages[0].get_online_url(),
|
||||
}
|
||||
return None
|
||||
|
||||
|
@ -256,3 +266,20 @@ def get_gnm_portal_url():
|
|||
if '_interco_portal' in settings.KNOWN_SERVICES['combo']:
|
||||
return settings.KNOWN_SERVICES['combo']['_interco_portal'].get('url')
|
||||
return settings.KNOWN_SERVICES['combo']['portal'].get('url')
|
||||
|
||||
@register.assignment_tag
|
||||
def get_gnm_collectivities():
|
||||
collectivities = []
|
||||
collectivities.append({'url': 'http://example.net', 'label': 'test'})
|
||||
for key in settings.KNOWN_SERVICES['combo']:
|
||||
if not key.endswith('_portal'):
|
||||
continue
|
||||
matching_hobo = settings.KNOWN_SERVICES['hobo'].get(key.split('_portal')[0][1:])
|
||||
if not matching_hobo:
|
||||
continue
|
||||
if matching_hobo['title'] in ('SAU'): # blacklist
|
||||
continue
|
||||
service = settings.KNOWN_SERVICES['combo'][key]
|
||||
collectivities.append({'url': service.get('url'), 'label': matching_hobo['title']})
|
||||
collectivities.sort(key=lambda x: x['label'])
|
||||
return collectivities
|
||||
|
|
Loading…
Reference in New Issue