Add additional info to the module-build(s) API output

This commit is contained in:
Matt Prahl
2016-08-17 10:36:46 -04:00
committed by Nils Philippsen
parent 864ba5104e
commit c79139b82c
2 changed files with 32 additions and 8 deletions

View File

@@ -199,11 +199,41 @@ class ModuleBuild(RidaBase):
'state': self.state,
'state_name': INVERSE_BUILD_STATES[self.state],
'scmurl': self.scmurl,
'owner': self.owner,
'time_submitted': self.time_submitted,
'time_modified': self.time_modified,
'time_completed': self.time_completed,
# TODO, show their entire .json() ?
'component_builds': [build.id for build in self.component_builds],
}
@staticmethod
def _utc_datetime_to_iso(datetime_object):
"""
Takes a UTC datetime object and returns an ISO formatted string
:param datetime_object: datetime.datetime
:return: string with datetime in ISO format
"""
if datetime_object:
# Converts the datetime to ISO 8601
return datetime_object.strftime("%Y-%m-%dT%H:%M:%SZ")
return None
def api_json(self):
return {
"id": self.id,
"state": self.state,
"owner": self.owner,
"name": self.name,
"time_submitted": self._utc_datetime_to_iso(self.time_submitted),
"time_modified": self._utc_datetime_to_iso(self.time_modified),
"time_completed": self._utc_datetime_to_iso(self.time_completed),
"tasks": self.tasks()
}
def tasks(self):
"""
:return: dictionary containing the tasks associated with the build

View File

@@ -175,8 +175,7 @@ def query_builds():
}
if verbose_flag.lower() == 'true' or verbose_flag == '1':
json_data['items'] = [{'id': item.id, 'state': item.state, 'tasks': item.tasks()}
for item in p_query.items]
json_data['items'] = [item.api_json() for item in p_query.items]
else:
json_data['items'] = [{'id': item.id, 'state': item.state} for item in p_query.items]
@@ -189,11 +188,6 @@ def query_build(id):
module = models.ModuleBuild.query.filter_by(id=id).first()
if module:
return jsonify({
"id": module.id,
"state": module.state,
"tasks": module.tasks()
}), 200
return jsonify(module.api_json()), 200
else:
return "No such module found.", 404