[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.

This commit is contained in:
substantialnoninfringinguser 2009-06-18 06:53:52 +01:00
parent 0306723c95
commit b4a63eca02
7 changed files with 125 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import django.forms as forms
from expo.forms import LogbookEntryForm from expo.forms import LogbookEntryForm
from django.http import HttpResponse from django.http import HttpResponse
from django.core import serializers from django.core import serializers
from expo.views_other import downloadLogbook
#from troggle.reversion.admin import VersionAdmin #django-reversion version control #from troggle.reversion.admin import VersionAdmin #django-reversion version control
#overriding admin save so we have the new since parsing field #overriding admin save so we have the new since parsing field
@ -50,6 +51,16 @@ class LogbookEntryAdmin(TroggleModelAdmin):
date_heirarchy = ('date') date_heirarchy = ('date')
inlines = (PersonTripInline, PhotoInline, QMsFoundInline) inlines = (PersonTripInline, PhotoInline, QMsFoundInline)
form = LogbookEntryForm 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): class PersonExpeditionInline(admin.TabularInline):
model = PersonExpedition model = PersonExpedition

View File

@ -1,6 +1,7 @@
from troggle.expo.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, Photo from troggle.expo.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, Photo
import troggle.settings as settings import troggle.settings as settings
from django import forms from django import forms
from django.template import loader, Context
from django.db.models import Q from django.db.models import Q
import databaseReset import databaseReset
import re import re
@ -80,7 +81,7 @@ def controlPanel(request):
else: else:
return HttpResponseRedirect(reverse('auth_login')) 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): def downloadCavetab(request):
from export import tocavetab from export import tocavetab
@ -96,7 +97,42 @@ def downloadSurveys(request):
tosurveys.writeCaveTab(response) tosurveys.writeCaveTab(response)
return 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): def downloadQMs(request):
# Note to self: use get_cave method for the below
if request.method=='GET': if request.method=='GET':
try: try:
cave=Cave.objects.get(kataster_number=request.GET['cave_id']) cave=Cave.objects.get(kataster_number=request.GET['cave_id'])

View File

@ -1,9 +1,7 @@
import troggle.expo.models as models import troggle.expo.models as models
from django.conf import settings from django.conf import settings
import csv import csv, re, os
import re
import os
#format of CAVETAB2.CSV is #format of CAVETAB2.CSV is
headers=['KatasterNumber','KatStatusCode','Entrances','UnofficialNumber','MultipleEntrances','AutogenFile','LinkFile','LinkEntrance','Name','UnofficialName', headers=['KatasterNumber','KatStatusCode','Entrances','UnofficialNumber','MultipleEntrances','AutogenFile','LinkFile','LinkEntrance','Name','UnofficialName',

View File

@ -32,9 +32,9 @@
<h3>Import (non-destructive):</h3> <h3>Import (non-destructive):</h3>
<form name="import" method="post" action=""> <form name="import" method="post" action="">
<table> <table>
<tr><td>people from folk.csv using parsers\people.py</td><td><input type="checkbox" name="import_people"/></td></tr>
<tr><td>caves from cavetab2.csv using parsers\cavetab.py</td><td> <input type="checkbox" class="parser" name="import_cavetab"/></td></tr> <tr><td>caves from cavetab2.csv using parsers\cavetab.py</td><td> <input type="checkbox" class="parser" name="import_cavetab"/></td></tr>
<tr><td>logbook entries using parsers\logbooks.py</td><td><input type="checkbox" name="import_logbooks"/></td></tr> <tr><td>logbook entries using parsers\logbooks.py</td><td><input type="checkbox" name="import_logbooks"/></td></tr>
<tr><td>people from folk.csv using parsers\people.py</td><td><input type="checkbox" name="import_people"/></td></tr>
<tr><td>QMs using parsers\QMs.py</td><td><input type="checkbox" name="import_QMs" /></td></tr> <tr><td>QMs using parsers\QMs.py</td><td><input type="checkbox" name="import_QMs" /></td></tr>
<tr><td>survey scans using parsers\surveys.py</td><td><input type="checkbox" name="import_surveys" /></td></tr> <tr><td>survey scans using parsers\surveys.py</td><td><input type="checkbox" name="import_surveys" /></td></tr>
<tr><td>survex data using parsers\survex.py</td><td><input type="checkbox" name="import_survex" /></td></tr> <tr><td>survex data using parsers\survex.py</td><td><input type="checkbox" name="import_survex" /></td></tr>
@ -50,8 +50,13 @@
</form> </form>
<h3>Export to csv:</h3> <h3>Export to legacy formats:</h3>
<table> <table>
<th>
<td>Export onto server</td>
<td>Export and Download</td>
</th>
<tr> <tr>
<td> <td>
caves to cavetab2.csv caves to cavetab2.csv
@ -70,6 +75,40 @@
</td> </td>
</tr> </tr>
<tr>
<td>
surveys to Surveys.csv
</td>
<td>
</td>
<td>
<form name="export" method="get" action={% url downloadlogbook %}>
<p>Download a logbook file which is dynamically generated by Troggle.</p>
<p>
Expedition year:
<select name="year">
{% for expedition in expeditions %}
<option value="{{expedition}}"> {{expedition}} </option>
{% endfor %}
</select>
</p>
<p>
Output style:
<select name="extension">
<option value="txt">.txt file with MediaWiki markup - 2008 style</option>
<option value="html">.html file - 2005 style</option>
</select>
</p>
<p>
<input name="download_logbook" type="submit" value="Download logbook" />
</p>
</form>
</td>
</tr>
<tr> <tr>
<td> <td>
surveys to Surveys.csv surveys to Surveys.csv

View File

@ -0,0 +1,26 @@
<html>
<head><title>{{logbook_entries.0.expedition}} Expo Logbook</title></head>
<link rel="stylesheet" type="text/css" href="../../css/main2.css" />
<style type="text/css">
.tripdate { float: left;}
.trippeople { float: right;}
.triptitle { font-size: 120%; text-align: center; font-weight: bold; clear: both }
.timeug { text-align: right; font-weight: bold }
p { clear: both }
</style>
<body>
<h1>Expo {{logbook_entries.0.expedition}}</h1>
{%for logbook_entry in logbook_entries%}
<hr />
<div class="tripdate" id="t{{logbook_entry.date}}A">{{logbook_entry.date}}</div>
<div class="trippeople"><u>{{logbook_entry.author.person}}</u>
{% for persontrip in logbook_entry.persontrip_set.all %}{{ persontrip.person_expedition.person }} {{ persontrip.person_expedition.time_underground }}, {% endfor %}
</div>
<div class="triptitle">{{logbook_entry.place}} - {{logbook_entry.title}}</div>
{{logbook_entry.text|safe}}
{% endfor %}

View File

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

View File

@ -61,7 +61,9 @@ urlpatterns = patterns('',
url(r'^controlpanel/?$', views_other.controlPanel, name="controlpanel"), url(r'^controlpanel/?$', views_other.controlPanel, name="controlpanel"),
url(r'^CAVETAB2\.CSV/?$', views_other.downloadCavetab, name="downloadcavetab"), 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<year>\d\d\d\d)\.(?P<extension>.*)/?$',views_other.downloadLogbook),
url(r'^logbook/?$',views_other.downloadLogbook, name="downloadlogbook"),
url(r'^cave/(?P<cave_id>[^/]+)/qm\.csv/?$', views_other.downloadQMs, name="downloadqms"), url(r'^cave/(?P<cave_id>[^/]+)/qm\.csv/?$', views_other.downloadQMs, name="downloadqms"),
(r'^downloadqms$', views_other.downloadQMs), (r'^downloadqms$', views_other.downloadQMs),
url(r'^cave/(?P<cave_id>[^/]+)(?P<subcave>/.*)/?$', subcave, name="subcave"), url(r'^cave/(?P<cave_id>[^/]+)(?P<subcave>/.*)/?$', subcave, name="subcave"),