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
SRCT
where
Commits
511ad440
Unverified
Commit
511ad440
authored
Feb 16, 2020
by
Dylan Jones
Browse files
what is this, some kind of real project with docstrings???
parent
5930bcc4
Changes
2
Hide whitespace changes
Inline
Side-by-side
where/model/field_types.py
View file @
511ad440
...
...
@@ -9,11 +9,25 @@ class FieldType(enum.Enum):
RATING
=
{
'num_reviews'
:
int
,
'average_rating'
:
float
}
def
validate
(
self
,
data
):
"""
Given an instance of a value, verfiy that the instance satisfies the
schema for this primitive type. e.g. if FieldType.STRING.validate was
called, it would make sure that the `data` parameter looked like
{
"value": "some string"
}
This method throws a ValueError if the passed value doesn't conform to the
schema.
:param data: the instance of this primitive to validate.
:raises ValueError: if the passed data is incorrect
"""
if
type
(
data
)
is
not
dict
:
raise
ValueError
(
"YA DONE GOOFED. NEED A DICT."
)
for
field
in
self
.
value
:
if
field
not
in
data
:
raise
ValueError
(
f
"Fields of type
{
self
.
name
}
need a
{
field
}
field"
)
self
.
value
[
field
](
data
[
field
])
# This will throw ValueError if it fails to validate
if
type
(
data
[
field
])
is
not
self
.
value
[
field
]:
raise
ValueError
(
f
"Expecting field of type
{
self
.
value
[
field
]
}
, got
{
type
(
data
[
field
])
}
"
)
if
len
(
data
)
!=
len
(
self
.
value
):
raise
ValueError
(
f
"Too many fields for field of type
{
self
.
name
}
"
)
where/model/sa.py
View file @
511ad440
...
...
@@ -29,7 +29,7 @@ class Base(object):
class
Point
(
Base
):
"""
TODO docstring
Represents actual instances of any and all points on the map.
"""
__tablename__
=
'point'
name
=
Column
(
String
,
nullable
=
True
)
...
...
@@ -62,7 +62,7 @@ class Point(Base):
class
Category
(
Base
):
"""
Represent a schema for a single category of objects (e.g. water fountain)
Represent a schema for a single category of objects (e.g. water fountain
or bathroom
)
"""
__tablename__
=
'category'
...
...
@@ -74,7 +74,7 @@ class Category(Base):
class
Field
(
Base
):
"""
Represent a
field that can be on an ObjectType
schema
Represent
s
a
single field in the Category
schema
.
"""
__tablename__
=
'field'
...
...
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