summaryrefslogtreecommitdiff
path: root/opendc/api/v2/paths/pathId
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-24 09:13:09 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-06-24 09:13:09 +0200
commitbae760a62fc6a480fbe615dff6a7de03c7fd6d1d (patch)
tree06fc47f9922add14a3ac50fcfdfeb3d4fdc00363 /opendc/api/v2/paths/pathId
parent6fdb3e75dad15523d996e457c216647755b29101 (diff)
Add formatter
Diffstat (limited to 'opendc/api/v2/paths/pathId')
-rw-r--r--opendc/api/v2/paths/pathId/branches/endpoint.py47
-rw-r--r--opendc/api/v2/paths/pathId/endpoint.py14
-rw-r--r--opendc/api/v2/paths/pathId/sections/endpoint.py14
3 files changed, 19 insertions, 56 deletions
diff --git a/opendc/api/v2/paths/pathId/branches/endpoint.py b/opendc/api/v2/paths/pathId/branches/endpoint.py
index 13638ffa..5d3b6ec1 100644
--- a/opendc/api/v2/paths/pathId/branches/endpoint.py
+++ b/opendc/api/v2/paths/pathId/branches/endpoint.py
@@ -18,23 +18,14 @@ def POST(request):
# Make sure required parameters are there
try:
- request.check_required_parameters(
- path={
- 'pathId': 'int'
- },
- body={
- 'section': {
- 'startTick': 'int'
- }
- }
- )
+ request.check_required_parameters(path={'pathId': 'int'}, body={'section': {'startTick': 'int'}})
except exceptions.ParameterError as e:
return Response(400, e.message)
# Instantiate the current Path from the database
- current_path = Path.from_primary_key((request.params_path['pathId'],))
+ current_path = Path.from_primary_key((request.params_path['pathId'], ))
# Make sure the current Path exists
@@ -48,10 +39,8 @@ def POST(request):
# Create the new Path
- new_path = Path(
- simulation_id=current_path.simulation_id,
- datetime_created=database.datetime_to_string(datetime.now())
- )
+ new_path = Path(simulation_id=current_path.simulation_id,
+ datetime_created=database.datetime_to_string(datetime.now()))
new_path.insert()
@@ -63,11 +52,9 @@ def POST(request):
for current_section in current_sections:
if current_section.start_tick < request.params_body['section']['startTick'] or current_section.start_tick == 0:
- new_section = Section(
- path_id=new_path.id,
- datacenter_id=current_section.datacenter_id,
- start_tick=current_section.start_tick
- )
+ new_section = Section(path_id=new_path.id,
+ datacenter_id=current_section.datacenter_id,
+ start_tick=current_section.start_tick)
new_section.insert()
@@ -75,13 +62,11 @@ def POST(request):
# Make a deep copy of the last section's datacenter, its rooms, their tiles, etc.
- path_parameters = {
- 'simulationId': new_path.simulation_id
- }
+ path_parameters = {'simulationId': new_path.simulation_id}
# Copy the Datacenter
- old_datacenter = Datacenter.from_primary_key((last_section.datacenter_id,))
+ old_datacenter = Datacenter.from_primary_key((last_section.datacenter_id, ))
message = old_datacenter.generate_api_call(path_parameters, request.token)
response = Request(message).process()
@@ -91,11 +76,9 @@ def POST(request):
# Create the new last Section, with the IDs of the new Path and new Datacenter
if last_section.start_tick != 0:
- new_section = Section(
- path_id=new_path.id,
- datacenter_id=path_parameters['datacenterId'],
- start_tick=request.params_body['section']['startTick']
- )
+ new_section = Section(path_id=new_path.id,
+ datacenter_id=path_parameters['datacenterId'],
+ start_tick=request.params_body['section']['startTick'])
new_section.insert()
@@ -169,8 +152,4 @@ def POST(request):
# Return the new Path
- return Response(
- 200,
- 'Successfully created {}.'.format(new_path),
- new_path.to_JSON()
- )
+ return Response(200, 'Successfully created {}.'.format(new_path), new_path.to_JSON())
diff --git a/opendc/api/v2/paths/pathId/endpoint.py b/opendc/api/v2/paths/pathId/endpoint.py
index 7ade19ce..7a73ce17 100644
--- a/opendc/api/v2/paths/pathId/endpoint.py
+++ b/opendc/api/v2/paths/pathId/endpoint.py
@@ -9,18 +9,14 @@ def GET(request):
# Make sure required parameters are there
try:
- request.check_required_parameters(
- path={
- 'pathId': 'int'
- }
- )
+ request.check_required_parameters(path={'pathId': 'int'})
except exceptions.ParameterError as e:
return Response(400, e.message)
# Instantiate a Path from the database
- path = Path.from_primary_key((request.params_path['pathId'],))
+ path = Path.from_primary_key((request.params_path['pathId'], ))
# Make sure this Path exists
@@ -36,8 +32,4 @@ def GET(request):
path.read()
- return Response(
- 200,
- 'Successfully retrieved {}.'.format(path),
- path.to_JSON()
- )
+ return Response(200, 'Successfully retrieved {}.'.format(path), path.to_JSON())
diff --git a/opendc/api/v2/paths/pathId/sections/endpoint.py b/opendc/api/v2/paths/pathId/sections/endpoint.py
index d4161839..b8e4a861 100644
--- a/opendc/api/v2/paths/pathId/sections/endpoint.py
+++ b/opendc/api/v2/paths/pathId/sections/endpoint.py
@@ -10,17 +10,13 @@ def GET(request):
# Make sure required parameters are there
try:
- request.check_required_parameters(
- path={
- 'pathId': 'int'
- }
- )
+ request.check_required_parameters(path={'pathId': 'int'})
except exceptions.ParameterError as e:
return Response(400, e.message)
# Instantiate a Path from the database
- path = Path.from_primary_key((request.params_path['pathId'],))
+ path = Path.from_primary_key((request.params_path['pathId'], ))
# Make sure this Path exists
@@ -36,8 +32,4 @@ def GET(request):
sections = Section.query('path_id', request.params_path['pathId'])
- return Response(
- 200,
- 'Successfully retrieved Sections for {}.'.format(path),
- [x.to_JSON() for x in sections]
- )
+ return Response(200, 'Successfully retrieved Sections for {}.'.format(path), [x.to_JSON() for x in sections])