Commit 5930bcc4 authored by Dylan Jones's avatar Dylan Jones

acutally actually have test data

parent 021ff387
......@@ -19,7 +19,7 @@ fileConfig(config.config_file_name)
# target_metadata = mymodel.Base.metadata
import sys, os
sys.path.append(os.getcwd())
from where.sa import Base
from where.model.sa import Base
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
......
from flask import Flask
from sqlalchemy.orm import Session
from where.field_types import FieldType
from . import sa
from where.model import sa
from where.model.field_types import FieldType
app = Flask(__name__)
......@@ -23,7 +22,7 @@ def index():
@app.route('/test_data')
def test_data():
with sa.session_context() as session:
session = Session()
# session = Session()
session.query(sa.Point).delete()
session.query(sa.Field).delete()
session.query(sa.Category).delete()
......@@ -51,7 +50,10 @@ def test_data():
# an actual instance!
fn = sa.Point()
fn.name = None
fn.category_id = wf.id
fn.lat = 38.829791
fn.lon = -77.307043
# fn.category_id = wf.id
fn.category = wf
fn.parent_id = None
fn.attributes = {
"coldness": {
......@@ -64,6 +66,7 @@ def test_data():
}
session.add(fn)
session.commit()
return "Success!"
if __name__ == '__main__':
......
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///db.sqlite3') # TODO configurable
Session = sessionmaker(bind=engine)
......@@ -2,14 +2,15 @@ from contextlib import contextmanager
from sqlalchemy import String, ForeignKey, Enum, Integer, Float, JSON
from sqlalchemy.ext.declarative import as_declarative
from sqlalchemy.orm import relationship, validates, Session
from sqlalchemy.orm import relationship, validates
from sqlalchemy.schema import Column
from .field_types import FieldType
from .meta import Session
@contextmanager
def session_context() -> Session:
def session_context():
session = Session()
try:
yield session
......@@ -51,10 +52,10 @@ class Point(Base):
for key in data:
# Find Field object that corresponds to this key
for field in fields:
if field.name == key:
if field.slug == key:
break
else:
raise ValueError('extra data must be a registered field')
raise ValueError(f'extra data "{key}" must be a registered field')
field.validate_data(data[key])
return data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment