diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2020-07-26 20:48:25 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2020-07-26 20:48:25 +0100 |
commit | 0cf3b869af528b3b68a861b94ddb0aefc3819ecf (patch) | |
tree | 24d8cb0e85675319abebe13d1a4dcc6160d2e799 /core/views_logbooks.py | |
parent | 69b843a824a8367b2a5f99447185482ffb920661 (diff) | |
download | troggle-0cf3b869af528b3b68a861b94ddb0aefc3819ecf.tar.gz troggle-0cf3b869af528b3b68a861b94ddb0aefc3819ecf.tar.bz2 troggle-0cf3b869af528b3b68a861b94ddb0aefc3819ecf.zip |
First implementation of html API, both TSV and JSON
Diffstat (limited to 'core/views_logbooks.py')
-rw-r--r-- | core/views_logbooks.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/core/views_logbooks.py b/core/views_logbooks.py index 92be4cc..c3cea1e 100644 --- a/core/views_logbooks.py +++ b/core/views_logbooks.py @@ -41,7 +41,7 @@ def getNotablePersons(): for person in Person.objects.all(): if person.bisnotable(): notablepersons.append(person) - return notablepersons + return notablepersons def personindex(request): @@ -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 - def get_context_data(self, **kwargs): - context = super(ExpeditionListView, self).get_context_data(**kwargs) - context['now'] = timezone.now() - return context + +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 person(request, first_name='', last_name='', ): this_person = Person.objects.get(first_name = first_name, last_name = last_name) |