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 @@