Commit c5fe59b2 authored by Arnaud Fabre's avatar Arnaud Fabre

adds command to import 1 proposal

parent e787f2dd
# coding: utf-8
# This file is part of toutatis.
# toutatis is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
# toutatis is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# See the GNU Affero General Public License for more details.
# You should have received a copy of the GNU General Affero Public
# License along with Foobar.
# If not, see <>.
# Copyright (C) 2013 Laurent Peuch <>
# Copyright (C) 2015 Arnaud Fabre <>
import json
from urllib2 import urlopen
from import BaseCommand
from django.conf import settings
from representatives_votes.utils import import_a_dossier
class Command(BaseCommand):
def handle(self, *args, **options):
proposal_id = args[0]
toutatis_server = getattr(settings,
proposal_url = '{}/api/proposals/{}'.format(toutatis_server, proposal_id)
print('Import proposal from {}'.format(proposal_url))
proposal_data = json.load(urlopen(proposal_url))
dossier_url = proposal_data['dossier']
dossier_data = json.load(urlopen(dossier_url))
# Replace dossier proposals by the one proposal we want
dossier_data['proposals'] = [proposal_data]
......@@ -23,6 +23,7 @@ from representatives_votes.serializers import DossierDetailSerializer
# Import a dossier
def import_a_dossier(data):
serializer = DossierDetailSerializer(data=data)
if serializer.is_valid():
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