API for listing current projects

Fix #274
This commit is contained in:
Julien Duponchelle committed 2015-07-24 10:09:16 +02:00
1 parent cbe593f4a4
commit d9f1a7c7d3
4 files changed
+47 -1

No files matched your search

+16 -1
View File
@@ -21,7 +21,7 @@ import json
import os
from ...web.route import Route
from ...schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA, PROJECT_FILE_LIST_SCHEMA
from ...schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA, PROJECT_FILE_LIST_SCHEMA, PROJECT_LIST_SCHEMA
from ...modules.project_manager import ProjectManager
from ...modules import MODULES
from ...utils.asyncio import wait_run_in_executor
@@ -35,6 +35,21 @@ class ProjectHandler:
# How many clients has subcribe to notifications
_notifications_listening = 0
@classmethod
@Route.get(
r"/projects",
description="List projects opened on the server",
status_codes={
200: "Project list",
}
# output=PROJECT_LIST_SCHEMA)
)
def list_projects(request, response):
pm = ProjectManager.instance()
response.set_status(200)
response.json(list(pm.projects))
@classmethod
@Route.post(
r"/projects",
+7
View File
@@ -104,6 +104,13 @@ PROJECT_OBJECT_SCHEMA = {
"required": ["location", "project_id", "temporary"]
}
PROJECT_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "List of projects",
"type": "array",
"items": PROJECT_OBJECT_SCHEMA
}
PROJECT_FILE_LIST_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "List files in the project",
+7
View File
@@ -87,6 +87,13 @@ class Response(aiohttp.web.Response):
self.content_type = "application/json"
if hasattr(answer, '__json__'):
answer = answer.__json__()
elif isinstance(answer, list):
newanswer = []
for elem in answer:
if hasattr(elem, '__json__'):
elem = elem.__json__()
newanswer.append(elem)
answer = newanswer
if self._output_schema is not None:
try:
jsonschema.validate(answer, self._output_schema)