Skip to content

Commit 37744a0

Browse files
committed
Documents refactored
1 parent 1cd9352 commit 37744a0

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

activities/documents.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ class Activity(Document):
2525
user_id = IntField()
2626

2727

28-
class Like(Activity):
29-
config_polymorphic_identity = 'like'
30-
28+
class PerformerAware(Document):
3129
performed_by = StringField()
3230
performer_avatar = StringField(allow_none=True)
31+
32+
33+
class PostAware(Document):
3334
post_id = IntField()
3435
post_image = StringField()
3536

37+
38+
class Like(Activity, PerformerAware, PostAware):
39+
config_polymorphic_identity = 'like'
40+
3641
def to_dict(self):
3742
return {
3843
'id': str(self.mongo_id),
@@ -46,14 +51,9 @@ def to_dict(self):
4651
}
4752

4853

49-
class Comment(Activity):
54+
class Comment(Activity, PerformerAware, PostAware):
5055
config_polymorphic_identity = 'comment'
5156

52-
performed_by = StringField()
53-
performer_avatar = StringField(allow_none=True)
54-
post_id = IntField()
55-
post_image = StringField()
56-
5757
def to_dict(self):
5858
return {
5959
'id': str(self.mongo_id),
@@ -67,14 +67,9 @@ def to_dict(self):
6767
}
6868

6969

70-
class Repost(Activity):
70+
class Repost(Activity, PerformerAware, PostAware):
7171
config_polymorphic_identity = 'repost'
7272

73-
performed_by = StringField()
74-
performer_avatar = StringField(allow_none=True)
75-
post_id = IntField()
76-
post_image = StringField()
77-
7873
def to_dict(self):
7974
return {
8075
'id': str(self.mongo_id),
@@ -88,12 +83,9 @@ def to_dict(self):
8883
}
8984

9085

91-
class Follow(Activity):
86+
class Follow(Activity, PerformerAware):
9287
config_polymorphic_identity = 'follow'
9388

94-
performed_by = StringField()
95-
performer_avatar = StringField(allow_none=True)
96-
9789
def to_dict(self):
9890
return {
9991
'id': str(self.mongo_id),
@@ -105,14 +97,9 @@ def to_dict(self):
10597
}
10698

10799

108-
class Mention(Activity):
100+
class Mention(Activity, PerformerAware, PostAware):
109101
config_polymorphic_identity = 'mention'
110102

111-
performed_by = StringField()
112-
performer_avatar = StringField(allow_none=True)
113-
post_id = IntField()
114-
post_image = StringField()
115-
116103
def to_dict(self):
117104
return {
118105
'id': str(self.mongo_id),
@@ -126,13 +113,11 @@ def to_dict(self):
126113
}
127114

128115

129-
class Badge(Activity):
116+
class Badge(Activity, PostAware):
130117
config_polymorphic_identity = 'badge'
131118

132119
badge_name = StringField()
133120
badge_image = StringField()
134-
post_id = IntField()
135-
post_image = StringField()
136121

137122
def to_dict(self):
138123
return {

0 commit comments

Comments
 (0)