Commit e77669eb authored by okhin's avatar okhin

Fix #1: Importing the meps is now working

parent 151f9eb2
Pipeline #101 failed with stage
in 48 seconds
......@@ -83,7 +83,7 @@ class Importer(models.Model):
# We do not have enough field to discriminate our meps
continue
updated_mep = {}
updated_mep['groups'] = []
groups = []
for mandate in import_mep['mandates']:
# Parltrack gives us a date starting with 9999 if ends has not happens
# FranceData gives us an empty one
......@@ -94,18 +94,20 @@ class Importer(models.Model):
if not (end_date == '' or end_date.startswith('9999')):
# This mandate has ended
continue
#import ipdb; ipdb.set_trace()
groupType, added = GroupType.objects.get_or_create(organization = self.organization,
name = mandate['group']['kind'])
# We want to only use the groups nown by the organisation
try:
groupType = GroupType.objects.get(organization = self.organization,
name = mandate['group']['kind'])
except:
continue
if 'abbreviation' in mandate['group']:
group, added = Group.objects.get_or_create(name = mandate['group']['abbreviation'],
type = groupType)
else:
group, added = Group.objects.get_or_create(name = mandate['group']['name'],
type = groupType)
updated_mep['groups'].append(group)
#import ipdb; ipdb.set_trace()
if updated_mep['groups'] == []:
groups.append(group)
if groups == []:
# The mep have no groups active, he is not to be bothered.
continue
......@@ -146,6 +148,9 @@ class Importer(models.Model):
for phone in phones:
mep.phones.get_or_create(phone=phone)
# Let's link the MEP to the group
mep.groups = groups
mep.save()
# We want to link the mep to our current campaign
CampaignContact(campaign=self.campaign, contact=mep).save()
inserted += 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment