f70630cda102862e51f6cc74baafa0df63c24f48
[releng.git] / utils / test / result_collection_api / opnfv_testapi / resources / project_models.py
1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from opnfv_testapi.tornado_swagger import swagger
10
11
12 @swagger.model()
13 class ProjectCreateRequest(object):
14     def __init__(self, name, description=''):
15         self.name = name
16         self.description = description
17
18     def format(self):
19         return {
20             "name": self.name,
21             "description": self.description,
22         }
23
24
25 @swagger.model()
26 class ProjectUpdateRequest(object):
27     def __init__(self, name='', description=''):
28         self.name = name
29         self.description = description
30
31     def format(self):
32         return {
33             "name": self.name,
34             "description": self.description,
35         }
36
37
38 @swagger.model()
39 class Project(object):
40     def __init__(self,
41                  name=None, _id=None, description=None, create_date=None):
42         self._id = _id
43         self.name = name
44         self.description = description
45         self.creation_date = create_date
46
47     @staticmethod
48     def from_dict(res_dict):
49
50         if res_dict is None:
51             return None
52
53         t = Project()
54         t._id = res_dict.get('_id')
55         t.creation_date = res_dict.get('creation_date')
56         t.name = res_dict.get('name')
57         t.description = res_dict.get('description')
58
59         return t
60
61     def format(self):
62         return {
63             "name": self.name,
64             "description": self.description,
65             "creation_date": str(self.creation_date)
66         }
67
68     def format_http(self):
69         return {
70             "_id": str(self._id),
71             "name": self.name,
72             "description": self.description,
73             "creation_date": str(self.creation_date),
74         }
75
76
77 @swagger.model()
78 class Projects(object):
79     """
80         @property projects:
81         @ptype projects: C{list} of L{Project}
82     """
83     def __init__(self):
84         self.projects = list()
85
86     @staticmethod
87     def from_dict(res_dict):
88         if res_dict is None:
89             return None
90
91         res = Projects()
92         for project in res_dict.get('projects'):
93             res.projects.append(Project.from_dict(project))
94         return res