diff options
Diffstat (limited to 'result_collection_api/opnfv_testapi/resources/project_models.py')
-rw-r--r-- | result_collection_api/opnfv_testapi/resources/project_models.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/result_collection_api/opnfv_testapi/resources/project_models.py b/result_collection_api/opnfv_testapi/resources/project_models.py new file mode 100644 index 0000000..fbb6beb --- /dev/null +++ b/result_collection_api/opnfv_testapi/resources/project_models.py @@ -0,0 +1,88 @@ +from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger + +__author__ = '__serena__' + + +@swagger.model() +class ProjectCreateRequest(object): + def __init__(self, name, description=''): + self.name = name + self.description = description + + def format(self): + return { + "name": self.name, + "description": self.description, + } + + +@swagger.model() +class ProjectUpdateRequest(object): + def __init__(self, name='', description=''): + self.name = name + self.description = description + + def format(self): + return { + "name": self.name, + "description": self.description, + } + + +@swagger.model() +class Project(object): + def __init__(self, + name=None, _id=None, description=None, create_date=None): + self._id = _id + self.name = name + self.description = description + self.creation_date = create_date + + @staticmethod + def from_dict(res_dict): + + if res_dict is None: + return None + + t = Project() + t._id = res_dict.get('_id') + t.creation_date = res_dict.get('creation_date') + t.name = res_dict.get('name') + t.description = res_dict.get('description') + + return t + + def format(self): + return { + "name": self.name, + "description": self.description, + "creation_date": str(self.creation_date) + } + + def format_http(self): + return { + "_id": str(self._id), + "name": self.name, + "description": self.description, + "creation_date": str(self.creation_date), + } + + +@swagger.model() +class Projects(object): + """ + @property projects: + @ptype projects: C{list} of L{Project} + """ + def __init__(self): + self.projects = list() + + @staticmethod + def from_dict(res_dict): + if res_dict is None: + return None + + res = Projects() + for project in res_dict.get('projects'): + res.projects.append(Project.from_dict(project)) + return res |