commit
04edfcdd90
|
@ -14,7 +14,7 @@ def create_account(username, email, password):
|
||||||
:type username: string
|
:type username: string
|
||||||
:type email: string
|
:type email: string
|
||||||
:type password: string
|
:type password: string
|
||||||
:returns: Email confirmation token if creation was successful
|
:returns: Account and Email confirmation token if creation was successful
|
||||||
:rtype: string
|
:rtype: string
|
||||||
:raises: ValueError if account already exists
|
:raises: ValueError if account already exists
|
||||||
"""
|
"""
|
||||||
|
@ -24,7 +24,7 @@ def create_account(username, email, password):
|
||||||
account.save()
|
account.save()
|
||||||
|
|
||||||
emailtoken = generate_confirmation_token(account.email)
|
emailtoken = generate_confirmation_token(account.email)
|
||||||
return emailtoken
|
return account, emailtoken
|
||||||
|
|
||||||
raise ValueError("Account with given parameters already exists")
|
raise ValueError("Account with given parameters already exists")
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ def update_account_role(account_id, role_id):
|
||||||
acc = Account.get(id=account_id)
|
acc = Account.get(id=account_id)
|
||||||
acc.role_id = role_id
|
acc.role_id = role_id
|
||||||
acc.save()
|
acc.save()
|
||||||
|
return acc
|
||||||
|
|
||||||
|
|
||||||
def create_role(display_name, permissions):
|
def create_role(display_name, permissions):
|
||||||
|
@ -74,6 +75,7 @@ def create_role(display_name, permissions):
|
||||||
"""
|
"""
|
||||||
role = Role(display_name, permissions)
|
role = Role(display_name, permissions)
|
||||||
role.save()
|
role.save()
|
||||||
|
return role
|
||||||
|
|
||||||
|
|
||||||
def get_role(role_id):
|
def get_role(role_id):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from calendar import timegm
|
||||||
class Account(db.Model):
|
class Account(db.Model):
|
||||||
__tablename__ = 'accounts'
|
__tablename__ = 'accounts'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
username = db.Column(db.String, index=True, unique=True)
|
username = db.Column(db.String, index=True, unique=True)
|
||||||
password = db.Column(db.String)
|
password = db.Column(db.String)
|
||||||
email = db.Column(db.String, index=True, unique=True)
|
email = db.Column(db.String, index=True, unique=True)
|
||||||
|
@ -123,7 +123,7 @@ class Account(db.Model):
|
||||||
class Role(db.Model):
|
class Role(db.Model):
|
||||||
__tablename__ = 'roles'
|
__tablename__ = 'roles'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
display_name = db.Column(db.String, unique=True)
|
display_name = db.Column(db.String, unique=True)
|
||||||
permissions = db.Column(db.ARRAY(db.String))
|
permissions = db.Column(db.ARRAY(db.String))
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,9 @@ class RolesResource(ProtectedResource):
|
||||||
@use_args(RoleCreationSchema(), locations=('json',))
|
@use_args(RoleCreationSchema(), locations=('json',))
|
||||||
@swag_from('swagger/create_role_spec.yaml')
|
@swag_from('swagger/create_role_spec.yaml')
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
success = accounts.create_role(args['display_name'],
|
created_role = accounts.create_role(args['display_name'],
|
||||||
args['permissions'])
|
args['permissions'])
|
||||||
if success:
|
return RoleSchema().dump(created_role), 201
|
||||||
return '', 201
|
|
||||||
|
|
||||||
@swag_from('swagger/get_roles_spec.yaml')
|
@swag_from('swagger/get_roles_spec.yaml')
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -77,9 +76,9 @@ class AccountRoleResource(ProtectedResource):
|
||||||
if g.current_account.id == account_id:
|
if g.current_account.id == account_id:
|
||||||
abort(403, message='You may not change your own roles',
|
abort(403, message='You may not change your own roles',
|
||||||
status='error')
|
status='error')
|
||||||
success = accounts.update_account_role(account_id, args['role_id'])
|
updated_account = accounts.update_account_role(
|
||||||
if success:
|
account_id, args['role_id'])
|
||||||
return '', 204
|
return UserSchema().dump(updated_account), 200
|
||||||
|
|
||||||
|
|
||||||
class AccountListResource(Resource):
|
class AccountListResource(Resource):
|
||||||
|
@ -87,7 +86,7 @@ class AccountListResource(Resource):
|
||||||
@swag_from('swagger/create_account_spec.yaml')
|
@swag_from('swagger/create_account_spec.yaml')
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
try:
|
try:
|
||||||
emailtoken = accounts.create_account(
|
created_account, emailtoken = accounts.create_account(
|
||||||
args['username'],
|
args['username'],
|
||||||
args['email'],
|
args['email'],
|
||||||
args['password'])
|
args['password'])
|
||||||
|
@ -101,7 +100,7 @@ class AccountListResource(Resource):
|
||||||
args['email'],
|
args['email'],
|
||||||
'Please confirm your email',
|
'Please confirm your email',
|
||||||
html)
|
html)
|
||||||
return '', 201
|
return UserSchema().dump(created_account), 201
|
||||||
except ValueError:
|
except ValueError:
|
||||||
abort(422, message='Account already exists', status='error')
|
abort(422, message='Account already exists', status='error')
|
||||||
|
|
||||||
|
|
|
@ -57,27 +57,25 @@ class DashboardResource(ProtectedResource):
|
||||||
@swag_from('swagger/update_dashboard_spec.yaml')
|
@swag_from('swagger/update_dashboard_spec.yaml')
|
||||||
def put(self, args, dashboard_id):
|
def put(self, args, dashboard_id):
|
||||||
validate_dashboard_ownership(dashboard_id)
|
validate_dashboard_ownership(dashboard_id)
|
||||||
success = dashboard.patch_dashboard(
|
updated_dashboard = dashboard.patch_dashboard(
|
||||||
g.current_account.id,
|
g.current_account.id,
|
||||||
dashboard_id,
|
dashboard_id,
|
||||||
args['dashboard_data'],
|
args['dashboard_data'],
|
||||||
args['active'],
|
args['active'],
|
||||||
args['name'])
|
args['name'])
|
||||||
if success:
|
return DashboardSchema().dump(updated_dashboard), 200
|
||||||
return '', 204
|
|
||||||
|
|
||||||
@use_args(DashboardSchema(partial=True), locations=('json',))
|
@use_args(DashboardSchema(partial=True), locations=('json',))
|
||||||
@swag_from('swagger/update_dashboard_spec.yaml')
|
@swag_from('swagger/update_dashboard_spec.yaml')
|
||||||
def patch(self, args, dashboard_id):
|
def patch(self, args, dashboard_id):
|
||||||
validate_dashboard_ownership(dashboard_id)
|
validate_dashboard_ownership(dashboard_id)
|
||||||
success = dashboard.patch_dashboard(
|
updated_dashboard = dashboard.patch_dashboard(
|
||||||
g.current_account.id,
|
g.current_account.id,
|
||||||
dashboard_id,
|
dashboard_id,
|
||||||
args.get('dashboard_data'),
|
args.get('dashboard_data'),
|
||||||
args.get('active'),
|
args.get('active'),
|
||||||
args.get('name'))
|
args.get('name'))
|
||||||
if success:
|
return DashboardSchema().dump(updated_dashboard), 200
|
||||||
return '', 204
|
|
||||||
|
|
||||||
@swag_from('swagger/delete_dashboard_spec.yaml')
|
@swag_from('swagger/delete_dashboard_spec.yaml')
|
||||||
def delete(self, dashboard_id):
|
def delete(self, dashboard_id):
|
||||||
|
@ -90,12 +88,11 @@ class DashboardListResource(ProtectedResource):
|
||||||
@use_args(DashboardSchema(), locations=('json',))
|
@use_args(DashboardSchema(), locations=('json',))
|
||||||
@swag_from('swagger/create_dashboard_spec.yaml')
|
@swag_from('swagger/create_dashboard_spec.yaml')
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
success = dashboard.create_dashboard(
|
created_dashboard = dashboard.create_dashboard(
|
||||||
args['dashboard_data'],
|
args['dashboard_data'],
|
||||||
args['name'],
|
args['name'],
|
||||||
g.current_account.id)
|
g.current_account.id)
|
||||||
if success:
|
return DashboardSchema().dump(created_dashboard), 201
|
||||||
return '', 201
|
|
||||||
|
|
||||||
@swag_from('swagger/get_dashboards_spec.yaml')
|
@swag_from('swagger/get_dashboards_spec.yaml')
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -112,7 +109,7 @@ class DashboardWidgetListResource(ProtectedResource):
|
||||||
def post(self, args, dashboard_id):
|
def post(self, args, dashboard_id):
|
||||||
validate_dashboard_ownership(dashboard_id)
|
validate_dashboard_ownership(dashboard_id)
|
||||||
validate_device_ownership(args['device_id'])
|
validate_device_ownership(args['device_id'])
|
||||||
success = dashboard.create_widget(
|
created_widget = dashboard.create_widget(
|
||||||
dashboard_id,
|
dashboard_id,
|
||||||
args['device_id'],
|
args['device_id'],
|
||||||
args['height'],
|
args['height'],
|
||||||
|
@ -121,8 +118,7 @@ class DashboardWidgetListResource(ProtectedResource):
|
||||||
args['y'],
|
args['y'],
|
||||||
args['chart_type'],
|
args['chart_type'],
|
||||||
args['filters'])
|
args['filters'])
|
||||||
if success:
|
return DashboardWidgetSchema().dump(created_widget), 201
|
||||||
return '', 201
|
|
||||||
|
|
||||||
@swag_from('swagger/get_dashboard_widgets_spec.yaml')
|
@swag_from('swagger/get_dashboard_widgets_spec.yaml')
|
||||||
def get(self, dashboard_id):
|
def get(self, dashboard_id):
|
||||||
|
@ -143,7 +139,7 @@ class DashboardWidgetResource(ProtectedResource):
|
||||||
def put(self, args, dashboard_id, widget_id):
|
def put(self, args, dashboard_id, widget_id):
|
||||||
validate_dashboard_ownership(dashboard_id)
|
validate_dashboard_ownership(dashboard_id)
|
||||||
validate_device_ownership(args['device_id'])
|
validate_device_ownership(args['device_id'])
|
||||||
success = dashboard.patch_widget(
|
updated_widget = dashboard.patch_widget(
|
||||||
widget_id,
|
widget_id,
|
||||||
args['device_id'],
|
args['device_id'],
|
||||||
args['height'],
|
args['height'],
|
||||||
|
@ -152,8 +148,7 @@ class DashboardWidgetResource(ProtectedResource):
|
||||||
args['y'],
|
args['y'],
|
||||||
args['chart_type'],
|
args['chart_type'],
|
||||||
args['filters'])
|
args['filters'])
|
||||||
if success:
|
return DashboardWidgetSchema().dump(updated_widget), 200
|
||||||
return '', 204
|
|
||||||
|
|
||||||
@use_args(DashboardWidgetSchema(partial=True), locations=('json',))
|
@use_args(DashboardWidgetSchema(partial=True), locations=('json',))
|
||||||
@swag_from('swagger/update_dashboard_widget_spec.yaml')
|
@swag_from('swagger/update_dashboard_widget_spec.yaml')
|
||||||
|
@ -161,7 +156,7 @@ class DashboardWidgetResource(ProtectedResource):
|
||||||
validate_dashboard_ownership(dashboard_id)
|
validate_dashboard_ownership(dashboard_id)
|
||||||
if args.get('device_id') is not None:
|
if args.get('device_id') is not None:
|
||||||
validate_device_ownership(args['device_id'])
|
validate_device_ownership(args['device_id'])
|
||||||
success = dashboard.patch_widget(
|
updated_widget = dashboard.patch_widget(
|
||||||
widget_id,
|
widget_id,
|
||||||
args.get('device_id'),
|
args.get('device_id'),
|
||||||
args.get('height'),
|
args.get('height'),
|
||||||
|
@ -170,8 +165,7 @@ class DashboardWidgetResource(ProtectedResource):
|
||||||
args.get('y'),
|
args.get('y'),
|
||||||
args.get('chart_type'),
|
args.get('chart_type'),
|
||||||
args.get('filters'))
|
args.get('filters'))
|
||||||
if success:
|
return DashboardWidgetSchema().dump(updated_widget), 200
|
||||||
return '', 204
|
|
||||||
|
|
||||||
@swag_from('swagger/delete_dashboard_widget_spec.yaml')
|
@swag_from('swagger/delete_dashboard_widget_spec.yaml')
|
||||||
def delete(self, dashboard_id, widget_id):
|
def delete(self, dashboard_id, widget_id):
|
||||||
|
|
|
@ -44,7 +44,7 @@ class DeviceResource(ProtectedResource):
|
||||||
@swag_from('swagger/get_device_spec.yaml')
|
@swag_from('swagger/get_device_spec.yaml')
|
||||||
def get(self, device_id):
|
def get(self, device_id):
|
||||||
validate_device_ownership(device_id)
|
validate_device_ownership(device_id)
|
||||||
return DeviceSchema().dump(
|
return DeviceWithConfigurationSchema().dump(
|
||||||
devices.get_device(device_id)), 200
|
devices.get_device(device_id)), 200
|
||||||
|
|
||||||
@swag_from('swagger/delete_device_spec.yaml')
|
@swag_from('swagger/delete_device_spec.yaml')
|
||||||
|
@ -68,10 +68,9 @@ class DeviceTypeListResource(ProtectedResource):
|
||||||
if g.current_account.role_id != 1:
|
if g.current_account.role_id != 1:
|
||||||
abort(403, message='Only admin may create device types',
|
abort(403, message='Only admin may create device types',
|
||||||
status='error')
|
status='error')
|
||||||
success = devices.create_device_type(
|
created_device_type = devices.create_device_type(
|
||||||
args['name'])
|
args['name'])
|
||||||
if success:
|
return DeviceTypeSchema().dump(created_device_type), 201
|
||||||
return '', 201
|
|
||||||
|
|
||||||
@swag_from('swagger/get_device_types_spec.yaml')
|
@swag_from('swagger/get_device_types_spec.yaml')
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -94,21 +93,20 @@ class DeviceRecordingResource(ProtectedResource):
|
||||||
@swag_from('swagger/create_device_recording_spec.yaml')
|
@swag_from('swagger/create_device_recording_spec.yaml')
|
||||||
def post(self, device_id):
|
def post(self, device_id):
|
||||||
validate_device_ownership(device_id)
|
validate_device_ownership(device_id)
|
||||||
success = devices.create_recording(device_id, request.json)
|
created_recording = devices.create_recording_and_return(
|
||||||
if success:
|
device_id, request.json)
|
||||||
return '', 201
|
return RecordingsSchema().dump(created_recording), 201
|
||||||
|
|
||||||
|
|
||||||
class DeviceListResource(ProtectedResource):
|
class DeviceListResource(ProtectedResource):
|
||||||
@use_args(DeviceSchema(), locations=('json',))
|
@use_args(DeviceSchema(), locations=('json',))
|
||||||
@swag_from('swagger/create_device_spec.yaml')
|
@swag_from('swagger/create_device_spec.yaml')
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
success = devices.create_device(
|
created_device = devices.create_device(
|
||||||
args['name'],
|
args['name'],
|
||||||
g.current_account.id,
|
g.current_account.id,
|
||||||
args['device_type_id'])
|
args['device_type_id'])
|
||||||
if success:
|
return DeviceSchema().dump(created_device), 201
|
||||||
return '', 201
|
|
||||||
|
|
||||||
@swag_from('swagger/get_devices_spec.yaml')
|
@swag_from('swagger/get_devices_spec.yaml')
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -120,9 +118,10 @@ class DeviceConfigurationResource(ProtectedResource):
|
||||||
@swag_from('swagger/update_device_configuration_spec.yaml')
|
@swag_from('swagger/update_device_configuration_spec.yaml')
|
||||||
def put(self, device_id):
|
def put(self, device_id):
|
||||||
validate_device_ownership(device_id)
|
validate_device_ownership(device_id)
|
||||||
success = devices.set_device_configuration(device_id, request.json)
|
updated_device = devices.set_device_configuration(
|
||||||
if success:
|
device_id, request.json)
|
||||||
return '', 204
|
return DeviceWithConfigurationSchema().dump(
|
||||||
|
updated_device), 200
|
||||||
|
|
||||||
@swag_from('swagger/get_device_configuration_spec.yaml')
|
@swag_from('swagger/get_device_configuration_spec.yaml')
|
||||||
def get(self, device_id):
|
def get(self, device_id):
|
||||||
|
|
|
@ -14,7 +14,14 @@ parameters:
|
||||||
security: []
|
security: []
|
||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
422:
|
422:
|
||||||
description: Account already exists
|
description: Account already exists
|
||||||
schema:
|
schema:
|
||||||
|
|
|
@ -11,5 +11,12 @@ parameters:
|
||||||
type: object
|
type: object
|
||||||
$ref: '#/definitions/DashboardCreation'
|
$ref: '#/definitions/DashboardCreation'
|
||||||
responses:
|
responses:
|
||||||
201:
|
200:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/Dashboard'
|
||||||
|
|
|
@ -16,5 +16,12 @@ parameters:
|
||||||
type: object
|
type: object
|
||||||
$ref: '#/definitions/WidgetCreation'
|
$ref: '#/definitions/WidgetCreation'
|
||||||
responses:
|
responses:
|
||||||
201:
|
200:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/Widget'
|
||||||
|
|
|
@ -16,4 +16,11 @@ parameters:
|
||||||
$ref: '#/definitions/RecordingCreation'
|
$ref: '#/definitions/RecordingCreation'
|
||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/Recording'
|
||||||
|
|
|
@ -12,4 +12,11 @@ parameters:
|
||||||
$ref: '#/definitions/DeviceCreation'
|
$ref: '#/definitions/DeviceCreation'
|
||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/DeviceWithConfig'
|
||||||
|
|
|
@ -12,4 +12,11 @@ parameters:
|
||||||
$ref: '#/definitions/DeviceType'
|
$ref: '#/definitions/DeviceType'
|
||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/DeviceType'
|
||||||
|
|
|
@ -12,4 +12,11 @@ parameters:
|
||||||
$ref: '#/definitions/Role'
|
$ref: '#/definitions/Role'
|
||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: Successful creation
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/Role'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Deletes a dashboard
|
Deletes a widget
|
||||||
---
|
---
|
||||||
tags:
|
tags:
|
||||||
- Dashboard
|
- Dashboard
|
||||||
|
@ -8,6 +8,11 @@ parameters:
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
type: integer
|
||||||
description: Id of the dashboard
|
description: Id of the dashboard
|
||||||
|
- in: path
|
||||||
|
name: widget_id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
description: Id of the widget
|
||||||
responses:
|
responses:
|
||||||
204:
|
204:
|
||||||
description: Success
|
description: Success
|
||||||
|
|
|
@ -20,5 +20,12 @@ parameters:
|
||||||
role_id:
|
role_id:
|
||||||
type: integer
|
type: integer
|
||||||
responses:
|
responses:
|
||||||
204:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/User'
|
||||||
|
|
|
@ -16,5 +16,12 @@ parameters:
|
||||||
type: object
|
type: object
|
||||||
$ref: '#/definitions/DashboardCreation'
|
$ref: '#/definitions/DashboardCreation'
|
||||||
responses:
|
responses:
|
||||||
204:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/Dashboard'
|
||||||
|
|
|
@ -20,5 +20,12 @@ parameters:
|
||||||
type: object
|
type: object
|
||||||
$ref: '#/definitions/WidgetCreation'
|
$ref: '#/definitions/WidgetCreation'
|
||||||
responses:
|
responses:
|
||||||
204:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/Widget'
|
||||||
|
|
|
@ -15,5 +15,12 @@ parameters:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
responses:
|
responses:
|
||||||
204:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/definitions/DeviceWithConfig'
|
||||||
|
|
|
@ -17,6 +17,7 @@ def create_dashboard(dashboard_data, name, account_id):
|
||||||
"""
|
"""
|
||||||
dashboard = Dashboard(account_id, dashboard_data, name)
|
dashboard = Dashboard(account_id, dashboard_data, name)
|
||||||
dashboard.save()
|
dashboard.save()
|
||||||
|
return dashboard
|
||||||
|
|
||||||
|
|
||||||
def get_dashboard(dashboard_id):
|
def get_dashboard(dashboard_id):
|
||||||
|
@ -49,6 +50,8 @@ def patch_dashboard(account_id, dashboard_id,
|
||||||
dashboard.save()
|
dashboard.save()
|
||||||
if active:
|
if active:
|
||||||
set_active_dashboard(account_id, dashboard_id)
|
set_active_dashboard(account_id, dashboard_id)
|
||||||
|
dashboard.active = True
|
||||||
|
return dashboard
|
||||||
|
|
||||||
|
|
||||||
def delete_dashboard(dashboard_id):
|
def delete_dashboard(dashboard_id):
|
||||||
|
@ -111,6 +114,7 @@ def create_widget(dashboard_id, device_id, height, width, x, y,
|
||||||
widget = DashboardWidget(dashboard_id, device_id, height, width, x, y,
|
widget = DashboardWidget(dashboard_id, device_id, height, width, x, y,
|
||||||
chart_type, filters)
|
chart_type, filters)
|
||||||
widget.save()
|
widget.save()
|
||||||
|
return widget
|
||||||
|
|
||||||
|
|
||||||
def delete_widget(widget_id):
|
def delete_widget(widget_id):
|
||||||
|
@ -177,4 +181,4 @@ def patch_widget(widget_id, device_id=None, height=None, width=None,
|
||||||
widget.filters = filters
|
widget.filters = filters
|
||||||
|
|
||||||
widget.save()
|
widget.save()
|
||||||
print("Saved widget")
|
return widget
|
||||||
|
|
|
@ -5,7 +5,7 @@ from sqlalchemy.dialects.postgresql import JSON
|
||||||
class Dashboard(db.Model):
|
class Dashboard(db.Model):
|
||||||
__tablename__ = 'dashboards'
|
__tablename__ = 'dashboards'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
dashboard_data = db.Column(JSON, nullable=False)
|
dashboard_data = db.Column(JSON, nullable=False)
|
||||||
account_id = db.Column(db.Integer, db.ForeignKey('accounts.id'),
|
account_id = db.Column(db.Integer, db.ForeignKey('accounts.id'),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
|
@ -121,7 +121,7 @@ class Dashboard(db.Model):
|
||||||
class DashboardWidget(db.Model):
|
class DashboardWidget(db.Model):
|
||||||
__tablename__ = 'dashboard_widgets'
|
__tablename__ = 'dashboard_widgets'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
dashboard_id = db.Column(db.Integer, db.ForeignKey('dashboards.id'))
|
dashboard_id = db.Column(db.Integer, db.ForeignKey('dashboards.id'))
|
||||||
device_id = db.Column(db.Integer, db.ForeignKey('devices.id'))
|
device_id = db.Column(db.Integer, db.ForeignKey('devices.id'))
|
||||||
height = db.Column(db.Integer, nullable=False)
|
height = db.Column(db.Integer, nullable=False)
|
||||||
|
|
|
@ -20,6 +20,7 @@ def create_device(name, account_id, device_type=1):
|
||||||
device.save()
|
device.save()
|
||||||
device_association = DeviceAssociation(device.id, account_id)
|
device_association = DeviceAssociation(device.id, account_id)
|
||||||
device_association.save()
|
device_association.save()
|
||||||
|
return device
|
||||||
|
|
||||||
|
|
||||||
def create_device_type(name):
|
def create_device_type(name):
|
||||||
|
@ -33,6 +34,7 @@ def create_device_type(name):
|
||||||
"""
|
"""
|
||||||
device_type = DeviceType(name)
|
device_type = DeviceType(name)
|
||||||
device_type.save()
|
device_type.save()
|
||||||
|
return device_type
|
||||||
|
|
||||||
|
|
||||||
def set_device_configuration(device_id, configuration_json):
|
def set_device_configuration(device_id, configuration_json):
|
||||||
|
@ -50,6 +52,7 @@ def set_device_configuration(device_id, configuration_json):
|
||||||
device.configuration = configuration_json
|
device.configuration = configuration_json
|
||||||
device.save()
|
device.save()
|
||||||
send_config.delay(device_id, str(configuration_json))
|
send_config.delay(device_id, str(configuration_json))
|
||||||
|
return device
|
||||||
|
|
||||||
|
|
||||||
def get_device_configuration(device_id):
|
def get_device_configuration(device_id):
|
||||||
|
@ -173,17 +176,16 @@ def get_device_types():
|
||||||
return DeviceType.get_many()
|
return DeviceType.get_many()
|
||||||
|
|
||||||
|
|
||||||
def create_recording(device_id, raw_json):
|
def parse_raw_json_recording(device_id, json_msg):
|
||||||
"""
|
"""
|
||||||
Tries to create recording with given parameters. Raises error on failure
|
Parses raw json recording and creates Recrding object
|
||||||
|
|
||||||
:param device_id: Id of device
|
:param device_id: Id of device
|
||||||
:type device_id: int
|
:type device_id: int
|
||||||
:param raw_json: Raw json received
|
:param raw_json: Raw json received
|
||||||
:type raw_json: json
|
:type raw_json: json
|
||||||
:raises: ValueError if parsing fails or device does not exist
|
:raises: ValueError if parsing fails
|
||||||
"""
|
"""
|
||||||
def parse_raw_json_recording(device_id, json_msg):
|
|
||||||
try:
|
try:
|
||||||
return Recording(device_id=device_id,
|
return Recording(device_id=device_id,
|
||||||
record_type=json_msg["record_type"],
|
record_type=json_msg["record_type"],
|
||||||
|
@ -195,6 +197,36 @@ def create_recording(device_id, raw_json):
|
||||||
raise ValueError("JSON parsing failed! Key error: "
|
raise ValueError("JSON parsing failed! Key error: "
|
||||||
+ str(error_instance))
|
+ str(error_instance))
|
||||||
|
|
||||||
|
|
||||||
|
def create_recording_and_return(device_id, raw_json):
|
||||||
|
"""
|
||||||
|
Tries to create recording with given parameters and returns it.
|
||||||
|
Raises error on failure
|
||||||
|
|
||||||
|
:param device_id: Id of device
|
||||||
|
:type device_id: int
|
||||||
|
:param raw_json: Raw json received
|
||||||
|
:type raw_json: json
|
||||||
|
:raises: ValueError if parsing fails or device does not exist
|
||||||
|
"""
|
||||||
|
if not Device.exists(id=device_id):
|
||||||
|
raise ValueError("Device does not exist!")
|
||||||
|
|
||||||
|
recording = parse_raw_json_recording(device_id, raw_json)
|
||||||
|
recording.save()
|
||||||
|
return recording
|
||||||
|
|
||||||
|
|
||||||
|
def create_recording(device_id, raw_json):
|
||||||
|
"""
|
||||||
|
Tries to create recording with given parameters. Raises error on failure
|
||||||
|
|
||||||
|
:param device_id: Id of device
|
||||||
|
:type device_id: int
|
||||||
|
:param raw_json: Raw json received
|
||||||
|
:type raw_json: json
|
||||||
|
:raises: ValueError if parsing fails or device does not exist
|
||||||
|
"""
|
||||||
if not Device.exists(id=device_id):
|
if not Device.exists(id=device_id):
|
||||||
raise ValueError("Device does not exist!")
|
raise ValueError("Device does not exist!")
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from sqlalchemy.dialects.postgresql import JSON
|
||||||
class Recording(db.Model):
|
class Recording(db.Model):
|
||||||
__tablename__ = 'recordings'
|
__tablename__ = 'recordings'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
recorded_at = db.Column(db.DateTime, index=True,
|
recorded_at = db.Column(db.DateTime, index=True,
|
||||||
default=db.func.current_timestamp())
|
default=db.func.current_timestamp())
|
||||||
received_at = db.Column(db.DateTime, index=True,
|
received_at = db.Column(db.DateTime, index=True,
|
||||||
|
@ -115,7 +115,7 @@ class Recording(db.Model):
|
||||||
class Device(db.Model):
|
class Device(db.Model):
|
||||||
__tablename__ = 'devices'
|
__tablename__ = 'devices'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
created_at = db.Column(db.DateTime,
|
created_at = db.Column(db.DateTime,
|
||||||
nullable=False,
|
nullable=False,
|
||||||
default=db.func.current_timestamp())
|
default=db.func.current_timestamp())
|
||||||
|
@ -267,7 +267,7 @@ class DeviceAssociation(db.Model):
|
||||||
class DeviceType(db.Model):
|
class DeviceType(db.Model):
|
||||||
__tablename__ = 'device_types'
|
__tablename__ = 'device_types'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
@ -320,7 +320,7 @@ class DeviceType(db.Model):
|
||||||
class AccessLevel(db.Model):
|
class AccessLevel(db.Model):
|
||||||
__tablename__ = 'access_levels'
|
__tablename__ = 'access_levels'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
|
|
||||||
# App configuration
|
# App configuration
|
||||||
DEBUG = os.environ['DEBUG']
|
DEBUG = os.environ['DEBUG']
|
||||||
APP_VERSION = '0.3.1'
|
APP_VERSION = '0.3.2'
|
||||||
|
|
||||||
# Define the application directory
|
# Define the application directory
|
||||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
Loading…
Reference in New Issue