Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ross I Kinsey
where
Commits
5930bcc4
Unverified
Commit
5930bcc4
authored
Feb 16, 2020
by
Dylan Jones
Browse files
acutally actually have test data
parent
021ff387
Changes
6
Hide whitespace changes
Inline
Side-by-side
where/alembic/env.py
View file @
5930bcc4
...
...
@@ -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,
...
...
where/app.py
View file @
5930bcc4
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__'
:
...
...
where/model/__init__.py
0 → 100644
View file @
5930bcc4
where/field_types.py
→
where/
model/
field_types.py
View file @
5930bcc4
File moved
where/model/meta.py
0 → 100644
View file @
5930bcc4
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
engine
=
create_engine
(
'sqlite:///db.sqlite3'
)
# TODO configurable
Session
=
sessionmaker
(
bind
=
engine
)
where/sa.py
→
where/
model/
sa.py
View file @
5930bcc4
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment