diff --git a/django/website/chn_spreadsheet/migrations/0007_update_rapidpro_config.py b/django/website/chn_spreadsheet/migrations/0007_update_rapidpro_config.py new file mode 100644 index 0000000000000000000000000000000000000000..77aaafd2e476effb94d75c96dd352db51a5518fc --- /dev/null +++ b/django/website/chn_spreadsheet/migrations/0007_update_rapidpro_config.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + + +RAPIDPRO_CONFIG = { + "label": "rapidpro", + "name": "RapidPro", + "format": "excel", + "type": "rumor", + "columns": [ + { + "name": "Phone", + "type": "ignore", + "field": "ignore" + }, + { + "name": "Name", + "type": "ignore", + "field": "ignore" + }, + { + "name": "Groups", + "type": "ignore", + "field": "ignore" + }, + { + "name": "Last Seen", + "type": "date", + "field": "timestamp", + "date_format": "%m/%d/%y %H:%M:%S" + }, + { + "name": "Rumors (Text) - DEY Say sample flow", + "type": "text", + "field": "body" + }, + { + "name": "Channel", + "type": "text", + "field": "network_provider" + } + ], + "skip_header": 1 +} + + +def update_rapidpro_config(apps, schema_editor): + Profile = apps.get_model('chn_spreadsheet', 'SheetProfile') + Profile.objects.filter(label='rapidpro').update(profile=RAPIDPRO_CONFIG) + + +class Migration(migrations.Migration): + + dependencies = [ + ('chn_spreadsheet', '0006_update_rapidpro_config'), + ] + + operations = [ + migrations.RunPython(update_rapidpro_config) + ] diff --git a/django/website/chn_spreadsheet/tests/rapidpro_tests.py b/django/website/chn_spreadsheet/tests/rapidpro_tests.py index cf26497c4b5638f6c23af22e67dc4fb4cdcd137d..f35c839264a8ed429c846c5a26fea3730242e44f 100644 --- a/django/website/chn_spreadsheet/tests/rapidpro_tests.py +++ b/django/website/chn_spreadsheet/tests/rapidpro_tests.py @@ -27,6 +27,7 @@ def test_items_imported(importer): assert items[0]['body'] == "That there is a special budget to give money to the family of each dead in Liberia since the Ebola outbreak." assert items[0]['timestamp'] == pytz.utc.localize( datetime.datetime(2015, 4, 19, 21, 35, 20)) + assert items[0]['network_provider'] == '8737 (Cellcom)' item_types = transport.taxonomies.term_itemcount( slug='item-types') diff --git a/django/website/data_layer/migrations/0006_message_network_provider.py b/django/website/data_layer/migrations/0006_message_network_provider.py new file mode 100644 index 0000000000000000000000000000000000000000..6aeca506b6359b33950c7c2d6382cd35e078254b --- /dev/null +++ b/django/website/data_layer/migrations/0006_message_network_provider.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('data_layer', '0005_message_last_modified'), + ] + + operations = [ + migrations.AddField( + model_name='message', + name='network_provider', + field=models.CharField(max_length=200, blank=True), + ), + ] diff --git a/django/website/data_layer/models.py b/django/website/data_layer/models.py index 97fbebfad810f236561d0ad8cdb82da7288227ea..c7dce24f93e1aea8a913fd0ae59122ba8de70981 100644 --- a/django/website/data_layer/models.py +++ b/django/website/data_layer/models.py @@ -21,6 +21,7 @@ class Message(DataLayerModel): body = models.TextField() timestamp = models.DateTimeField(null=True) terms = models.ManyToManyField(Term, related_name="items") + network_provider = models.CharField(max_length=200, blank=True) def apply_term(self, term): # TODO: test this