From e9e755b5175b47a4dbb69ac114428660bb2e12a8 Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Thu, 14 May 2009 06:19:46 +0100 Subject: [PATCH] [svn] Fixed broken buttons on controlpanel, added CAVETAB2.CSV export and download buttons and made them work too. Changed ordering on PersonExpeditions so that it is based on their expedition. That way, even if we don't have date info on when a user was on expo exactly, pages like personindex work correctly. --- databaseReset.py | 18 +++++++++++++++++- expo/models.py | 3 ++- expo/views_other.py | 24 +++++++++++++++++------- export/tocavetab.py | 3 +-- export/toqms.py | 3 +-- parsers/cavetab.py | 2 -- urls.py | 2 +- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/databaseReset.py b/databaseReset.py index f2c3b51..5503104 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -6,6 +6,7 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.core import management from django.db import connection from django.contrib.auth.models import User +from django.http import HttpResponse def reload_db(): cursor = connection.cursor() @@ -55,4 +56,19 @@ def reset(): import_logbooks() import_survex() import_QMs() - import_surveys() \ No newline at end of file + import_surveys() + +def export_cavetab(): + from export import tocavetab + outfile=file(os.path.join(settings.EXPOWEB, "noinfo", "CAVETAB2.CSV"),'w') + tocavetab.writeCaveTab(outfile) + outfile.close() + +def export_qms(): #finish this. need cave chooser + from export import toqms + outfile=file(os.path.join(settings.EXPOWEB, "noinfo", "CAVETAB2.CSV"),'w') + outfile.close() + + + + \ No newline at end of file diff --git a/expo/models.py b/expo/models.py index 3472a01..4c8332b 100644 --- a/expo/models.py +++ b/expo/models.py @@ -162,7 +162,8 @@ class PersonExpedition(TroggleModel): class Meta: ordering = ('expedition',) - get_latest_by = 'date_from' + #order_with_respect_to = 'expedition' + get_latest_by = 'expedition' def GetPersonChronology(self): res = { } diff --git a/expo/views_other.py b/expo/views_other.py index 0f8cb79..1b3b64f 100644 --- a/expo/views_other.py +++ b/expo/views_other.py @@ -5,8 +5,7 @@ from django.db.models import Q import databaseReset import re import randSent -from django.http import HttpResponse - +from django.http import HttpResponse, HttpResponseRedirect from django.core.urlresolvers import reverse from troggle.alwaysUseRequestContext import render_response # see views_logbooks for explanation on this. @@ -62,9 +61,20 @@ def calendar(request,year): def controlPanel(request): message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"}) if request.method=='POST': - for item in request.POST: - if request.user.is_superuser and item!='item': - print "running"+ " databaseReset."+item+"()" - exec "databaseReset."+item+"()" + 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')) - return render_response(request,'controlPanel.html', ) \ No newline at end of file + return render_response(request,'controlPanel.html', ) + +def downloadCavetab(request): + from export import tocavetab + response = HttpResponse(mimetype='text/csv') + response['Content-Disposition'] = 'attachment; filename=CAVEETAB2.CSV' + tocavetab.writeCaveTab(response) + return response + \ No newline at end of file diff --git a/export/tocavetab.py b/export/tocavetab.py index 121c36e..ab7a2ee 100644 --- a/export/tocavetab.py +++ b/export/tocavetab.py @@ -42,8 +42,7 @@ def cavetabRow(cave): caveRow[headers.index(column)]=modelField.replace(u'\xd7','x').replace(u'\u201c','').replace(u'\u2013','').replace(u'\xbd','') return caveRow -def writeCaveTab(path): - outfile=file(path,'w') +def writeCaveTab(outfile): cavewriter=csv.writer(outfile,lineterminator='\r') cavewriter.writerow(headers) for cave in models.Cave.objects.all(): diff --git a/export/toqms.py b/export/toqms.py index 0597da6..dd58fca 100644 --- a/export/toqms.py +++ b/export/toqms.py @@ -28,8 +28,7 @@ def qmRow(qm): qmRow[headers.index(column)]=modelField.replace(u'\xd7','x').replace(u'\u201c','').replace(u'\u2013','').replace(u'\xbd','') return qmRow -def writeQmTable(path,cave): - outfile=file(path,'w') +def writeQmTable(outfile,cave): cavewriter=csv.writer(outfile,lineterminator='\r') cavewriter.writerow(headers) for qm in cave.get_QMs(): diff --git a/parsers/cavetab.py b/parsers/cavetab.py index fde5333..2dc071c 100644 --- a/parsers/cavetab.py +++ b/parsers/cavetab.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -import sys -sys.path.append("/home/mjg/expoweb/troggle") import troggle.expo.models as models from django.conf import settings import csv diff --git a/urls.py b/urls.py index ee4dc62..f5decdb 100644 --- a/urls.py +++ b/urls.py @@ -58,6 +58,7 @@ urlpatterns = patterns('', url(r'^survey/(?P\d\d\d\d)\#(?P\d*)$', survey, name="survey"), url(r'^controlpanel/?$', views_other.controlPanel, name="controlpanel"), + url(r'^cavetab/?$', views_other.downloadCavetab, name="downloadcavetab"), (r'^admin/doc/?', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), @@ -68,7 +69,6 @@ urlpatterns = patterns('', # (r'^personform/(.*)$', personForm), - (r'^photologue/', include('photologue.urls')), (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),