[svn r8273] Make qm table export script work

This commit is contained in:
aaron 2009-03-14 05:16:00 +01:00
parent 5ad01940f7
commit a2057e63f5
2 changed files with 45 additions and 1 deletions

View File

@ -28,6 +28,11 @@ class PersonAdmin(admin.ModelAdmin):
search_fields = ('first_name','last_name') search_fields = ('first_name','last_name')
inlines = (PersonExpeditionInline,) inlines = (PersonExpeditionInline,)
class QMAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
obj.new_since_parsing=True
obj.save()
class PersonExpeditionAdmin(admin.ModelAdmin): class PersonExpeditionAdmin(admin.ModelAdmin):
search_fields = ('person__first_name','expedition__year') search_fields = ('person__first_name','expedition__year')
@ -35,6 +40,8 @@ class CaveAdmin(admin.ModelAdmin):
search_fields = ('official_name','kataster_number','unofficial_number') search_fields = ('official_name','kataster_number','unofficial_number')
extra = 4 extra = 4
admin.site.register(Photo) admin.site.register(Photo)
admin.site.register(Cave, CaveAdmin) admin.site.register(Cave, CaveAdmin)
admin.site.register(Area) admin.site.register(Area)

View File

@ -0,0 +1,37 @@
import troggle.expo.models as models
from django.conf import settings
import csv
import re
import os
#format of QM tables
headers=['Number','Grade','Area','Description','Page reference','Nearest station','Completion description','Comment']
def qmRow(qm):
#mapping of troggle models to table columns is: (guess this could just be a tuple of tuples rather than a dictionary actually)
columnsToModelFields={
'Number':str(qm.number),
'Grade':qm.grade,
'Area':qm.area,
'Description':qm.location_description,
#'Page reference': #not implemented
'Nearest station':qm.nearest_station_description,
'Completion description':qm.completion_description,
'Comment':qm.comment
}
qmRow=['' for x in range(len(headers))]
for column, modelField in columnsToModelFields.items():
if modelField:
# Very sorry about the atrocious replace below. I will fix this soon if noone beats me to it. - AC
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')
cavewriter=csv.writer(outfile,lineterminator='\r')
cavewriter.writerow(headers)
for qm in cave.get_QMs():
cavewriter.writerow(qmRow(qm))