Skip to content

Commit

Permalink
Merge pull request #208 from hydroserver2/220-sensorthings-pagination
Browse files Browse the repository at this point in the history
220 sensorthings pagination
kjlippold authored Oct 4, 2024
2 parents 7dd60be + e230919 commit 62fbe4d
Showing 8 changed files with 48 additions and 34 deletions.
16 changes: 11 additions & 5 deletions hydroserver/settings.py
Original file line number Diff line number Diff line change
@@ -23,22 +23,28 @@
DEPLOYMENT_BACKEND = config('DEPLOYMENT_BACKEND', default='local')
DISABLE_ACCOUNT_CREATION = config('DISABLE_ACCOUNT_CREATION', default=False, cast=bool)

# CORS Settings

CORS_ORIGIN_ALLOW_ALL = True
CORS_URLS_REGEX = r'^/api/.*$'
CORS_ALLOW_HEADERS = list(default_headers)

# Deployment Settings

if DEPLOYMENT_BACKEND == 'aws':
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname) # This is necessary for AWS ELB Health Checks to pass.
PROXY_BASE_URL = config('PROXY_BASE_URL')
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=PROXY_BASE_URL).split(',') + [local_ip]
CSRF_TRUSTED_ORIGINS = [PROXY_BASE_URL]
CORS_ALLOW_HEADERS = list(default_headers) + ['Refresh_Authorization']
CORS_ALLOW_HEADERS += ['Refresh_Authorization']
elif DEPLOYMENT_BACKEND == 'vm':
PROXY_BASE_URL = config('PROXY_BASE_URL')
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=PROXY_BASE_URL).split(',')
CSRF_TRUSTED_ORIGINS = [PROXY_BASE_URL]
else:
PROXY_BASE_URL = config('PROXY_BASE_URL', 'http://127.0.0.1:3030')
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
CSRF_TRUSTED_ORIGINS = [PROXY_BASE_URL]
CORS_ORIGIN_ALLOW_ALL = True # Warning: Do not use this setting in production.

CSRF_TRUSTED_ORIGINS = [PROXY_BASE_URL]

LOGIN_REDIRECT_URL = 'sites'
LOGOUT_REDIRECT_URL = 'home'
2 changes: 2 additions & 0 deletions stapi/engine/components/datastreams.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,8 @@ def get_datastreams(
order_by=ordering
)

datastreams = datastreams.distinct()

if get_count:
count = datastreams.count()
else:
2 changes: 2 additions & 0 deletions stapi/engine/components/locations.py
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ def get_locations(
order_by=ordering
)

things = things.distinct()

if get_count:
count = things.count()
else:
4 changes: 2 additions & 2 deletions stapi/engine/components/observations.py
Original file line number Diff line number Diff line change
@@ -77,13 +77,13 @@ def get_observations(
order_by=ordering
)

observations = observations.distinct()

if get_count:
count = observations.count()
else:
count = None

observations = observations.distinct()

if datastream_ids:
observations = self.apply_rank(
component=ObservationSchema,
2 changes: 2 additions & 0 deletions stapi/engine/components/observed_properties.py
Original file line number Diff line number Diff line change
@@ -45,6 +45,8 @@ def get_observed_properties(
order_by=ordering
)

observed_properties = observed_properties.distinct()

if get_count:
count = observed_properties.count()
else:
2 changes: 2 additions & 0 deletions stapi/engine/components/sensors.py
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ def get_sensors(
order_by=ordering
)

sensors = sensors.distinct()

if get_count:
count = sensors.count()
else:
2 changes: 2 additions & 0 deletions stapi/engine/components/things.py
Original file line number Diff line number Diff line change
@@ -64,6 +64,8 @@ def get_things(
order_by=ordering
)

things = things.distinct()

if get_count:
count = things.count()
else:
52 changes: 25 additions & 27 deletions tests/test_sensorthings_endpoints.py

Large diffs are not rendered by default.

0 comments on commit 62fbe4d

Please sign in to comment.