forked from expo/troggle
edit logbooks, new logbook format, increased database normalisation
This commit is contained in:
@@ -11,11 +11,17 @@ from django.http import HttpResponse
|
||||
|
||||
|
||||
def reload_db():
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("drop database %s" % settings.DATABASE_NAME)
|
||||
cursor.execute("create database %s" % settings.DATABASE_NAME)
|
||||
cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % settings.DATABASE_NAME)
|
||||
cursor.execute("USE %s" % settings.DATABASE_NAME)
|
||||
if settings.DATABASE_ENGINE == 'sqlite3':
|
||||
try:
|
||||
os.remove(settings.DATABASE_NAME)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("DROP DATABASE %s" % settings.DATABASE_NAME)
|
||||
cursor.execute("CREATE DATABASE %s" % settings.DATABASE_NAME)
|
||||
cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % settings.DATABASE_NAME)
|
||||
cursor.execute("USE %s" % settings.DATABASE_NAME)
|
||||
management.call_command('syncdb', interactive=False)
|
||||
user = User.objects.create_user('expo', 'goatchurch@gmail.com', 'gosser')
|
||||
user.is_staff = True
|
||||
@@ -111,6 +117,59 @@ def export_cavetab():
|
||||
tocavetab.writeCaveTab(outfile)
|
||||
outfile.close()
|
||||
|
||||
def import_auto_logbooks():
|
||||
import parsers.logbooks
|
||||
import os
|
||||
for pt in core.models.PersonTrip.objects.all():
|
||||
pt.delete()
|
||||
for lbe in core.models.LogbookEntry.objects.all():
|
||||
lbe.delete()
|
||||
for expedition in core.models.Expedition.objects.all():
|
||||
directory = os.path.join(settings.EXPOWEB,
|
||||
"years",
|
||||
expedition.year,
|
||||
"autologbook")
|
||||
for root, dirs, filenames in os.walk(directory):
|
||||
for filename in filenames:
|
||||
print os.path.join(root, filename)
|
||||
parsers.logbooks.parseAutoLogBookEntry(os.path.join(root, filename))
|
||||
|
||||
#Temporary function until definative source of data transfered.
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.template import Context, loader
|
||||
def dumplogbooks():
|
||||
def get_name(pe):
|
||||
if pe.nickname:
|
||||
return pe.nickname
|
||||
else:
|
||||
return pe.person.first_name
|
||||
for lbe in core.models.LogbookEntry.objects.all():
|
||||
dateStr = lbe.date.strftime("%Y-%m-%d")
|
||||
directory = os.path.join(settings.EXPOWEB,
|
||||
"years",
|
||||
lbe.expedition.year,
|
||||
"autologbook")
|
||||
if not os.path.isdir(directory):
|
||||
os.mkdir(directory)
|
||||
filename = os.path.join(directory,
|
||||
dateStr + "." + slugify(lbe.title)[:50] + ".html")
|
||||
if lbe.cave:
|
||||
print lbe.cave.reference()
|
||||
trip = {"title": lbe.title, "html":lbe.text, "cave": lbe.cave.reference(), "caveOrLocation": "cave"}
|
||||
else:
|
||||
trip = {"title": lbe.title, "html":lbe.text, "location":lbe.place, "caveOrLocation": "location"}
|
||||
pts = [pt for pt in lbe.persontrip_set.all() if pt.personexpedition]
|
||||
persons = [{"name": get_name(pt.personexpedition), "TU": pt.time_underground, "author": pt.is_logbook_entry_author} for pt in pts]
|
||||
f = open(filename, "wb")
|
||||
template = loader.get_template('dataformat/logbookentry.html')
|
||||
context = Context({'trip': trip,
|
||||
'persons': persons,
|
||||
'date': dateStr,
|
||||
'expeditionyear': lbe.expedition.year})
|
||||
output = template.render(context)
|
||||
f.write(unicode(output).encode( "utf-8" ))
|
||||
f.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import core.models
|
||||
import sys
|
||||
@@ -118,6 +177,8 @@ if __name__ == "__main__":
|
||||
resetdesc()
|
||||
elif "scans" in sys.argv:
|
||||
import_surveyscans()
|
||||
elif "QMs" in sys.argv:
|
||||
import_QMs()
|
||||
elif "tunnel" in sys.argv:
|
||||
import_tunnelfiles()
|
||||
elif "reset" in sys.argv:
|
||||
@@ -129,6 +190,10 @@ if __name__ == "__main__":
|
||||
elif "logbooks" in sys.argv:
|
||||
management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
||||
import_logbooks()
|
||||
elif "autologbooks" in sys.argv:
|
||||
import_auto_logbooks()
|
||||
elif "dumplogbooks" in sys.argv:
|
||||
dumplogbooks()
|
||||
else:
|
||||
print "Do 'python databaseReset.py reset'"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user