Skip to content

Commit

Permalink
Merge pull request #518 from Representable/multi-export-csv
Browse files Browse the repository at this point in the history
Multi export csv
  • Loading branch information
jasony123123 authored Dec 21, 2020
2 parents a247dea + 23383a1 commit 91589ef
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
3 changes: 2 additions & 1 deletion main/templates/main/partners/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ <h4 class="font-weight-light text-center my-2"> {{ organization }} </h4>
{% endif %}
</div>
<div class="row justify-content-center">
<a class="mb-2 btn btn-outline-primary btn-canvas mx-auto d-none d-sm-block" href={{multi_export_link}} role="button" download="communities.geojson">Export All Maps as GeoJSON</a>
<a class="mb-2 btn btn-outline-primary btn-canvas mx-auto d-none d-sm-block" href={{multi_export_link}}/geo/ role="button" download="communities.geojson">Export All as GeoJSON</a>
<a class="mb-2 btn btn-outline-primary btn-canvas mx-auto d-none d-sm-block" href={{multi_export_link}}/csv/ role="button" download="communities.csv">Export All as CSV</a>
</div>
<input class="m-2 p-2 rounded border border-secondary" id="search-comm" type="text" placeholder="Search communities...">
<div id="headingOne">
Expand Down
4 changes: 2 additions & 2 deletions main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@
path("export/", views.main.ExportView.as_view(), name="export"),
path("export/<abbr>/", views.main.ExportView.as_view(), name="export"),
path(
"multiexport/drive/<drive>",
"multiexport/drive/<drive>/<type>/",
views.partners.MultiExportView.as_view(),
name="multi_export",
),
path(
"multiexport/org/<org>",
"multiexport/org/<org>/<type>/",
views.partners.MultiExportView.as_view(),
name="multi_export",
),
Expand Down
17 changes: 14 additions & 3 deletions main/views/partners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -278,9 +279,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', '********')
response = HttpResponse(geojson.dumps(final), content_type="application/json")
else:
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


Expand Down
31 changes: 27 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
arabic-reshaper==2.1.1
astroid==2.3.3
autopep8==1.4.4
boto3==1.16.22
Expand All @@ -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

0 comments on commit 91589ef

Please sign in to comment.