Merged in bugfix/fix-jsonql-datetime-fields (pull request #46)
Fix datetime fields in selection for recordingsdevelop
commit
d71aca4b8c
|
@ -0,0 +1 @@
|
|||
3.6.6
|
|
@ -7,7 +7,7 @@ from .models import (Device,
|
|||
DeviceType,
|
||||
AccessLevel)
|
||||
from itsdangerous import URLSafeSerializer
|
||||
from app.core import app
|
||||
from app.core import app, db
|
||||
from app.jsonql import api as jsonql
|
||||
|
||||
|
||||
|
@ -335,7 +335,7 @@ def run_custom_query(device_id, request):
|
|||
if not Device.exists(id=device_id):
|
||||
raise ValueError("Device does not exist!")
|
||||
|
||||
def recording_field_provider(name):
|
||||
def recording_field_provider(name, formatted=False):
|
||||
if name == 'record_value':
|
||||
return Recording.record_value
|
||||
if name == 'record_type':
|
||||
|
@ -343,8 +343,14 @@ def run_custom_query(device_id, request):
|
|||
if name == 'device_id':
|
||||
return Recording.device_id
|
||||
if name == 'recorded_at':
|
||||
if formatted:
|
||||
return db.func.to_char(
|
||||
Recording.recorded_at, 'YYYY-MM-DD"T"HH24:MI:SSOF')
|
||||
return Recording.recorded_at
|
||||
if name == 'received_at':
|
||||
if formatted:
|
||||
return db.func.to_char(
|
||||
Recording.received_at, 'YYYY-MM-DD"T"HH24:MI:SSOF')
|
||||
return Recording.received_at
|
||||
|
||||
resulting_query = jsonql.run_query_on(Recording.query.with_entities(),
|
||||
|
|
|
@ -7,11 +7,20 @@ ORDERS = ['asc', 'desc']
|
|||
|
||||
|
||||
def run_query_on(query_object, field_provider, **kwargs):
|
||||
"""
|
||||
Generates a query for target object based on query provided as kwargs
|
||||
|
||||
:param query_object: Initial query object as returned by SQLAlchemy for
|
||||
target table
|
||||
:type query_object: Query
|
||||
:param field_provider: Function which provides fields based on name, with
|
||||
optional parameter formatted which returns the field formatted using sql
|
||||
functions
|
||||
:type field_provider: func(col_name:String, formatted:Boolean)
|
||||
"""
|
||||
selections, filters, groups, orderings = validate_selections(**kwargs)
|
||||
entities = []
|
||||
|
||||
print('Starting with args: ' + str(kwargs))
|
||||
|
||||
if selections is not None:
|
||||
if groups is not None:
|
||||
for group in groups.keys():
|
||||
|
@ -26,9 +35,8 @@ def run_query_on(query_object, field_provider, **kwargs):
|
|||
|
||||
for selection in selections.keys():
|
||||
entities.append(get_column(selections[selection],
|
||||
field_provider(selection)).label(selection))
|
||||
field_provider(selection, True)).label(selection))
|
||||
|
||||
print('New entities: ' + str(entities))
|
||||
query_object = query_object.with_entities(*entities)
|
||||
|
||||
if filters is not None:
|
||||
|
|
Loading…
Reference in New Issue