-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.py
68 lines (51 loc) · 1.64 KB
/
comment.py
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
from datetime import datetime
from marshmallow import Schema, fields, post_load, ValidationError, validates
class Admin(object):
def __init__(self, login, repo, origin=None):
self.login = login
self.repo = repo
self.origin = origin
class User(object):
def __init__(self, login, html_url=None, avatar_url=None):
self.login = login
self.html_url = html_url
self.avatar_url = avatar_url
class Comment(object):
def __init__(self, body, title=None, user=None, html_url=None,
created_at=datetime.now(), updated_at=datetime.now()):
self.title = title
self.body = body
self.user = user
self.html_url = html_url
self.created_at = created_at
self.updated_at = updated_at
class AdminSchema(Schema):
login = fields.Str(required=True)
repo = fields.Str(required=True)
origin = fields.URL()
@post_load
def make_admin(self, data):
return Admin(**data)
@validates('login')
def validate_github_login(self, value):
return True
@validates('repo')
def validate_repo(self, value):
return True
class UserSchema(Schema):
login = fields.Str(required=True)
html_url = fields.URL()
avatar_url = fields.URL()
@post_load
def make_user(self, data):
return User(**data)
class CommentSchema(Schema):
body = fields.Str(required=True)
title = fields.Str()
html_url = fields.URL()
created_at = fields.DateTime()
updated_at = fields.DateTime()
user = fields.Nested(UserSchema)
@post_load
def make_comment(self, data):
return Comment(**data)