2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-12-12 03:22:18 +00:00
troggle/export/toqms.py

39 lines
1.4 KiB
Python
Raw Normal View History

2011-07-11 02:10:22 +01:00
import csv
import os
2023-01-19 20:47:26 +00:00
import re
from django.conf import settings
import troggle.core.models as models
2011-07-11 02:10:22 +01:00
2022-07-08 20:19:56 +01:00
'''Unused and untested in 2022. Not part fo the re-engineering to make troggle work with QMs.
'''
2011-07-11 02:10:22 +01:00
#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,
2011-07-11 02:10:22 +01:00
'Comment':qm.comment
}
qmRow=['' for x in range(len(headers))]
2020-05-24 01:57:06 +01:00
for column, modelField in list(columnsToModelFields.items()):
2011-07-11 02:10:22 +01:00
if modelField:
# Very sorry about the atrocious replace below. I will fix this soon if noone beats me to it. - AC
2020-05-24 01:57:06 +01:00
qmRow[headers.index(column)]=modelField.replace('\xd7','x').replace('\u201c','').replace('\u2013','').replace('\xbd','')
2011-07-11 02:10:22 +01:00
return qmRow
def writeQmTable(outfile,cave):
cavewriter=csv.writer(outfile,lineterminator='\r')
cavewriter.writerow(headers)
for qm in cave.get_QMs():
cavewriter.writerow(qmRow(qm))