From 1cbf08856e2c31a5046a217889b7141e1e80d93f Mon Sep 17 00:00:00 2001
From: Alan M Jackson <alan@aptivate.org>
Date: Wed, 8 Apr 2020 12:55:37 +0100
Subject: [PATCH] Changed the covid importer to import more fields and install
 the json admin editor

---
 Pipfile                                 |   3 +-
 Pipfile.lock                            | 117 ++++++++++++++----------
 internewshid/chn_spreadsheet/admin.py   |  12 ++-
 internewshid/dashboard/admin.py         |   7 ++
 internewshid/hid/fixtures/covid-19.json |   4 +-
 internewshid/settings.py                |   1 +
 internewshid/tabbed_page/admin.py       |   7 ++
 7 files changed, 99 insertions(+), 52 deletions(-)

diff --git a/Pipfile b/Pipfile
index edc6a86b..bf7e578b 100644
--- a/Pipfile
+++ b/Pipfile
@@ -10,7 +10,7 @@ python_version = "3.6"
 asgiref = "*"
 "django-bootstrap3" = "*"
 "django-tables2" = "*"
-"django.js" = {editable = true,git = "https://git@github.com/aptivate/django.js.git",ref = "ca328a94b00023bd64f4fc1c908675edaaf2ac19"}
+"django.js" = {ref = "ca328a94b00023bd64f4fc1c908675edaaf2ac19",git = "https://git@github.com/aptivate/django.js.git",editable = true}
 "linecache2" = "*"
 Django = ">2.2.8,<3.0"
 Pillow = "*"
@@ -33,6 +33,7 @@ rest-pandas = "*"
 mysqlclient = "*"
 django-debug-toolbar-template-timings = "*"
 ipdb = "*"
+django-jsoneditor = "*"
 
 [dev-packages]
 django-debug-toolbar = "*"
diff --git a/Pipfile.lock b/Pipfile.lock
index bad64889..f9657a09 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "853bc2ef3d6225526ec3254e2e004b9d724e7d198064ad801c0b47c0bd8e4943"
+            "sha256": "ca4eab6f51db983f5d27b4bd604989a90057dfd18a125558273c13e19b610f61"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -47,11 +47,11 @@
         },
         "django": {
             "hashes": [
-                "sha256:65e2387e6bde531d3bb803244a2b74e0253550a9612c64a60c8c5be267b30f50",
-                "sha256:b51c9c548d5c3b3ccbb133d0bebc992e8ec3f14899bce8936e6fdda6b23a1881"
+                "sha256:69897097095f336d5aeef45b4103dceae51c00afa6d3ae198a2a18e519791b7a",
+                "sha256:6ecd229e1815d4fc5240fc98f1cca78c41e7a8cd3e3f2eefadc4735031077916"
             ],
             "index": "pypi",
-            "version": "==2.2.11"
+            "version": "==2.2.12"
         },
         "django-assets": {
             "hashes": [
@@ -130,6 +130,14 @@
             "git": "https://git@github.com/aptivate/django.js.git",
             "ref": "ca328a94b00023bd64f4fc1c908675edaaf2ac19"
         },
+        "django-jsoneditor": {
+            "hashes": [
+                "sha256:574f33a60271f464cad5739b6f4718aca81a779188297faa5adab41754cac9ba",
+                "sha256:e74760740ef5ecb0d295bb07c21635d2bebea7b9bab4352fa403720cc275a905"
+            ],
+            "index": "pypi",
+            "version": "==0.1.6"
+        },
         "django-picklefield": {
             "hashes": [
                 "sha256:67a5e156343e3b032cac2f65565f0faa81635a99c7da74b0f07a0f5db467b646",
@@ -139,11 +147,11 @@
         },
         "django-tables2": {
             "hashes": [
-                "sha256:0d9b17f5c030ba1b5fcaeb206d8397bf58f1fdfc6beaf56e7874841b8647aa94",
-                "sha256:6afa0496695e15b332e98537265d09fe01a55b28c75a85323d8e6b0dc2350280"
+                "sha256:28da782f81f046c7d921246f43e7ba2df430cafe5a0e00a0f9dadef25a0e487d",
+                "sha256:7e425ad51e22caf5470351981f0fcd4fd35d4cf2d4c3b76fa1b7bf56251778d1"
             ],
             "index": "pypi",
-            "version": "==2.2.1"
+            "version": "==2.3.1"
         },
         "django-widget-tweaks": {
             "hashes": [
@@ -280,6 +288,13 @@
             "index": "pypi",
             "version": "==3.0.3"
         },
+        "packaging": {
+            "hashes": [
+                "sha256:3c292b474fda1671ec57d46d739d072bfd495a4f51ad01a055121d81e952b7a3",
+                "sha256:82f77b9bee21c1bafbf35a84905d604d5d1223801d639cf3ed140bd651c08752"
+            ],
+            "version": "==20.3"
+        },
         "pandas": {
             "hashes": [
                 "sha256:07c1b58936b80eafdfe694ce964ac21567b80a48d972879a359b3ebb2ea76835",
@@ -325,31 +340,31 @@
         },
         "pillow": {
             "hashes": [
-                "sha256:0a628977ac2e01ca96aaae247ec2bd38e729631ddf2221b4b715446fd45505be",
-                "sha256:4d9ed9a64095e031435af120d3c910148067087541131e82b3e8db302f4c8946",
-                "sha256:54ebae163e8412aff0b9df1e88adab65788f5f5b58e625dc5c7f51eaf14a6837",
-                "sha256:5bfef0b1cdde9f33881c913af14e43db69815c7e8df429ceda4c70a5e529210f",
-                "sha256:5f3546ceb08089cedb9e8ff7e3f6a7042bb5b37c2a95d392fb027c3e53a2da00",
-                "sha256:5f7ae9126d16194f114435ebb79cc536b5682002a4fa57fa7bb2cbcde65f2f4d",
-                "sha256:62a889aeb0a79e50ecf5af272e9e3c164148f4bd9636cc6bcfa182a52c8b0533",
-                "sha256:7406f5a9b2fd966e79e6abdaf700585a4522e98d6559ce37fc52e5c955fade0a",
-                "sha256:8453f914f4e5a3d828281a6628cf517832abfa13ff50679a4848926dac7c0358",
-                "sha256:87269cc6ce1e3dee11f23fa515e4249ae678dbbe2704598a51cee76c52e19cda",
-                "sha256:875358310ed7abd5320f21dd97351d62de4929b0426cdb1eaa904b64ac36b435",
-                "sha256:8ac6ce7ff3892e5deaab7abaec763538ffd011f74dc1801d93d3c5fc541feee2",
-                "sha256:91b710e3353aea6fc758cdb7136d9bbdcb26b53cefe43e2cba953ac3ee1d3313",
-                "sha256:9d2ba4ed13af381233e2d810ff3bab84ef9f18430a9b336ab69eaf3cd24299ff",
-                "sha256:a62ec5e13e227399be73303ff301f2865bf68657d15ea50b038d25fc41097317",
-                "sha256:ab76e5580b0ed647a8d8d2d2daee170e8e9f8aad225ede314f684e297e3643c2",
-                "sha256:bf4003aa538af3f4205c5fac56eacaa67a6dd81e454ffd9e9f055fff9f1bc614",
-                "sha256:bf598d2e37cf8edb1a2f26ed3fb255191f5232badea4003c16301cb94ac5bdd0",
-                "sha256:c18f70dc27cc5d236f10e7834236aff60aadc71346a5bc1f4f83a4b3abee6386",
-                "sha256:c5ed816632204a2fc9486d784d8e0d0ae754347aba99c811458d69fcdfd2a2f9",
-                "sha256:dc058b7833184970d1248135b8b0ab702e6daa833be14035179f2acb78ff5636",
-                "sha256:ff3797f2f16bf9d17d53257612da84dd0758db33935777149b3334c01ff68865"
-            ],
-            "index": "pypi",
-            "version": "==7.0.0"
+                "sha256:04a10558320eba9137d6a78ca6fc8f4a5801f1b971152938851dc4629d903579",
+                "sha256:0f89ddc77cf421b8cd34ae852309501458942bf370831b4a9b406156b599a14e",
+                "sha256:251e5618125ec12ac800265d7048f5857a8f8f1979db9ea3e11382e159d17f68",
+                "sha256:291bad7097b06d648222b769bbfcd61e40d0abdfe10df686d20ede36eb8162b6",
+                "sha256:2f0b52a08d175f10c8ea36685115681a484c55d24d0933f9fd911e4111c04144",
+                "sha256:3713386d1e9e79cea1c5e6aaac042841d7eef838cc577a3ca153c8bedf570287",
+                "sha256:433bbc2469a2351bea53666d97bb1eb30f0d56461735be02ea6b27654569f80f",
+                "sha256:4510c6b33277970b1af83c987277f9a08ec2b02cc20ac0f9234e4026136bb137",
+                "sha256:50a10b048f4dd81c092adad99fa5f7ba941edaf2f9590510109ac2a15e706695",
+                "sha256:670e58d3643971f4afd79191abd21623761c2ebe61db1c2cb4797d817c4ba1a7",
+                "sha256:6c1924ed7dbc6ad0636907693bbbdd3fdae1d73072963e71f5644b864bb10b4d",
+                "sha256:721c04d3c77c38086f1f95d1cd8df87f2f9a505a780acf8575912b3206479da1",
+                "sha256:8d5799243050c2833c2662b824dfb16aa98e408d2092805edea4300a408490e7",
+                "sha256:90cd441a1638ae176eab4d8b6b94ab4ec24b212ed4c3fbee2a6e74672481d4f8",
+                "sha256:a5dc9f28c0239ec2742d4273bd85b2aa84655be2564db7ad1eb8f64b1efcdc4c",
+                "sha256:b2f3e8cc52ecd259b94ca880fea0d15f4ebc6da2cd3db515389bb878d800270f",
+                "sha256:b7453750cf911785009423789d2e4e5393aae9cbb8b3f471dab854b85a26cb89",
+                "sha256:b99b2607b6cd58396f363b448cbe71d3c35e28f03e442ab00806463439629c2c",
+                "sha256:cd47793f7bc9285a88c2b5551d3f16a2ddd005789614a34c5f4a598c2a162383",
+                "sha256:d6bf085f6f9ec6a1724c187083b37b58a8048f86036d42d21802ed5d1fae4853",
+                "sha256:da737ab273f4d60ae552f82ad83f7cbd0e173ca30ca20b160f708c92742ee212",
+                "sha256:eb84e7e5b07ff3725ab05977ac56d5eeb0c510795aeb48e8b691491be3c5745b"
+            ],
+            "index": "pypi",
+            "version": "==7.1.1"
         },
         "prompt-toolkit": {
             "hashes": [
@@ -372,6 +387,13 @@
             ],
             "version": "==2.6.1"
         },
+        "pyparsing": {
+            "hashes": [
+                "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1",
+                "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"
+            ],
+            "version": "==2.4.7"
+        },
         "python-dateutil": {
             "hashes": [
                 "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c",
@@ -457,10 +479,10 @@
         },
         "certifi": {
             "hashes": [
-                "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3",
-                "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f"
+                "sha256:1d987a998c75633c40847cc966fcf5904906c920a7f17ef374f5aa4282abd304",
+                "sha256:51fcb31174be6e6664c5f69e3e1691a2d72a1a12e90f872cbdb1567eb47b6519"
             ],
-            "version": "==2019.11.28"
+            "version": "==2020.4.5.1"
         },
         "chardet": {
             "hashes": [
@@ -520,11 +542,11 @@
         },
         "django": {
             "hashes": [
-                "sha256:65e2387e6bde531d3bb803244a2b74e0253550a9612c64a60c8c5be267b30f50",
-                "sha256:b51c9c548d5c3b3ccbb133d0bebc992e8ec3f14899bce8936e6fdda6b23a1881"
+                "sha256:69897097095f336d5aeef45b4103dceae51c00afa6d3ae198a2a18e519791b7a",
+                "sha256:6ecd229e1815d4fc5240fc98f1cca78c41e7a8cd3e3f2eefadc4735031077916"
             ],
             "index": "pypi",
-            "version": "==2.2.11"
+            "version": "==2.2.12"
         },
         "django-debug-toolbar": {
             "hashes": [
@@ -692,11 +714,10 @@
         },
         "pyparsing": {
             "hashes": [
-                "sha256:4c830582a84fb022400b85429791bc551f1f4871c33f23e44f353119e92f969f",
-                "sha256:c342dccb5250c08d45fd6f8b4a559613ca603b57498511740e65cd11a2e7dcec"
+                "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1",
+                "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"
             ],
-            "index": "pypi",
-            "version": "==2.4.6"
+            "version": "==2.4.7"
         },
         "pytest": {
             "hashes": [
@@ -826,10 +847,10 @@
         },
         "virtualenv": {
             "hashes": [
-                "sha256:4e399f48c6b71228bf79f5febd27e3bbb753d9d5905776a86667bc61ab628a25",
-                "sha256:9e81279f4a9d16d1c0654a127c2c86e5bca2073585341691882c1e66e31ef8a5"
+                "sha256:6ea131d41c477f6c4b7863948a9a54f7fa196854dbef73efbdff32b509f4d8bf",
+                "sha256:94f647e12d1e6ced2541b93215e51752aecbd1bbb18eb1816e2867f7532b1fe1"
             ],
-            "version": "==20.0.15"
+            "version": "==20.0.16"
         },
         "virtualenv-clone": {
             "hashes": [
@@ -847,11 +868,11 @@
         },
         "werkzeug": {
             "hashes": [
-                "sha256:169ba8a33788476292d04186ab33b01d6add475033dfc07215e6d219cc077096",
-                "sha256:6dc65cf9091cf750012f56f2cad759fa9e879f511b5ff8685e456b4e3bf90d16"
+                "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43",
+                "sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c"
             ],
             "index": "pypi",
-            "version": "==1.0.0"
+            "version": "==1.0.1"
         },
         "zipp": {
             "hashes": [
diff --git a/internewshid/chn_spreadsheet/admin.py b/internewshid/chn_spreadsheet/admin.py
index 8d9c49b6..0b221680 100644
--- a/internewshid/chn_spreadsheet/admin.py
+++ b/internewshid/chn_spreadsheet/admin.py
@@ -1,5 +1,15 @@
 from django.contrib import admin
 
+from jsoneditor.forms import JSONEditor
+from jsonfield import JSONField
+
 from .models import SheetProfile
 
-admin.site.register(SheetProfile, admin.ModelAdmin)
+
+class SheetProfileAdmin(admin.ModelAdmin):
+    formfield_overrides = {
+        JSONField: {'widget': JSONEditor},
+    }
+
+
+admin.site.register(SheetProfile, SheetProfileAdmin)
diff --git a/internewshid/dashboard/admin.py b/internewshid/dashboard/admin.py
index 826970d1..f426cdc6 100644
--- a/internewshid/dashboard/admin.py
+++ b/internewshid/dashboard/admin.py
@@ -1,9 +1,16 @@
 from django.contrib import admin
 
+from jsoneditor.forms import JSONEditor
+from jsonfield import JSONField
+
 from .models import Dashboard, WidgetInstance
 
 
 class WidgetInstanceInline(admin.StackedInline):
+    formfield_overrides = {
+        JSONField: {'widget': JSONEditor},
+    }
+
     model = WidgetInstance
     extra = 0
 
diff --git a/internewshid/hid/fixtures/covid-19.json b/internewshid/hid/fixtures/covid-19.json
index 9010f83a..8f3279c5 100644
--- a/internewshid/hid/fixtures/covid-19.json
+++ b/internewshid/hid/fixtures/covid-19.json
@@ -71,7 +71,7 @@
     "pk": 7,
     "fields": {
       "label": "Covid 1",
-      "profile": "{\"name\": \"TWB - Covid 1\", \"format\": \"excel\", \"label\": \"Covid 1\", \"skip_header\": 2, \"taxonomies\": {}, \"columns\": [{\"field\": \"timestamp\", \"type\": \"date\", \"name\": \"CREATED\", \"date_format\": \"%d-%m-%Y %Z %H:%M\"}, {\"field\": \"body\", \"type\": \"text\", \"name\": \"FEEDBACK DATA\"}, {\"field\": \"language\", \"type\": \"text\", \"name\": \"LANGUAGE\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Followers/Views/members/retweets/Reach\"}, {\"field\": \"translation\", \"type\": \"text\", \"name\": \"TRANSLATION, NOTES\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"NOTES\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"THEME\", \"taxonomy\": \"covid19-theme\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"HASHTAGS\", \"taxonomy\": \"tags\"}, {\"field\": \"item-types\", \"type\": \"taxonomy\", \"name\": \"TYPE\", \"taxonomy\": \"item-types\"}, {\"field\": \"gender\", \"type\": \"text\", \"name\": \"GENDER\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"AGE\", \"taxonomy\": \"age-ranges\"}, {\"field\": \"location\", \"type\": \"text\", \"name\": \"LOCATION /Platform\"}, {\"field\": \"sub_location\", \"type\": \"text\", \"name\": \"SUB-LOCATION\"}, {\"field\": \"contributor\", \"type\": \"text\", \"name\": \"CONTRIBUTER\"}, {\"field\": \"collection_type\", \"type\": \"text\", \"name\": \"COLLECTION TYPE\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"CONTENT CREATOR TYPE\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"SECONDARY DATE\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"COMMUNITY TYPE\"}, {\"field\": \"risk\", \"type\": \"text\", \"name\": \"RISK\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"LOCATION TYPE\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"TAGS\"}]}"
+      "profile": "{\"name\": \"TWB - Covid 1\", \"format\": \"excel\", \"label\": \"Covid 1\", \"skip_header\": 2, \"taxonomies\": {}, \"columns\": [{\"field\": \"timestamp\", \"type\": \"date\", \"name\": \"CREATED\", \"date_format\": \"%d-%m-%Y %Z %H:%M\"}, {\"field\": \"body\", \"type\": \"text\", \"name\": \"FEEDBACK DATA\"}, {\"field\": \"language\", \"type\": \"text\", \"name\": \"LANGUAGE\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Followers/Views/members/retweets/Reach\"}, {\"field\": \"translation\", \"type\": \"text\", \"name\": \"TRANSLATION, NOTES\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"NOTES\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"THEME\", \"taxonomy\": \"covid19-theme\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"HASHTAGS\", \"taxonomy\": \"tags\"}, {\"field\": \"item-types\", \"type\": \"taxonomy\", \"name\": \"TYPE\", \"taxonomy\": \"item-types\"}, {\"field\": \"gender\", \"type\": \"text\", \"name\": \"GENDER\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"AGE\", \"taxonomy\": \"age-ranges\"}, {\"field\": \"location\", \"type\": \"text\", \"name\": \"LOCATION /Platform\"}, {\"field\": \"sub_location\", \"type\": \"text\", \"name\": \"SUB-LOCATION\"}, {\"field\": \"contributor\", \"type\": \"text\", \"name\": \"CONTRIBUTOR\"}, {\"field\": \"collection_type\", \"type\": \"text\", \"name\": \"COLLECTION TYPE\"}, {\"field\": \"risk\", \"type\": \"text\", \"name\": \"RISK\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"TAGS\"}]}"
     }
   },
   {
@@ -79,7 +79,7 @@
     "pk": 8,
     "fields": {
       "label": "Covid 2",
-      "profile": "{\"name\": \"SBTF - Covid 2\", \"format\": \"excel\", \"label\": \"Covid 2\", \"skip_header\": 2, \"taxonomies\": {}, \"columns\": [{\"field\": \"timestamp\", \"type\": \"date\", \"name\": \"Date of posting\", \"date_format\": \"%d-%b-%Y\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Link\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Source type FB, TW, media etc\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Followers/ Views/ Members\"}, {\"field\": \"language\", \"type\": \"text\", \"name\": \"Original Language\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Specific country referenced?\"}, {\"field\": \"ignore\", \"type\": \"ignore\", \"name\": \"Relatation to Covid-19\"}, {\"field\": \"body\", \"type\": \"text\", \"name\": \"brief summary\"}, {\"field\": \"translation\", \"type\": \"text\", \"name\": \"Extra Notes\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"Hashtags\", \"taxonomy\": \"tags\"}]}"
+      "profile": "{\"name\": \"SBTF - Covid 2\", \"format\": \"excel\", \"label\": \"Covid 2\", \"skip_header\": 2, \"taxonomies\": {}, \"columns\": [{\"field\": \"timestamp\", \"type\": \"date\", \"name\": \"Date of posting\", \"date_format\": \"%d-%b-%Y\"}, {\"field\": \"language\", \"type\": \"text\", \"name\": \"Original Language\"}, {\"field\": \"body\", \"type\": \"text\", \"name\": \"brief summary\"}, {\"field\": \"translation\", \"type\": \"text\", \"name\": \"Extra Notes\"}, {\"field\": \"terms\", \"type\": \"taxonomy\", \"name\": \"Hashtags\", \"taxonomy\": \"tags\"}]}"
     }
   },
   {
diff --git a/internewshid/settings.py b/internewshid/settings.py
index 9b824b1c..86a1dc85 100644
--- a/internewshid/settings.py
+++ b/internewshid/settings.py
@@ -89,6 +89,7 @@ THIRD_PARTY_APPS = (
     'djangojs',
     'django_assets',
     'floppyforms',
+    'jsoneditor',
     'widget_tweaks'
 )
 
diff --git a/internewshid/tabbed_page/admin.py b/internewshid/tabbed_page/admin.py
index 305273b6..e4a7bc57 100644
--- a/internewshid/tabbed_page/admin.py
+++ b/internewshid/tabbed_page/admin.py
@@ -1,9 +1,16 @@
 from django.contrib import admin
 
+from jsoneditor.forms import JSONEditor
+from jsonfield import JSONField
+
 from .models import TabbedPage, TabInstance
 
 
 class TabInline(admin.StackedInline):
+    formfield_overrides = {
+        JSONField: {'widget': JSONEditor},
+    }
+
     model = TabInstance
     extra = 0
 
-- 
GitLab