Commit 98a0fae0 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Recomm import: change delimiter and fix weight

parent 566f4a22
......@@ -40,6 +40,7 @@ class RecommendationImporter:
if dossier is None:
try:
dossier = Dossier.objects.get(title__iexact=title)
self.dossier_cache[title] = dossier
except Dossier.DoesNotExist:
dossier = None
......@@ -63,6 +64,8 @@ class RecommendationImporter:
row['part'], row['title']))
return False
weight = int(row['weight']) * int(row['ponderation'])
try:
recom = Recommendation.objects.get(proposal=proposal)
except Recommendation.DoesNotExist:
......@@ -70,11 +73,11 @@ class RecommendationImporter:
proposal=proposal,
recommendation=row['recommendation'],
title=row['description'],
weight=row['weight']
weight=weight
)
recom.save()
logger.info('Created recommendation with weight %s for %s: %s' % (
row['weight'],
weight,
row['title'],
row['part']
))
......@@ -87,11 +90,11 @@ def main(stream=None):
Imports recommendations from an old memopol instance.
Usage:
cat recommendations.csv | memopol_import_recommendations > rejected.csv
cat recommendations.csv | memopol_import_recommendations
The input CSV file should be generated by the following query:
SELECT CONCAT(r.description, ';', r.weight, ';', r.recommendation, ';',
r.part, ';', p.title)
SELECT CONCAT(r.description, '|', r.weight, '|', r.recommendation, '|',
r.part, '|', p.title, '|', p.ponderation)
FROM votes_recommendation r
LEFT JOIN votes_proposal p ON r.proposal_id = p.id
WHERE p.institution = 'EU'
......@@ -105,12 +108,13 @@ def main(stream=None):
rejected = []
imported = 0
reader = csv.DictReader(stream or sys.stdin, delimiter=';', fieldnames=[
reader = csv.DictReader(stream or sys.stdin, delimiter='|', fieldnames=[
'description',
'weight',
'recommendation',
'part',
'title'
'title',
'ponderation'
], quoting=csv.QUOTE_NONE)
for row in reader:
......
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