summaryrefslogtreecommitdiffstats
path: root/export/toqms.py
blob: f939c5ba583ab835e5ad8dba6e5555e5cab32b63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import csv
import os
import re

from django.conf import settings

import troggle.core.models as models

'''Unused and untested in 2022. Not part fo the re-engineering to make troggle work with QMs.
'''
#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 list(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('\xd7','x').replace('\u201c','').replace('\u2013','').replace('\xbd','')
    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))