summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/resources/project_models.py
blob: a8f8309323366b792e085b6743b1765ab1432191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from 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:
    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):
    """
        @ptype projects: C{list} of L{Project}
    """
    def __init__(self, projects=list()):
        self.projects = projects

    @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