##// END OF EJS Templates
events: remove attribute from schema, redundant
dan -
r390:36aef1e6 default
parent child Browse files
Show More
@@ -1,70 +1,70 b''
1 1 # Copyright (C) 2016-2016 RhodeCode GmbH
2 2 #
3 3 # This program is free software: you can redistribute it and/or modify
4 4 # it under the terms of the GNU Affero General Public License, version 3
5 5 # (only), as published by the Free Software Foundation.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU Affero General Public License
13 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 #
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 from datetime import datetime
20 20 from marshmallow import Schema, fields
21 21 from pyramid.threadlocal import get_current_request
22 22 from rhodecode.lib.utils2 import AttributeDict
23 23
24 24
25 25 SYSTEM_USER = AttributeDict(dict(
26 26 username='__SYSTEM__'
27 27 ))
28 28
29 29
30 30 class UserSchema(Schema):
31 31 """
32 32 Marshmallow schema for a user
33 33 """
34 34 username = fields.Str()
35 35
36 36
37 37 class RhodecodeEventSchema(Schema):
38 38 """
39 39 Marshmallow schema for a rhodecode event
40 40 """
41 41 utc_timestamp = fields.DateTime()
42 42 actor = fields.Nested(UserSchema)
43 43 actor_ip = fields.Str()
44 name = fields.Str(attribute='name')
44 name = fields.Str()
45 45
46 46
47 47 class RhodecodeEvent(object):
48 48 """
49 49 Base event class for all Rhodecode events
50 50 """
51 51 MarshmallowSchema = RhodecodeEventSchema
52 52
53 53 def __init__(self):
54 54 self.request = get_current_request()
55 55 self.utc_timestamp = datetime.utcnow()
56 56
57 57 @property
58 58 def actor(self):
59 59 if self.request:
60 60 return self.request.user.get_instance()
61 61 return SYSTEM_USER
62 62
63 63 @property
64 64 def actor_ip(self):
65 65 if self.request:
66 66 return self.request.user.ip_addr
67 67 return '<no ip available>'
68 68
69 69 def as_dict(self):
70 70 return self.MarshmallowSchema().dump(self).data No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now