2009-05-13 06:15:48 +01:00
|
|
|
from troggle.expo.models import Cave, Expedition, Person, LogbookEntry, PersonExpedition, PersonTrip, Photo
|
2009-05-13 05:22:14 +01:00
|
|
|
import troggle.settings as settings
|
|
|
|
from django import forms
|
|
|
|
from django.db.models import Q
|
2009-05-13 06:15:48 +01:00
|
|
|
import databaseReset
|
2009-05-13 05:25:17 +01:00
|
|
|
import re
|
2009-05-13 05:31:44 +01:00
|
|
|
import randSent
|
2009-05-14 06:19:46 +01:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
2009-05-13 05:35:59 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
2009-05-13 05:52:15 +01:00
|
|
|
from troggle.alwaysUseRequestContext import render_response # see views_logbooks for explanation on this.
|
2009-05-17 04:31:23 +01:00
|
|
|
from expo.models import *
|
2009-05-13 05:35:59 +01:00
|
|
|
|
2009-05-13 06:08:04 +01:00
|
|
|
def showrequest(request):
|
|
|
|
return HttpResponse(request.GET)
|
|
|
|
|
2009-05-13 05:22:14 +01:00
|
|
|
def stats(request):
|
|
|
|
statsDict={}
|
|
|
|
statsDict['expoCount'] = int(Expedition.objects.count())
|
|
|
|
statsDict['caveCount'] = int(Cave.objects.count())
|
|
|
|
statsDict['personCount'] = int(Person.objects.count())
|
|
|
|
statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count())
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'statistics.html', statsDict)
|
2009-05-13 05:25:17 +01:00
|
|
|
|
2009-05-13 05:48:47 +01:00
|
|
|
def frontpage(request):
|
2009-05-13 05:35:59 +01:00
|
|
|
message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"})
|
2009-05-13 05:39:52 +01:00
|
|
|
if "reloadexpos" in request.GET:
|
2009-05-13 05:35:59 +01:00
|
|
|
message = LoadPersonsExpos()
|
|
|
|
message = "Reloaded personexpos"
|
2009-05-13 06:15:48 +01:00
|
|
|
if "reloadsurvex" in request.POST:
|
2009-05-13 05:39:52 +01:00
|
|
|
message = LoadAllSurvexBlocks()
|
|
|
|
message = "Reloaded survexblocks"
|
|
|
|
|
2009-05-13 06:19:45 +01:00
|
|
|
#'randSent':randSent.randomLogbookSentence(),
|
|
|
|
expeditions = Expedition.objects.order_by("-year")
|
|
|
|
logbookentry = LogbookEntry
|
|
|
|
cave = Cave
|
|
|
|
photo = Photo
|
|
|
|
return render_response(request,'frontpage.html', locals())
|
|
|
|
|
|
|
|
def todo(request):
|
|
|
|
message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"})
|
|
|
|
if "reloadexpos" in request.GET:
|
|
|
|
message = LoadPersonsExpos()
|
|
|
|
message = "Reloaded personexpos"
|
|
|
|
if "reloadsurvex" in request.POST:
|
|
|
|
message = LoadAllSurvexBlocks()
|
|
|
|
message = "Reloaded survexblocks"
|
|
|
|
|
2009-05-13 05:35:59 +01:00
|
|
|
#'randSent':randSent.randomLogbookSentence(),
|
2009-05-13 05:44:35 +01:00
|
|
|
expeditions = Expedition.objects.order_by("-year")
|
2009-05-13 06:06:11 +01:00
|
|
|
totallogbookentries = LogbookEntry.objects.count()
|
|
|
|
return render_response(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message})
|
2009-05-13 06:19:45 +01:00
|
|
|
|
2009-05-13 05:35:11 +01:00
|
|
|
def calendar(request,year):
|
|
|
|
week=['S','S','M','T','W','T','F']
|
|
|
|
if year:
|
2009-05-13 06:15:48 +01:00
|
|
|
expedition=Expedition.objects.get(year=year)
|
|
|
|
PersonExpeditions=expedition.personexpedition_set.all()
|
|
|
|
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'calendar.html', locals())
|
2009-05-13 06:15:48 +01:00
|
|
|
|
|
|
|
def controlPanel(request):
|
|
|
|
message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"})
|
|
|
|
if request.method=='POST':
|
2009-05-14 06:19:46 +01:00
|
|
|
if request.user.is_superuser:
|
|
|
|
for item in request.POST:
|
|
|
|
if item!='item':
|
|
|
|
print "running"+ " databaseReset."+item+"()"
|
|
|
|
exec "databaseReset."+item+"()"
|
|
|
|
else:
|
|
|
|
return HttpResponseRedirect(reverse('auth_login'))
|
|
|
|
|
2009-05-17 04:31:23 +01:00
|
|
|
return render_response(request,'controlPanel.html', {'caves':Cave.objects.all()} )
|
2009-05-13 06:15:48 +01:00
|
|
|
|
2009-05-14 06:19:46 +01:00
|
|
|
def downloadCavetab(request):
|
|
|
|
from export import tocavetab
|
|
|
|
response = HttpResponse(mimetype='text/csv')
|
2009-05-17 04:31:23 +01:00
|
|
|
response['Content-Disposition'] = 'attachment; filename=CAVETAB2.CSV'
|
2009-05-14 06:19:46 +01:00
|
|
|
tocavetab.writeCaveTab(response)
|
|
|
|
return response
|
2009-05-17 04:31:23 +01:00
|
|
|
|
|
|
|
def downloadSurveys(request):
|
|
|
|
from export import tosurveys
|
|
|
|
response = HttpResponse(mimetype='text/csv')
|
|
|
|
response['Content-Disposition'] = 'attachment; filename=Surveys.csv'
|
|
|
|
tosurveys.writeCaveTab(response)
|
|
|
|
return response
|
|
|
|
|
|
|
|
def downloadQMs(request):
|
|
|
|
if request.method=='GET':
|
|
|
|
try:
|
|
|
|
cave=Cave.objects.get(kataster_number=request.GET['cave_id'])
|
|
|
|
except Cave.DoesNotExist:
|
|
|
|
cave=Cave.objects.get(name=cave_id)
|
|
|
|
|
|
|
|
from export import toqms
|
|
|
|
|
|
|
|
response = HttpResponse(mimetype='text/csv')
|
|
|
|
response['Content-Disposition'] = 'attachment; filename=qm.csv'
|
|
|
|
toqms.writeQmTable(response,cave)
|
|
|
|
return response
|