From b4a63eca026a31e0f5471d7b37523e3072e2eb1d Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Thu, 18 Jun 2009 06:53:52 +0100 Subject: [PATCH] [svn] Adding logbook export features. Troggle can now produce .txt or .html logbooks through the controlPanel or via an action in the LogbookEntry admin pages. --- expo/admin.py | 11 +++++++++ expo/views_other.py | 38 ++++++++++++++++++++++++++++- export/tocavetab.py | 4 +-- templates/controlPanel.html | 43 +++++++++++++++++++++++++++++++-- templates/logbook2005style.html | 26 ++++++++++++++++++++ templates/logbook2008style.txt | 6 +++++ urls.py | 4 ++- 7 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 templates/logbook2005style.html create mode 100644 templates/logbook2008style.txt diff --git a/expo/admin.py b/expo/admin.py index e4863b1..e88e1cd 100644 --- a/expo/admin.py +++ b/expo/admin.py @@ -6,6 +6,7 @@ import django.forms as forms from expo.forms import LogbookEntryForm from django.http import HttpResponse from django.core import serializers +from expo.views_other import downloadLogbook #from troggle.reversion.admin import VersionAdmin #django-reversion version control #overriding admin save so we have the new since parsing field @@ -50,6 +51,16 @@ class LogbookEntryAdmin(TroggleModelAdmin): date_heirarchy = ('date') inlines = (PersonTripInline, PhotoInline, QMsFoundInline) form = LogbookEntryForm + + actions=('export_logbook_entries_as_html','export_logbook_entries_as_txt') + + def export_logbook_entries_as_html(modeladmin, request, queryset): + response=downloadLogbook(request=request, queryset=queryset, extension='html') + return response + + def export_logbook_entries_as_txt(modeladmin, request, queryset): + response=downloadLogbook(request=request, queryset=queryset, extension='txt') + return response class PersonExpeditionInline(admin.TabularInline): model = PersonExpedition diff --git a/expo/views_other.py b/expo/views_other.py index c6da4b3..f56f8bc 100644 --- a/expo/views_other.py +++ b/expo/views_other.py @@ -1,6 +1,7 @@ from troggle.expo.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, Photo import troggle.settings as settings from django import forms +from django.template import loader, Context from django.db.models import Q import databaseReset import re @@ -80,7 +81,7 @@ def controlPanel(request): else: return HttpResponseRedirect(reverse('auth_login')) - return render_response(request,'controlPanel.html', {'caves':Cave.objects.all(),'jobs_completed':jobs_completed}) + return render_response(request,'controlPanel.html', {'caves':Cave.objects.all(),'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed}) def downloadCavetab(request): from export import tocavetab @@ -96,7 +97,42 @@ def downloadSurveys(request): tosurveys.writeCaveTab(response) return response +def downloadLogbook(request,year=None,extension=None,queryset=None): + + if year: + expedition=Expedition.objects.get(year=year) + logbook_entries=LogbookEntry.objects.filter(expedition=expedition) + filename='logbook'+year + elif queryset: + logbook_entries=queryset + filename='logbook' + else: + return response(r"Error: Logbook downloader doesn't know what year you want") + + if 'year' in request.GET: + year=request.GET['year'] + if 'extension' in request.GET: + extension=request.GET['extension'] + + + + if extension =='txt': + response = HttpResponse(mimetype='text/plain') + style='2008' + elif extension == 'html': + response = HttpResponse(mimetype='text/html') + style='2005' + + template='logbook'+style+'style.'+extension + response['Content-Disposition'] = 'attachment; filename='+filename+'.'+extension + t=loader.get_template(template) + c=Context({'logbook_entries':logbook_entries}) + response.write(t.render(c)) + return response + + def downloadQMs(request): + # Note to self: use get_cave method for the below if request.method=='GET': try: cave=Cave.objects.get(kataster_number=request.GET['cave_id']) diff --git a/export/tocavetab.py b/export/tocavetab.py index ab7a2ee..2ffc5be 100644 --- a/export/tocavetab.py +++ b/export/tocavetab.py @@ -1,9 +1,7 @@ import troggle.expo.models as models from django.conf import settings -import csv -import re -import os +import csv, re, os #format of CAVETAB2.CSV is headers=['KatasterNumber','KatStatusCode','Entrances','UnofficialNumber','MultipleEntrances','AutogenFile','LinkFile','LinkEntrance','Name','UnofficialName', diff --git a/templates/controlPanel.html b/templates/controlPanel.html index 49725e1..efaee62 100644 --- a/templates/controlPanel.html +++ b/templates/controlPanel.html @@ -32,9 +32,9 @@

Import (non-destructive):

+ - @@ -50,8 +50,13 @@ -

Export to csv:

+

Export to legacy formats:

people from folk.csv using parsers\people.py
caves from cavetab2.csv using parsers\cavetab.py
logbook entries using parsers\logbooks.py
people from folk.csv using parsers\people.py
QMs using parsers\QMs.py
survey scans using parsers\surveys.py
survex data using parsers\survex.py
+ + + + + + + + + +
+ Export onto serverExport and Download
caves to cavetab2.csv @@ -70,6 +75,40 @@
+ surveys to Surveys.csv + + + +
+

Download a logbook file which is dynamically generated by Troggle.

+ +

+ Expedition year: + +

+ +

+ Output style: + +

+

+ +

+
+
surveys to Surveys.csv diff --git a/templates/logbook2005style.html b/templates/logbook2005style.html new file mode 100644 index 0000000..39205f1 --- /dev/null +++ b/templates/logbook2005style.html @@ -0,0 +1,26 @@ + +{{logbook_entries.0.expedition}} Expo Logbook + + + + +

Expo {{logbook_entries.0.expedition}}

+ +{%for logbook_entry in logbook_entries%} +
+ +
{{logbook_entry.date}}
+
{{logbook_entry.author.person}} +{% for persontrip in logbook_entry.persontrip_set.all %}{{ persontrip.person_expedition.person }} {{ persontrip.person_expedition.time_underground }}, {% endfor %} +
+ +
{{logbook_entry.place}} - {{logbook_entry.title}}
+ +{{logbook_entry.text|safe}} +{% endfor %} diff --git a/templates/logbook2008style.txt b/templates/logbook2008style.txt new file mode 100644 index 0000000..a7fbea7 --- /dev/null +++ b/templates/logbook2008style.txt @@ -0,0 +1,6 @@ +=Expo {{logbook_entries.0.expedition}} logbook == +{%for logbook_entry in logbook_entries%} +==={{logbook_entry.date}} | {{logbook_entry.place}} - {{logbook_entry.title}} | {% for persontrip in logbook_entry.persontrip_set.all %}{{ persontrip.person_expedition.person }} {{ persontrip.person_expedition.time_underground }}, {% endfor %}=== + +{{logbook_entry.text|safe}} +{% endfor %} \ No newline at end of file diff --git a/urls.py b/urls.py index de77ada..d888e9d 100644 --- a/urls.py +++ b/urls.py @@ -61,7 +61,9 @@ urlpatterns = patterns('', url(r'^controlpanel/?$', views_other.controlPanel, name="controlpanel"), url(r'^CAVETAB2\.CSV/?$', views_other.downloadCavetab, name="downloadcavetab"), - url(r'^Surveys\.csv/?$', views_other.downloadSurveys, name="downloadsurveys"), + url(r'^Surveys\.csv/?$', views_other.downloadSurveys, name="downloadsurveys"), + url(r'^logbook(?P\d\d\d\d)\.(?P.*)/?$',views_other.downloadLogbook), + url(r'^logbook/?$',views_other.downloadLogbook, name="downloadlogbook"), url(r'^cave/(?P[^/]+)/qm\.csv/?$', views_other.downloadQMs, name="downloadqms"), (r'^downloadqms$', views_other.downloadQMs), url(r'^cave/(?P[^/]+)(?P/.*)/?$', subcave, name="subcave"),