Skip to content

Commit b98d42f

Browse files
Merge pull request #58 from chopdgd/pyup-scheduled-update-2018-10-29
Scheduled weekly dependency update for week 43
2 parents 2d257a4 + 1499022 commit b98d42f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

requirements_test.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
coverage==4.5.1
22
mock==2.0.0
3-
flake8==3.5.0
4-
tox==3.5.2
3+
flake8==3.6.0
4+
tox==3.5.3
55
codecov==2.0.15
66

77

88
# Additional test requirements go here
99

10-
pytest==3.9.1
10+
pytest==3.9.3
1111
pytest-cov==2.6.0
1212
pytest-django==3.4.3
1313
pytest-sugar==0.9.1

user_activities/managers.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ def fast(self):
99
return self.select_related('user').all()
1010

1111
def aggregate_counts(self, content_type, object_id, active=True):
12-
return self.fast().filter(
13-
Q(content_type=content_type) &
14-
Q(object_id=object_id) &
15-
Q(active=True)
16-
).values('activity_type').annotate(total=Count('activity_type'))
12+
counts_filter = Q(content_type=content_type)
13+
counts_filter &= Q(object_id=object_id)
14+
counts_filter &= Q(active=True)
15+
16+
return self.fast()\
17+
.filter(counts_filter) \
18+
.values('activity_type') \
19+
.annotate(total=Count('activity_type'))
1720

1821
def user_actions(self, user, content_type, object_id):
19-
return self.fast().filter(
20-
Q(user__id=user.id) &
21-
Q(content_type=content_type) &
22-
Q(object_id=object_id)
23-
).values('id', 'active', 'activity_type').distinct()
22+
actions_filter = Q(user__id=user.id)
23+
actions_filter &= Q(content_type=content_type)
24+
actions_filter &= Q(object_id=object_id)
25+
26+
return self.fast() \
27+
.filter(actions_filter) \
28+
.values('id', 'active', 'activity_type') \
29+
.distinct()
2430

2531

2632
class CommentQuerySet(models.QuerySet):

0 commit comments

Comments
 (0)