From 2172eee2837e159ef0474843b91a7650188145e2 Mon Sep 17 00:00:00 2001 From: Jason Yuan Date: Sat, 19 Dec 2020 15:15:40 -0600 Subject: [PATCH 1/2] buttons working csv not converted --- main/templates/main/partners/map.html | 3 ++- main/urls.py | 4 ++-- main/views/partners.py | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/main/templates/main/partners/map.html b/main/templates/main/partners/map.html index 2f208ca0a..bba50877f 100644 --- a/main/templates/main/partners/map.html +++ b/main/templates/main/partners/map.html @@ -48,7 +48,8 @@

{{ organization }}

{% endif %}
- Export All Maps as GeoJSON + Export All as GeoJSON + Export All as CSV
diff --git a/main/urls.py b/main/urls.py index 6a1b96c04..17218239f 100644 --- a/main/urls.py +++ b/main/urls.py @@ -120,12 +120,12 @@ path("export/", views.main.ExportView.as_view(), name="export"), path("export//", views.main.ExportView.as_view(), name="export"), path( - "multiexport/drive/", + "multiexport/drive///", views.partners.MultiExportView.as_view(), name="multi_export", ), path( - "multiexport/org/", + "multiexport/org///", views.partners.MultiExportView.as_view(), name="multi_export", ), diff --git a/main/views/partners.py b/main/views/partners.py index 7c74ea21f..d243be50b 100644 --- a/main/views/partners.py +++ b/main/views/partners.py @@ -259,6 +259,11 @@ def get(self, request, drive=None, org=None, **kwargs): response = HttpResponse( geojson.dumps(final), content_type="application/json" ) + + if(kwargs['type'] == 'geo'): + print('geo') + else: + print('csv + NEED TO CONVERT STUFF') return response From 23383a1f42efa5618d451c5d048dcaa6f52547e0 Mon Sep 17 00:00:00 2001 From: Jason Yuan Date: Sat, 19 Dec 2020 16:09:32 -0600 Subject: [PATCH 2/2] working csv all export --- main/views/partners.py | 18 ++++++++++++------ requirements.txt | 31 +++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/main/views/partners.py b/main/views/partners.py index d243be50b..b1cc296a1 100644 --- a/main/views/partners.py +++ b/main/views/partners.py @@ -21,6 +21,7 @@ import asyncio import boto3 import botocore +import pandas from django.contrib.gis import geos from django.contrib.gis.geos import GEOSGeometry, MultiPolygon, Polygon @@ -256,14 +257,19 @@ def get(self, request, drive=None, org=None, **kwargs): final = geojson.FeatureCollection(all_gj) - response = HttpResponse( - geojson.dumps(final), content_type="application/json" - ) - if(kwargs['type'] == 'geo'): - print('geo') + print('********', 'geo', '********') + response = HttpResponse(geojson.dumps(final), content_type="application/json") else: - print('csv + NEED TO CONVERT STUFF') + print('********', 'csv', '********') + dictform = json.loads(geojson.dumps(final)) + df = pandas.DataFrame() + for entry in dictform['features']: + row_dict = entry['properties'].copy() + row_dict['geometry'] = str(entry['geometry']) + df = df.append(row_dict, ignore_index=True) + response = HttpResponse(df.to_csv(), content_type="text/csv") + return response diff --git a/requirements.txt b/requirements.txt index f42194485..ff221c18e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +arabic-reshaper==2.1.1 astroid==2.3.3 autopep8==1.4.4 boto3==1.16.22 @@ -6,61 +7,83 @@ certifi==2019.3.9 chardet==3.0.4 Click==7.0 defusedxml==0.5.0 +diff-match-patch==20200713 dj-database-url==0.5.0 Django==2.2.13 django-allauth==0.39.1 django-appconf==1.0.3 django-bmemcached==0.2.4 +django-ckeditor==5.9.0 django-crispy-forms==1.7.2 +django-extensions==3.0.9 django-heroku==0.3.1 +django-import-export==2.2.0 +django-js-asset==1.2.2 django-leaflet==0.24.0 +django-phone-field==1.8.0 django-redis==4.10.0 django-redis-cache==2.0.0 django-select2==6.3.1 django-widget-tweaks==1.4.3 -django-extensions==3.0.9 +et-xmlfile==1.0.1 Faker==1.0.5 +future==0.18.2 geojson==2.4.1 geojson-rewind==0.2.0 gunicorn==19.9.0 +html5lib==1.1 idna==2.8 isort==4.3.21 itsdangerous==1.1.0 +jdcal==1.4.1 Jinja2==2.10.1 +jmespath==0.10.0 lazy-object-proxy==1.4.3 licenseheaders==0.6 +MarkupPy==1.14 MarkupSafe==1.1.1 mccabe==0.6.1 numpy==1.17.4 oauthlib==3.0.1 +odfpy==1.4.1 +openpyxl==3.0.5 +pandas==1.1.5 +Pillow==8.0.1 psycopg2==2.7.6 psycopg2-binary==2.7.7 pycodestyle==2.5.0 pylibmc==1.6.0 pylint==2.4.4 +PyPDF2==1.26.0 +python-bidi==0.4.2 python-binary-memcached==0.28.0 python-dateutil==2.8.0 python3-openid==3.1.0 pytz==2018.9 +PyYAML==5.3.1 redis==3.2.1 +reportlab==3.5.56 requests==2.21.0 requests-oauthlib==1.2.0 reverse-geocoder==1.5.1 +s3transfer==0.3.3 scipy==1.3.3 selenium==3.141.0 Shapely==1.6.4.post2 singledispatch==3.4.0.3 six==1.12.0 sqlparse==0.3.0 +tablib==2.0.0 text-unidecode==1.2 typed-ast==1.4.0 typing==3.6.6 uhashring==1.1 urllib3==1.24.2 virtualenv==16.4.3 +webencodings==0.5.1 Werkzeug==0.15.4 whitenoise==4.1.2 wrapt==1.11.2 -django-phone-field==1.8.0 -django-import-export==2.2.0 -django-ckeditor==5.9.0 +xhtml2pdf==0.2.5 +xlrd==1.2.0 +xlwt==1.3.0