import datetime from google.appengine.ext import db from google.appengine.tools import bulkloader from google.appengine.api import datastore_types from equations.models import * dstr = '%m/%d/%Y' class SymbolLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Symbol', [('name', str), ('latex', str), ('unicode', str), ]) class SymbolExporter(bulkloader.Exporter): def __init__(self): bulkloader.Exporter.__init__(self, 'Symbol', [('name', str, None), ('latex', str, None), ('unicode', str, None), ]) class VariableLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Variable', [('name', str), ('latex', str), ('unicode', str), ('description', str), ('symbol', str), ('references', str.split), ('isgeneric', boolean), ]) def HandleEntity(self, entity): f = Symbol.all().filter("name =", entity['symbol']).get() entity['symbol'] = f.key() reflist = [] refstr = eval(entity['references'][0]) for ref in refstr: r = datastore_types.Link(ref) reflist.append(r) entity['references'] = reflist class VariableExporter(bulkloader.Exporter): def __init__(self): bulkloader.Exporter.__init__(self, 'Variable', [('name', str, None), ('latex', str, None), ('unicode', str, None), ('description', str, None), ('symbol', str, None), ('references', str, None), ('isgeneric', str, None), ]) class EquationLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Equation', [('name', str), ('latex', str), ('unicode', str), ('description', str), ('created', lambda x: datetime.datetime.strptime(x, dstr).date()), ('updated', lambda x: datetime.datetime.strptime(x, dstr).date()), ('variables', str.split), ('references', str.split), ('userurl', datastore_types.Link), ]) def HandleEntity(self, entity): vlist = [] vstr = eval(entity['variables'][0]) for var in vstr: v = Variable.all().filter("name =", var).get() vlist.append(v.key()) entity['variables'] = vlist reflist = [] refstr = eval(entity['references'][0]) for ref in refstr: r = datastore_types.Link(ref) reflist.append(r) entity['references'] = reflist class EquationExporter(bulkloader.Exporter): def __init__(self): bulkloader.Exporter.__init__(self, 'Equation', [('name', str, None), ('latex', str, None), ('unicode', str, None), ('description', str, None), ('created', str, None), ('updated', str, None), ('variables', str, None), ('references', str, None), ('userurl', str, None), ]) loaders = [SymbolLoader, VariableLoader, EquationLoader] exporters= [SymbolExporter, VariableExporter, EquationExporter]