Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
campaign
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
piphone
campaign
Commits
79a691cd
Commit
79a691cd
authored
Aug 07, 2016
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Importer works
parent
0ab2a23f
Pipeline
#94
passed with stage
in 54 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
11 deletions
+56
-11
picampaign/contact/migrations/0005_auto_20160807_2052.py
picampaign/contact/migrations/0005_auto_20160807_2052.py
+20
-0
picampaign/contact/migrations/0006_auto_20160807_2057.py
picampaign/contact/migrations/0006_auto_20160807_2057.py
+20
-0
picampaign/contact/models.py
picampaign/contact/models.py
+1
-1
picampaign/importer/models.py
picampaign/importer/models.py
+15
-10
No files found.
picampaign/contact/migrations/0005_auto_20160807_2052.py
0 → 100644
View file @
79a691cd
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-07 18:52
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'contact'
,
'0004_auto_20160807_1834'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'contact'
,
name
=
'birthdate'
,
field
=
models
.
DateField
(
blank
=
True
),
),
]
picampaign/contact/migrations/0006_auto_20160807_2057.py
0 → 100644
View file @
79a691cd
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-07 18:57
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'contact'
,
'0005_auto_20160807_2052'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'contact'
,
name
=
'birthdate'
,
field
=
models
.
DateField
(
blank
=
True
,
null
=
True
),
),
]
picampaign/contact/models.py
View file @
79a691cd
...
...
@@ -7,7 +7,7 @@ class Contact(models.Model):
id
=
models
.
AutoField
(
primary_key
=
True
)
first_name
=
models
.
CharField
(
max_length
=
64
)
last_name
=
models
.
CharField
(
max_length
=
64
)
birthdate
=
models
.
DateField
()
birthdate
=
models
.
DateField
(
blank
=
True
,
null
=
True
)
phone
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
)
twitter
=
models
.
CharField
(
max_length
=
64
,
blank
=
True
)
mail
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
...
...
picampaign/importer/models.py
View file @
79a691cd
...
...
@@ -6,6 +6,7 @@ import re
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
picampaign.contact.models
import
Contact
from
picampaign.campaign.models
import
Campaign
from
picampaign.organization.models
import
Group
,
GroupType
,
Organization
...
...
@@ -49,12 +50,11 @@ class Importer(models.Model):
For instance, the comittee of a MEP would be listed in a column named 'group:comittee', separated
by columns.
"""
import
ipdb
;
ipdb
.
set_trace
()
import_data
=
[]
# First let's check what kind of importer are we running.
# If it's a file, let's parse it according to our format.
if
self
.
kind
==
'file'
:
with
open
(
self
.
file
,
u
'rU'
)
as
f
:
if
self
.
kind
()
==
'file'
:
with
open
(
self
.
file
.
path
,
u
'rU'
)
as
f
:
if
self
.
data_format
==
'CSV'
:
# If we're a csv format, let's use DictReader on a file object
reader
=
DictReader
(
f
)
...
...
@@ -79,13 +79,15 @@ class Importer(models.Model):
inserted
=
0
for
import_mep
in
import_data
:
# We want to know if all mandates exists
if
not
'birthdate'
in
import_mep
or
not
'first_name'
in
import_mep
or
not
'last_name'
in
import_mep
:
if
not
'birth
_
date'
in
import_mep
or
not
'first_name'
in
import_mep
or
not
'last_name'
in
import_mep
:
# We do not have enough field to discriminate our meps
continue
updated_mep
=
{}
updated_mep
[
'groups'
]
=
[]
for
mandate
in
import_mep
[
'mandates'
]:
if
mandate
[
'end_date'
]
!=
''
:
# Parltrack gives us a date starting with 9999 if ends has not happens
# FranceData gives us an empty one
if
'end_date'
in
mandate
and
(
mandate
[
'end_date'
]
!=
''
or
mandate
[
'end_date'
].
startswith
(
'9999'
)):
# This mandate has ended
continue
groupType
,
added
=
GroupType
.
objects
.
get_or_create
(
organization
=
self
.
organization
,
...
...
@@ -93,19 +95,22 @@ class Importer(models.Model):
group
,
added
=
Group
.
objects
.
get_or_create
(
name
=
mandate
[
'name'
],
type
=
groupType
)
updated_mep
[
'groups'
].
append
(
group
)
if
updated_mep
[
'groups'
]
==
[]:
del
updated_mep
[
'groups'
]
# All groups are done
# If we have a contact item, we can go through it. Otherwise we probably have
# phone, twitter, etc fields.
if
'contacts'
in
import_mep
:
# Let's get the first phone
if
import_mep
[
'contacts'
][
'phones'
]
!=
[]:
updated_
emp
[
'phone'
]
=
mep
[
'contacts'
][
'phones'
][
0
][
'phone
'
]
updated_
mep
[
'phone'
]
=
import_mep
[
'contacts'
][
'phones'
][
0
][
'number
'
]
if
import_mep
[
'contacts'
][
'emails'
]
!=
[]:
updated_mep
[
'mail'
]
=
mep
[
'contacts'
][
'phones'
][
0
][
'phone
'
]
updated_mep
[
'mail'
]
=
import_mep
[
'contacts'
][
'emails'
][
0
][
'email
'
]
if
import_mep
[
'contacts'
][
'websites'
]
!=
[]:
for
website
in
import_mep
[
'contacts'
][
'websites'
]:
if
website
[
'kind'
]
==
'twitter'
:
updated_mep
[
'twitter'
]
=
''
.
join
([
'@'
,
website
[
'
website
'
].
split
(
'/'
)[
-
1
]])
updated_mep
[
'twitter'
]
=
''
.
join
([
'@'
,
website
[
'
url
'
].
split
(
'/'
)[
-
1
]])
break
else
:
# We have phone, mail, twitter fields
...
...
@@ -116,11 +121,11 @@ class Importer(models.Model):
if
'twitter'
in
import_mep
:
updated_mep
[
'twitter'
]
=
import_mep
[
'twitter'
]
#
All groups are done
#
import ipdb; ipdb.set_trace()
# Let's update_or_create the mep
mep
,
updated
=
Contact
.
objects
.
update_or_create
(
first_name
=
import_mep
[
'first_name'
],
last_name
=
import_mep
[
'last_name'
],
birthdate
=
import_mep
[
'birthdate'
],
birthdate
=
import_mep
[
'birth
_
date'
],
defaults
=
updated_mep
)
inserted
+=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment