gmba_django/gmba_django/urls.py
2021-07-28 17:18:27 +05:30

89 lines
3.3 KiB
Python

"""gmba_django URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
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, DemoPageView, ConfigurationPageView, get_progress, UploadView,
ReindexPageView, RefreshPageView
)
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('geodata/<path:filename>/', send_from_file, name='send_geodata_file'),
path('data/<path:filename>', send_from_file, name='send_data_file'),
path('demo/', DemoPageView.as_view(), name='demo'),
path('admin/', admin.site.urls, name='admin'),
path('config/', ConfigurationPageView.as_view(), name='config'),
path('upload', UploadView.as_view(), name='upload'),
path('progress', get_progress, name='progress'),
path('reindex', ReindexPageView.as_view(), name='reindex'),
path('refresh', RefreshPageView.as_view(), name='refresh'),
# TODO Implement the following
# 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),
]