From a4edfca30e254aa5135a059870ebd60219874087 Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:59:40 +0100 Subject: [PATCH] [svn] Got QM pages working. Started scripts for exporting to old expo format. Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8269 by aaron @ 3/12/2009 2:22 PM --- expo/views_caves.py | 18 +++++++--- export/__init__.py | 0 export/tocavetab.py | 79 ++++++++++++++++++++++++++++++++++++++++++++ export/tologbooks.py | 0 export/toqms.py | 0 parsers/QMs.py | 8 +++-- templates/cave.html | 23 ++++++++++++- templates/qm.html | 40 ++++++++++++++++++++++ urls.py | 5 +-- 9 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 export/__init__.py create mode 100644 export/tocavetab.py create mode 100644 export/tologbooks.py create mode 100644 export/toqms.py create mode 100644 templates/qm.html diff --git a/expo/views_caves.py b/expo/views_caves.py index 487bbc9..169dbec 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -5,6 +5,14 @@ from troggle.expo.forms import CaveForm import search from troggle.alwaysUseRequestContext import render_response # see views_logbooks for explanation on this. +def getCave(cave_id): + """Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm.""" + try: + cave = Cave.objects.get(kataster_number=cave_id) + except Cave.DoesNotExist: + cave = Cave.objects.get(unofficial_number=cave_id) + return cave + def caveindex(request): caves = Cave.objects.all() notablecavehrefs = [ "161", "204", "258", "76" ] # could detect notability by trips and notability of people who have been down them @@ -12,12 +20,12 @@ def caveindex(request): return render_response(request,'caveindex.html', {'caves': caves, 'notablecaves':notablecaves}) def cavehref(request, cave_id='', offical_name=''): - try: - cave = Cave.objects.get(kataster_number=cave_id) - except Cave.DoesNotExist: - cave = Cave.objects.get(unofficial_number=cave_id) - return render_response(request,'cave.html', {'cave': cave,}) + return render_response(request,'cave.html', {'cave': getCave(cave_id),}) +def qm(request,cave_id,qm_id,year): + year=int(year) + qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) + return render_response(request,'qm.html',{'qm':qm,}) def ent(request, cave_id, ent_letter): cave = Cave.objects.filter(kataster_number = cave_id)[0] diff --git a/export/__init__.py b/export/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/export/tocavetab.py b/export/tocavetab.py new file mode 100644 index 0000000..5be866c --- /dev/null +++ b/export/tocavetab.py @@ -0,0 +1,79 @@ +import troggle.expo.models as models +from django.conf import settings + +import csv +import re +import os + +##format of CAVETAB2.CSV is +KatasterNumber = 0 +KatStatusCode = 1 +Entrances = 2 +UnofficialNumber = 3 +MultipleEntrances = 4 +AutogenFile = 5 +LinkFile = 6 +LinkEntrance = 7 +Name = 8 +UnofficialName = 9 +Comment = 10 +Area = 11 +Explorers = 12 +UndergroundDescription = 13 +Equipment = 14 +QMList = 15 +KatasterStatus = 16 +References = 17 +UndergroundCentreLine = 18 +UndergroundDrawnSurvey = 19 +SurvexFile = 20 +Length = 21 +Depth = 22 +Extent = 23 +Notes = 24 +EntranceName = 25 +TagPoint = 26 +OtherPoint = 27 +DescriptionOfOtherPoint = 28 +ExactEntrance = 29 +TypeOfFix = 30 +GPSpreSA = 31 +GPSpostSA = 32 +Northing = 33 +Easting = 34 +Altitude = 35 +Bearings = 36 +Map = 37 +Location = 38 +Approach = 39 +EntranceDescription = 40 +PhotoOfLocation = 41 +Marking = 42 +MarkingComment = 43 +Findability = 44 +FindabilityComment = 45 + +##format of CAVETAB2.CSV is +headers=['KatasterNumber','KatStatusCode','Entrances','UnofficialNumber','MultipleEntrances','AutogenFile','LinkFile','LinkEntrance','Name','UnofficialName', + 'Comment','Area','Explorers','UndergroundDescription','Equipment','QMList','KatasterStatus','References','UndergroundCentreLine','UndergroundDrawnSurvey', + 'SurvexFile','Length','Depth','Extent','Notes','EntranceName','TagPoint','OtherPoint','DescriptionOfOtherPoint','ExactEntrance','TypeOfFix','GPSpreSA', + 'GPSpostSA','Northing','Easting','Altitude','Bearings','Map','Location','Approach','EntranceDescription','PhotoOfLocation','Marking','MarkingComment', + 'Findability','FindabilityComment'] +headersDict={} +x=0 +for column in headers: + headersDict[x]=column + x+=1 +print headersDict + +def writeCaveTab(path): + outfile=file(path,'w') + cavewriter=csv.writer(outfile) + cavewriter.writerows + for cave in Cave.objects.all(): + caverow[KatasterNumber]=cave.kataster_number + caverow[KatStatusCode]=cave.katasternumber + +def addCell(caverow, attribute): + caverow[attribute]=cave.attribute + diff --git a/export/tologbooks.py b/export/tologbooks.py new file mode 100644 index 0000000..e69de29 diff --git a/export/toqms.py b/export/toqms.py new file mode 100644 index 0000000..e69de29 diff --git a/parsers/QMs.py b/parsers/QMs.py index 7858c0c..bad95a7 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -48,8 +48,12 @@ def parseCaveQMs(cave,pathToCSV): newQM.grade=line[1] newQM.area=line[2] newQM.location_description=line[3] - newQM.nearest_station_description=line[4] - newQM.completion_description=line[5] + + newQM.completion_description=line[4] + newQM.nearest_station_description=line[5] + if newQM.completion_description: # Troggle checks if QMs are completed by checking if they have a ticked_off_by trip. In the table, completion is indicated by the presence of a completion discription. + newQM.ticked_off_by=placeholder + newQM.comment=line[6] newQM.save() print "QM "+str(newQM) + ' added to database\r', diff --git a/templates/cave.html b/templates/cave.html index d76a211..9b7c482 100644 --- a/templates/cave.html +++ b/templates/cave.html @@ -4,7 +4,7 @@ {% block content %}
-

All trips done in this cave

+

All logbook entries regarding this cave ({{cave.logbookentry_set.count}})

{% for logbookentry in cave.logbookentry_set.all %} {% if logbookentry.title %} @@ -64,4 +64,25 @@

Notes

{{ cave.notes|wiki_to_html }} {% endif %} + +{% if cave.get_QMs %} +

Question marks

+

Extant

+ +

Ticked off

+ +{% endif %} {% endblock %} diff --git a/templates/qm.html b/templates/qm.html new file mode 100644 index 0000000..db3edc4 --- /dev/null +++ b/templates/qm.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} +{% load wiki_markup %} + +{% block title %} QM: {{qm|wiki_to_html_short}} {% endblock %} + +{% block editLink %}| Edit QM {{qm|wiki_to_html_short}}{% endblock %} + + + +{% block contentheader %} +
+ + + + + +
Previous{{qm|wiki_to_html_short}}Next
+{% endblock %} + +{% block content %} +

Location

+{{qm.location_description}} + + +

Creation

+Found by {{qm.found_by}} on {{qm.found_by.date}}. + +

Completion

+{% if ticked_off_by %} +{{qm.completion_description}} +Ticked off by: {{qm.ticked_off_by}}
+Description: {{qm.completion_description}} +{% else %} +None yet- STILL EXTANT. +{% endif %} + +

Comment

+{{qm.comment}} + +{% endblock %} diff --git a/urls.py b/urls.py index cb95636..4ab0f0a 100644 --- a/urls.py +++ b/urls.py @@ -27,7 +27,7 @@ urlpatterns = patterns('', url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"), url(r'^cavehref/(.+)$', views_caves.cavehref, name="cave"), - + url(r'^jgtfile/(.*)$', view_surveys.jgtfile, name="jgtfile"), url(r'^jgtuploadfile$', view_surveys.jgtuploadfile, name="jgtuploadfile"), @@ -41,7 +41,8 @@ urlpatterns = patterns('', url(r'^cavearea', caveArea, name="caveArea"), url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"), - url(r'^cave/(?P[^/]+)/?$', views_caves.cavehref), # deprecated + url(r'^cave/(?P[^/]+)/?$', views_caves.cavehref), + url(r'^cave/(?P[^/]+)/(?P\d\d\d\d)-(?P\d\d)?$', views_caves.qm), (r'^survex/(?P.*)\.svx$', svx), (r'^survex/(?P.*)\.3d$', threed), (r'^survex/(?P.*)\.log$', log),