Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ POSTGRES_DB=
GCS_BUCKET_NAME=
GOOGLE_APPLICATION_CREDENTIALS=/path/to/gcs_credentials.json


# set to development for lexicon and parameter to be populated and enable the enums to work
MODE=development

# disable authentication (for development only)
AUTHENTIK_DISABLE_AUTHENTICATION=1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pre-commit install
cp .env.example .env
```

In development set `MODE=development` to allow lexicon enums to be populated.

#### 5. Database and server


Expand Down
1 change: 1 addition & 0 deletions core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@
Unit: type[Enum] = build_enum_from_lexicon_category("unit")
Vertical_datum: type[Enum] = build_enum_from_lexicon_category("vertical_datum")
ScreenType: type[Enum] = build_enum_from_lexicon_category("screen_type")
SensorType: type[Enum] = build_enum_from_lexicon_category("sensor_type")
# ============= EOF =============================================
13 changes: 3 additions & 10 deletions schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
ConfigDict,
AwareDatetime,
field_validator,
model_serializer,
)
from pydantic.json_schema import JsonSchemaValue
from pydantic_core import core_schema

from core.enums import ReleaseStatus

DT_FMT = "%Y-%m-%dT%H:%M:%SZ"


class ResourceNotFoundResponse(BaseModel):
detail: str
Expand Down Expand Up @@ -66,7 +67,7 @@ def serialize_dt(value: datetime) -> str:
if value.tzinfo != timezone.utc:
value = value.astimezone(timezone.utc)
# Format with Z suffix
return value.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
return value.strftime(DT_FMT)

# Use generate_schema instead of calling handler directly
python_schema = handler.generate_schema(datetime)
Expand Down Expand Up @@ -96,14 +97,6 @@ class BaseResponseModel(BaseModel):
populate_by_name=True,
)

@model_serializer
def serialize(self):
data = self.__dict__.copy()
# If release_status is an enum, convert to string
if hasattr(data.get("release_status"), "value"):
data["release_status"] = data["release_status"].value
return data


# TODO: write function to convert any datetime field to UTC for use throughout
# for schema field_validators
Expand Down
4 changes: 2 additions & 2 deletions schemas/field.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pydantic import AwareDatetime

from schemas import BaseResponseModel

from core.enums import ActivityType

# RESPONSE ---------------------------------------------------------------------


class FieldActivityResponse(BaseResponseModel):
field_event_id: int
activity_type: str
activity_type: ActivityType


class FieldEventResponse(BaseResponseModel):
Expand Down
6 changes: 3 additions & 3 deletions schemas/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class LocationResponse(BaseResponseModel):
point: str
elevation: float | None
horizontal_datum: str = "WGS84"
vertical_daum: str = "NAVD88"
vertical_datum: str = "NAVD88"
elevation_accuracy: float | None
elevation_method: str | None
elevation_method: ElevationMethod | None
coordinate_accuracy: float | None
coordinate_method: str | None
coordinate_method: CoordinateMethod | None
state: str | None
county: str | None
quad_name: str | None
Expand Down
8 changes: 4 additions & 4 deletions schemas/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
UTCAwareDatetime,
)
from schemas.parameter import ParameterResponse

from core.enums import Unit

# class GeothermalMixin:
# depth: float
Expand Down Expand Up @@ -69,7 +69,7 @@ class CreateBaseObservation(BaseCreateModel, ValidateObservation):
sensor_id: int
parameter_id: int
value: float | None
unit: str | None
unit: Unit | None


class CreateGroundwaterLevelObservation(CreateBaseObservation):
Expand All @@ -90,7 +90,7 @@ class UpdateBaseObservation(BaseUpdateModel, ValidateObservation):
sensor_id: int | None = None
parameter_id: int | None = None
value: float | None | None = None
unit: str | None = None
unit: Unit | None = None


class UpdateGroundwaterLevelObservation(UpdateBaseObservation):
Expand All @@ -110,7 +110,7 @@ class BaseObservationResponse(BaseResponseModel):
observation_datetime: UTCAwareDatetime
parameter: ParameterResponse
value: float | None
unit: str
unit: Unit


class GroundwaterLevelObservationResponse(BaseObservationResponse):
Expand Down
7 changes: 4 additions & 3 deletions schemas/parameter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from schemas import BaseResponseModel
from core.enums import ParameterType, ParameterName, Unit


# -------- RESPONSE -------
Expand All @@ -8,8 +9,8 @@ class ParameterResponse(BaseResponseModel):
This model can be extended to include additional fields as needed.
"""

parameter_name: str
parameter_name: ParameterName
matrix: str
parameter_type: str | None
parameter_type: ParameterType | None
cas_number: str | None
default_unit: str
default_unit: Unit | None
5 changes: 3 additions & 2 deletions schemas/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
# ===============================================================================
from pydantic import BaseModel
from core.enums import PublicationType


# -------- CREATE ----------
Expand All @@ -28,7 +29,7 @@ class CreatePublication(BaseModel):
doi: str | None = None
url: str | None = None

publication_type: str
publication_type: PublicationType


# -------- RESPONSE ----------
Expand All @@ -54,7 +55,7 @@ class PublicationResponse(BaseModel):
year: int
doi: str | None = None
url: str | None = None
publication_type: str
publication_type: PublicationType


# -------- UPDATE ----------
Expand Down
6 changes: 3 additions & 3 deletions schemas/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ class SampleResponse(BaseResponseModel):
contact: ContactResponse
sample_date: UTCAwareDatetime
sample_name: str
sample_matrix: str
sample_method: str
qc_type: str
sample_matrix: SampleMatrix
sample_method: SampleMethod
qc_type: SampleQcType
notes: str | None
depth_top: float | None
depth_bottom: float | None
Expand Down
8 changes: 4 additions & 4 deletions schemas/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# model_validator,
# field_validator,
# )

from core.enums import SensorType
from schemas import BaseCreateModel, BaseUpdateModel, BaseResponseModel

# ------- VALIDATION ------
Expand Down Expand Up @@ -58,7 +58,7 @@ class CreateSensor(BaseCreateModel):
"""

name: str
sensor_type: str
sensor_type: SensorType
model: str | None = None
serial_no: str | None = None
pcn_number: str | None = None
Expand All @@ -70,7 +70,7 @@ class CreateSensor(BaseCreateModel):
# -------- UPDATE ----------
class UpdateSensor(BaseUpdateModel):
name: str | None = None
sensor_type: str | None = None
sensor_type: SensorType | None = None
model: str | None = None
serial_no: str | None = None
pcn_number: str | None = None
Expand All @@ -82,7 +82,7 @@ class UpdateSensor(BaseUpdateModel):
# -------- RESPONSE ----------
class SensorResponse(BaseResponseModel):
name: str
sensor_type: str
sensor_type: SensorType
model: str | None # = Column(String(50))
serial_no: str | None # = Column(String(50))
pcn_number: str | None
Expand Down
2 changes: 0 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
groundwater_level_parameter_id = parameter_map[("groundwater level", "Field Parameter")]
pH_parameter_id = parameter_map[("pH", "Field Parameter")]

DT_FMT = "%Y-%m-%dT%H:%M:%S.%fZ"


def override_authentication(default=True):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
from core.app import app
from core.dependencies import viewer_function, admin_function, editor_function
from db import Asset
from schemas import DT_FMT
from tests import (
client,
cleanup_post_test,
override_authentication,
cleanup_patch_test,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
)
from db import Contact, Address, Email, Phone
from main import app
from schemas import DT_FMT
from schemas.contact import ValidateEmail, ValidatePhone, ValidateContact
from tests import (
client,
cleanup_post_test,
cleanup_patch_test,
override_authentication,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from core.dependencies import admin_function, viewer_function, editor_function
from db import Group
from main import app
from schemas import DT_FMT
from schemas.group import ValidateGroup
from tests import (
client,
override_authentication,
cleanup_post_test,
cleanup_patch_test,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
)
from db import LexiconTerm, LexiconCategory, LexiconTriple
from main import app
from schemas import DT_FMT
from tests import (
client,
override_authentication,
cleanup_post_test,
cleanup_patch_test,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
from core.dependencies import admin_function, editor_function, viewer_function
from db import Location
from main import app
from schemas import DT_FMT
from tests import (
client,
override_authentication,
cleanup_post_test,
cleanup_patch_test,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
)
from db import Observation
from main import app
from schemas import DT_FMT
from tests import (
client,
cleanup_post_test,
override_authentication,
cleanup_patch_test,
groundwater_level_parameter_id,
pH_parameter_id,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from core.dependencies import admin_function, editor_function, viewer_function
from db.sample import Sample
from main import app
from schemas import DT_FMT
from schemas.sample import ValidateSample
from tests import (
client,
cleanup_post_test,
cleanup_patch_test,
override_authentication,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
from main import app

# from schemas.sensor import ValidateSensor
from schemas import DT_FMT
from tests import (
client,
cleanup_post_test,
cleanup_patch_test,
override_authentication,
groundwater_level_parameter_id,
DT_FMT,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
from main import app
from schemas.location import LocationResponse
from schemas.thing import ValidateWell
from schemas import DT_FMT
from tests import (
client,
override_authentication,
cleanup_post_test,
cleanup_patch_test,
DT_FMT,
)


Expand Down
Loading