mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 16:51:54 +00:00
First implementation of html API, both TSV and JSON
This commit is contained in:
parent
69b843a824
commit
0cf3b869af
@ -84,13 +84,28 @@ def expedition(request, expeditionname):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return ('expedition', (expedition.year))
|
return ('expedition', (expedition.year))
|
||||||
|
|
||||||
class ExpeditionListView(ListView):
|
class ExpeditionListView(ListView): # django thus expects a template called "expedition_list.html"
|
||||||
|
# from the name of the object not the name of the class.
|
||||||
|
model = Expedition
|
||||||
|
|
||||||
|
|
||||||
|
class Expeditions_tsvListView(ListView):
|
||||||
|
"""This uses the Django built-in shortcut mechanism
|
||||||
|
It defaults to use a template with name <app-label>/<model-name>_list.html.
|
||||||
|
https://www.agiliq.com/blog/2017/12/when-and-how-use-django-listview/
|
||||||
|
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Generic_views
|
||||||
|
Either a queryset variable or set_queryset() function is used, but not needed
|
||||||
|
if you want all the obejcts of a particaulr type in which case just set model = <object>
|
||||||
|
"""
|
||||||
|
template_name = 'core/expeditions_tsv_list.html' # if not present then uses core/expedition_list.html
|
||||||
|
#queryset = Expedition.objects.all()
|
||||||
|
#context_object_name = 'expedition'
|
||||||
|
model = Expedition # equivalent to .objects.all() for a queryset
|
||||||
|
|
||||||
|
class Expeditions_jsonListView(ListView):
|
||||||
|
template_name = 'core/expeditions_json_list.html'
|
||||||
model = Expedition
|
model = Expedition
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super(ExpeditionListView, self).get_context_data(**kwargs)
|
|
||||||
context['now'] = timezone.now()
|
|
||||||
return context
|
|
||||||
|
|
||||||
def person(request, first_name='', last_name='', ):
|
def person(request, first_name='', last_name='', ):
|
||||||
this_person = Person.objects.get(first_name = first_name, last_name = last_name)
|
this_person = Person.objects.get(first_name = first_name, last_name = last_name)
|
||||||
|
@ -8,7 +8,7 @@ from django.shortcuts import render, render_to_response
|
|||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.views.generic.list import ListView
|
#from django.views.generic.list import ListView
|
||||||
|
|
||||||
from troggle.core.models import Expedition, Person, PersonExpedition
|
from troggle.core.models import Expedition, Person, PersonExpedition
|
||||||
from troggle.core.models_caves import Cave, LogbookEntry
|
from troggle.core.models_caves import Cave, LogbookEntry
|
||||||
@ -18,34 +18,40 @@ import troggle.settings as settings
|
|||||||
|
|
||||||
|
|
||||||
def pathsreport(request):
|
def pathsreport(request):
|
||||||
pathsdict={
|
pathsdict={}
|
||||||
"CAVEDESCRIPTIONS" : settings.CAVEDESCRIPTIONS,
|
try:
|
||||||
"DIR_ROOT" : settings.DIR_ROOT,
|
pathsdict={
|
||||||
"ENTRANCEDESCRIPTIONS" : settings.ENTRANCEDESCRIPTIONS,
|
# "BOGUS" : settings.BOGUS,
|
||||||
"EXPOUSER_EMAIL" : settings.EXPOUSER_EMAIL,
|
"CAVEDESCRIPTIONS" : settings.CAVEDESCRIPTIONS,
|
||||||
"EXPOUSERPASS" :"<redacted>",
|
"DIR_ROOT" : settings.DIR_ROOT,
|
||||||
"EXPOUSER" : settings.EXPOUSER,
|
"ENTRANCEDESCRIPTIONS" : settings.ENTRANCEDESCRIPTIONS,
|
||||||
"EXPOWEB" : settings.EXPOWEB,
|
"EXPOUSER_EMAIL" : settings.EXPOUSER_EMAIL,
|
||||||
"EXPOWEB_URL" : settings.EXPOWEB_URL,
|
"EXPOUSERPASS" :"<redacted>",
|
||||||
"FILES" : settings.FILES,
|
"EXPOUSER" : settings.EXPOUSER,
|
||||||
"JSLIB_URL" : settings.JSLIB_URL,
|
"EXPOWEB" : settings.EXPOWEB,
|
||||||
"LOGFILE" : settings.LOGFILE,
|
"EXPOWEB_URL" : settings.EXPOWEB_URL,
|
||||||
"LOGIN_REDIRECT_URL" : settings.LOGIN_REDIRECT_URL,
|
"FILES" : settings.FILES,
|
||||||
"MEDIA_ROOT" : settings.MEDIA_ROOT,
|
"JSLIB_URL" : settings.JSLIB_URL,
|
||||||
"MEDIA_URL" : settings.MEDIA_URL,
|
"LOGFILE" : settings.LOGFILE,
|
||||||
"PHOTOS_URL" : settings.PHOTOS_URL,
|
"LOGIN_REDIRECT_URL" : settings.LOGIN_REDIRECT_URL,
|
||||||
"PYTHON_PATH" : settings.PYTHON_PATH,
|
"MEDIA_ROOT" : settings.MEDIA_ROOT,
|
||||||
"REPOS_ROOT_PATH" : settings.REPOS_ROOT_PATH,
|
"MEDIA_URL" : settings.MEDIA_URL,
|
||||||
"ROOT_URLCONF" : settings.ROOT_URLCONF,
|
"PHOTOS_URL" : settings.PHOTOS_URL,
|
||||||
"STATIC_URL" : settings.STATIC_URL,
|
"PYTHON_PATH" : settings.PYTHON_PATH,
|
||||||
"SURVEX_DATA" : settings.SURVEX_DATA,
|
"REPOS_ROOT_PATH" : settings.REPOS_ROOT_PATH,
|
||||||
"SURVEY_SCANS" : settings.SURVEY_SCANS,
|
"ROOT_URLCONF" : settings.ROOT_URLCONF,
|
||||||
"SURVEYS" : settings.SURVEYS,
|
"STATIC_URL" : settings.STATIC_URL,
|
||||||
"SURVEYS_URL" : settings.SURVEYS_URL,
|
"SURVEX_DATA" : settings.SURVEX_DATA,
|
||||||
"THREEDCACHEDIR" : settings.THREEDCACHEDIR,
|
"SURVEY_SCANS" : settings.SURVEY_SCANS,
|
||||||
"TUNNEL_DATA" : settings.TUNNEL_DATA,
|
"SURVEYS" : settings.SURVEYS,
|
||||||
"URL_ROOT" : settings.URL_ROOT
|
"SURVEYS_URL" : settings.SURVEYS_URL,
|
||||||
}
|
"THREEDCACHEDIR" : settings.THREEDCACHEDIR,
|
||||||
|
"TUNNEL_DATA" : settings.TUNNEL_DATA,
|
||||||
|
"URL_ROOT" : settings.URL_ROOT
|
||||||
|
}
|
||||||
|
except:
|
||||||
|
pathsdict["! EXCEPTION !"] = "missing string constant in troggle/settings"
|
||||||
|
|
||||||
# settings are unique by paths are not
|
# settings are unique by paths are not
|
||||||
ncodes = len(pathsdict)
|
ncodes = len(pathsdict)
|
||||||
bycodeslist = sorted(pathsdict.items())
|
bycodeslist = sorted(pathsdict.items())
|
||||||
|
1
templates/baseapi.html
Normal file
1
templates/baseapi.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
{% block content %}{% endblock %}
|
4
templates/core/expeditions_json_list.html
Normal file
4
templates/core/expeditions_json_list.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{% extends "baseapi.html" %}
|
||||||
|
{% block content %}{
|
||||||
|
{% for expedition in object_list %}"{{expedition.year}}": ["{{expedition.name}}","{{expedition.get_absolute_url}}"]
|
||||||
|
{% endfor %} }{% endblock %}
|
3
templates/core/expeditions_tsv_list.html
Normal file
3
templates/core/expeditions_tsv_list.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{% extends "baseapi.html" %}
|
||||||
|
{% block content %}{% for expedition in object_list %}{{expedition.year}} "{{expedition.name}}" "{{expedition.get_absolute_url}}"
|
||||||
|
{% endfor %}{% endblock %}
|
2
urls.py
2
urls.py
@ -45,6 +45,8 @@ actualurlpatterns = [
|
|||||||
|
|
||||||
url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"),
|
url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"),
|
||||||
url(r'^expeditions/?$', views_logbooks.ExpeditionListView.as_view(), name="expeditions"),
|
url(r'^expeditions/?$', views_logbooks.ExpeditionListView.as_view(), name="expeditions"),
|
||||||
|
url(r'^api/expeditions_tsv$', views_logbooks.Expeditions_tsvListView.as_view()),
|
||||||
|
url(r'^api/expeditions_json$', views_logbooks.Expeditions_jsonListView.as_view()),
|
||||||
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
|
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
|
||||||
url(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
|
url(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
|
||||||
# url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"), # Needed !
|
# url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"), # Needed !
|
||||||
|
Loading…
Reference in New Issue
Block a user