Handle geodata and offline requests

This commit is contained in:
PCoder 2021-07-27 13:43:27 +05:30
parent 984eaa68f6
commit 386ea46310
4 changed files with 1185 additions and 1 deletions

View file

@ -0,0 +1,54 @@
<!DOCTYPE HTML>
<html>
<head>
<title>GMBA Connect</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="{% static 'app/assets/js/ie/html5shiv.js' %}"></script><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="{% static 'app/assets/ss/ie8.css' %}" /><![endif]-->
<!--[if lte IE 9]><link rel="stylesheet" href="{% static 'app/assets/ss/ie9.css' %}" /><![endif]-->
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.5/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="{% static 'app/assets/js/leaflet/leaflet.css' %}">
<link rel="stylesheet" href="{% static 'app/assets/css/blaze.min.css' %}">
<link rel="stylesheet" href="{% static 'app/assets/css/material-icons.css' %}">
<link rel="stylesheet" href="{% static 'app/gmba-index.css' %}">
</head>
<body>
<blaze-site>
<!-- Main -->
<main>
<div class="container">
<gmba-search></gmba-search>
<noscript>
<u>This application requires JavaScript to work.</u>
</noscript>
</div>
</section>
<h5 style="display:none"><a href="#" id="logo"><em>GMBA</em> Connect</a></h5>
</blaze-site>
<!-- Riot tags -->
<script src="{% static 'app/gmba-search.tag' %}" type="riot/tag"></script>
<!-- Scripts -->
<script src="{% static 'app/assets/js/zepto.min.js' %}"></script>
<script src="{% static 'app/assets/js/qs.min.js' %}"></script>
<script src="{% static 'app/assets/js/leaflet/leaflet.js' %}"></script>
<script src="{% static 'app/assets/js/leaflet/leaflet.ajax.min.js' %}"></script>
<script src="{% static 'app/assets/js/riot+compiler.min.js' %}"></script>
<script src="{% static 'app/assets/js/rg.min.js' %}"></script>
<script language="JavaScript">riot.mount('gmba-search')</script>
</body>
</html>

View file

@ -1,8 +1,10 @@
import os
from django.views.generic.base import TemplateView
from django.http import FileResponse
import os.path as ospath
from os import makedirs
from shutil import move
from tempfile import gettempdir
from .formats import *
@ -31,3 +33,24 @@ class HomePageView(TemplateView):
f['ready'] = ospath.isfile(get_datafile(f))
context = super().get_context_data(**kwargs)
return context
class OfflinePageView(TemplateView):
template_name = "app/offline.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
return context
def send_from_file(request, path):
request_for = ''
if request.path.startswith('/geodata'):
request_for = 'geodata'
elif request.path.startswith('/data'):
request_for = 'data'
file_path = ospath.join(DATA_PATH, request_for, path)
file_to_send = open(file_path, 'rb')
response = FileResponse(file_to_send)
return response

1050
geodata/gmba.geojson Normal file

File diff suppressed because one or more lines are too long

View file

@ -15,7 +15,64 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
from app.views import HomePageView, OfflinePageView, send_from_file
FILTER_QUERIES = [ 'country', 'range', 'field', 'taxon' ]
def get_paginated(query, request):
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 10))
ppp = query.paginate(page, per_page, error_out=False)
filters = {
'country': [],
'range': [],
'field': [],
'taxon': [],
}
for p in ppp.items:
filters['country'].append(p.country)
for r in p.ranges:
filters['range'].append(r.name)
for r in p.research_fields:
filters['field'].append(r.name)
for r in p.research_taxa:
filters['taxon'].append(r.name)
filters = {
'country': sorted(set(filters['country'])),
'range': sorted(set(filters['range'])),
'field': sorted(set(filters['field'])),
'taxon': sorted(set(filters['taxon'])),
}
if len(query.all()) > len(ppp.items) and ppp.pages == 1:
ppp.items = query.all()
ppp.total = len(ppp.items)
return {
'items': [p.dict() for p in ppp.items],
'filters': filters,
'page': page, 'pages': ppp.pages, 'total': ppp.total,
'has_next': ppp.has_next, 'has_prev': ppp.has_prev
}
urlpatterns = [
path('', HomePageView.as_view(), name='home'),
path('offline', OfflinePageView.as_view(), name='offline'),
path('demo/', admin.site.urls),
path('geodata/<path:path>/', send_from_file, name='send_file'),
path('data/<path:path>', admin.site.urls),
path('reindex/', admin.site.urls),
path('progress/', admin.site.urls),
path('refresh/', admin.site.urls),
path('upload/', admin.site.urls),
path('api/taxa', admin.site.urls),
path('api/fields', admin.site.urls),
path('api/ranges', admin.site.urls),
path('api/resources', admin.site.urls),
path('api/people', admin.site.urls),
path('api/people/<int:people_id>', admin.site.urls),
path('api/search', admin.site.urls),
]