summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Boulanger <christophe.boulanger@imio.be>2017-02-28 15:19:49 (GMT)
committerChristophe Boulanger <christophe.boulanger@imio.be>2017-02-28 15:20:07 (GMT)
commit40af77b2677f94d81521d6668d1d3aefd12376c9 (patch)
tree014827f17ef439d6e7048417430f8ed6355d8bba
parent2765059990ea7639bbdf8d586ead01908128c4d2 (diff)
downloadpasserelle-imio-ts1-datasources-40af77b2677f94d81521d6668d1d3aefd12376c9.zip
passerelle-imio-ts1-datasources-40af77b2677f94d81521d6668d1d3aefd12376c9.tar.gz
passerelle-imio-ts1-datasources-40af77b2677f94d81521d6668d1d3aefd12376c9.tar.bz2
Add management for ts1 terms (manage.py). usage : bin/manage.py ts1_terms_manage [options]
-rw-r--r--passerelle_imio_ts1_datasources/management/__init__.py0
-rw-r--r--passerelle_imio_ts1_datasources/management/commands/__init__.py0
-rw-r--r--passerelle_imio_ts1_datasources/management/commands/ts1_terms_manage.py48
3 files changed, 48 insertions, 0 deletions
diff --git a/passerelle_imio_ts1_datasources/management/__init__.py b/passerelle_imio_ts1_datasources/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/passerelle_imio_ts1_datasources/management/__init__.py
diff --git a/passerelle_imio_ts1_datasources/management/commands/__init__.py b/passerelle_imio_ts1_datasources/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/passerelle_imio_ts1_datasources/management/commands/__init__.py
diff --git a/passerelle_imio_ts1_datasources/management/commands/ts1_terms_manage.py b/passerelle_imio_ts1_datasources/management/commands/ts1_terms_manage.py
new file mode 100644
index 0000000..684709b
--- /dev/null
+++ b/passerelle_imio_ts1_datasources/management/commands/ts1_terms_manage.py
@@ -0,0 +1,48 @@
+from django.core.management.base import BaseCommand, CommandError
+from passerelle_imio_ts1_datasources.models import MotivationTerm, DestinationTerm
+import json
+
+
+class Command(BaseCommand):
+ help = 'Import TS1 Motivationterms in TS2.'
+
+ def add_arguments(self, parser):
+ parser.add_argument('--motivationterms_filepath', type=str)
+ parser.add_argument('--destinationterms_filepath', type=str)
+ parser.add_argument('--remove_all_terms', action='store_true')
+
+ def handle(self, *args, **options):
+ motivationterms_filepath = options['motivationterms_filepath']
+ destinationterms_filepath = options['destinationterms_filepath']
+ remove_all_terms = options['remove_all_terms']
+ if remove_all_terms is True:
+ self.remove_all_terms()
+ if motivationterms_filepath is not None:
+ self.motivationterms_import(motivationterms_filepath)
+ if destinationterms_filepath is not None:
+ self.destinationterms_import(destinationterms_filepath)
+
+ def remove_all_terms(self):
+ MotivationTerm.objects.all().delete()
+ DestinationTerm.objects.all().delete()
+
+ def motivationterms_import(self, path):
+ data = {}
+ with open(path) as data_file:
+ data = json.load(data_file)
+ for motivationterm in data:
+ mt_object = MotivationTerm(text=motivationterm["text"],
+ price=motivationterm["price"],
+ description=motivationterm["description"])
+ mt_object.save()
+
+ def destinationterms_import(self, path):
+ data = {}
+ with open(path) as data_file:
+ data = json.load(data_file)
+ for destinationterm in data:
+ mt_object = DestinationTerm(text=destinationterm["text"],
+ price=destinationterm["price"],
+ description=destinationterm["description"],
+ paymentrequired=destinationterm["paymentRequired"])
+ mt_object.save()