mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +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):
|
||||
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
|
||||
|
||||
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='', ):
|
||||
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.defaultfilters import slugify
|
||||
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_caves import Cave, LogbookEntry
|
||||
@ -18,7 +18,10 @@ import troggle.settings as settings
|
||||
|
||||
|
||||
def pathsreport(request):
|
||||
pathsdict={}
|
||||
try:
|
||||
pathsdict={
|
||||
# "BOGUS" : settings.BOGUS,
|
||||
"CAVEDESCRIPTIONS" : settings.CAVEDESCRIPTIONS,
|
||||
"DIR_ROOT" : settings.DIR_ROOT,
|
||||
"ENTRANCEDESCRIPTIONS" : settings.ENTRANCEDESCRIPTIONS,
|
||||
@ -46,6 +49,9 @@ def pathsreport(request):
|
||||
"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
|
||||
ncodes = len(pathsdict)
|
||||
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'^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'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
|
||||
# url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"), # Needed !
|
||||
|
Loading…
Reference in New Issue
Block a user