diff --git a/spirit/category/tests.py b/spirit/category/tests.py index e9ba762e4..ad1a1f70a 100644 --- a/spirit/category/tests.py +++ b/spirit/category/tests.py @@ -36,15 +36,11 @@ def test_category_detail_view(self): topic2 = utils.create_topic(category=self.subcategory_1) topic3 = utils.create_topic(category=self.category_1) - ( - Topic.objects.filter(pk=topic.pk).update( - last_active=timezone.now() - datetime.timedelta(days=10) - ) + Topic.objects.filter(pk=topic.pk).update( + last_active=timezone.now() - datetime.timedelta(days=10) ) - ( - Topic.objects.filter(pk=topic3.pk).update( - last_active=timezone.now() - datetime.timedelta(days=5) - ) + Topic.objects.filter(pk=topic3.pk).update( + last_active=timezone.now() - datetime.timedelta(days=5) ) response = self.client.get( @@ -63,10 +59,8 @@ def test_category_detail_view_order(self): topic_b = utils.create_topic(category=self.category_1) utils.create_topic(category=self.category_1, is_pinned=True, is_removed=True) # show pinned first - ( - Topic.objects.filter(pk=topic_a.pk).update( - last_active=timezone.now() - datetime.timedelta(days=10) - ) + Topic.objects.filter(pk=topic_a.pk).update( + last_active=timezone.now() - datetime.timedelta(days=10) ) response = self.client.get( @@ -87,10 +81,8 @@ def test_category_detail_view_pinned(self): topic_c = utils.create_topic(category=category) topic_d = utils.create_topic(category=category, is_globally_pinned=True) # show globally pinned first - ( - Topic.objects.filter(pk=topic_d.pk).update( - last_active=timezone.now() - datetime.timedelta(days=10) - ) + Topic.objects.filter(pk=topic_d.pk).update( + last_active=timezone.now() - datetime.timedelta(days=10) ) response = self.client.get( diff --git a/spirit/comment/models.py b/spirit/comment/models.py index d80737738..5de4089c1 100644 --- a/spirit/comment/models.py +++ b/spirit/comment/models.py @@ -55,20 +55,16 @@ def like(self): return def increase_modified_count(self): - ( - Comment.objects.filter(pk=self.pk).update( - modified_count=F("modified_count") + 1 - ) + Comment.objects.filter(pk=self.pk).update( + modified_count=F("modified_count") + 1 ) def increase_likes_count(self): - (Comment.objects.filter(pk=self.pk).update(likes_count=F("likes_count") + 1)) + Comment.objects.filter(pk=self.pk).update(likes_count=F("likes_count") + 1) def decrease_likes_count(self): - ( - Comment.objects.filter(pk=self.pk, likes_count__gt=0).update( - likes_count=F("likes_count") - 1 - ) + Comment.objects.filter(pk=self.pk, likes_count__gt=0).update( + likes_count=F("likes_count") - 1 ) @classmethod diff --git a/spirit/comment/poll/forms.py b/spirit/comment/poll/forms.py index 1f349ce4b..aa2d50f1b 100644 --- a/spirit/comment/poll/forms.py +++ b/spirit/comment/poll/forms.py @@ -74,10 +74,8 @@ def save_m2m(self): if not self.poll.is_multiple_choice: choices = [choices] - ( - CommentPollVote.objects.filter( - voter=self.user, choice__poll=self.poll - ).update(is_removed=True) + CommentPollVote.objects.filter(voter=self.user, choice__poll=self.poll).update( + is_removed=True ) for choice_id in choices: diff --git a/spirit/comment/poll/models.py b/spirit/comment/poll/models.py index f74995489..b8f166670 100644 --- a/spirit/comment/poll/models.py +++ b/spirit/comment/poll/models.py @@ -93,7 +93,7 @@ def total_votes(self): @classmethod def update_or_create_many(cls, comment, polls_raw): - (cls.objects.for_comment(comment).update(is_removed=True)) + cls.objects.for_comment(comment).update(is_removed=True) default_fields = ["title", "choice_min", "choice_max", "close_at", "mode"] @@ -148,23 +148,19 @@ def votes_percentage(self): @classmethod def increase_vote_count(cls, poll, voter): - ( - cls.objects.for_vote(poll=poll, voter=voter).update( - vote_count=F("vote_count") + 1 - ) + cls.objects.for_vote(poll=poll, voter=voter).update( + vote_count=F("vote_count") + 1 ) @classmethod def decrease_vote_count(cls, poll, voter): - ( - cls.objects.for_vote(poll=poll, voter=voter).update( - vote_count=F("vote_count") - 1 - ) + cls.objects.for_vote(poll=poll, voter=voter).update( + vote_count=F("vote_count") - 1 ) @classmethod def update_or_create_many(cls, comment, choices_raw): - (cls.objects.for_comment(comment).update(is_removed=True)) + cls.objects.for_comment(comment).update(is_removed=True) if not choices_raw: # Avoid the later transaction.atomic() return diff --git a/spirit/comment/poll/views.py b/spirit/comment/poll/views.py index 71f7ffdeb..c482b889b 100644 --- a/spirit/comment/poll/views.py +++ b/spirit/comment/poll/views.py @@ -26,7 +26,7 @@ def close_or_open(request, pk, close=True): else: close_at = None - (CommentPoll.objects.filter(pk=poll.pk).update(close_at=close_at)) + CommentPoll.objects.filter(pk=poll.pk).update(close_at=close_at) return safe_redirect(request, "next", poll.get_absolute_url()) diff --git a/spirit/comment/views.py b/spirit/comment/views.py index 4ec6c6977..3f0609121 100644 --- a/spirit/comment/views.py +++ b/spirit/comment/views.py @@ -76,7 +76,7 @@ def update(request, pk): def delete(request, pk, remove=True): comment = get_object_or_404(Comment, pk=pk) if is_post(request): - (Comment.objects.filter(pk=pk).update(is_removed=remove)) + Comment.objects.filter(pk=pk).update(is_removed=remove) return safe_redirect(request, "next", comment.get_absolute_url()) return render( request=request, diff --git a/spirit/core/utils/timezone.py b/spirit/core/utils/timezone.py index e9e8bd36d..a0286ab0f 100644 --- a/spirit/core/utils/timezone.py +++ b/spirit/core/utils/timezone.py @@ -96,6 +96,6 @@ def timezones(): for offset, time_zone in timezones_by_offset(): zone, pretty_time_zone = timezone_format(time_zone, offset) - (timezones_cache.setdefault(zone, []).append((time_zone, pretty_time_zone))) + timezones_cache.setdefault(zone, []).append((time_zone, pretty_time_zone)) return sorted(timezones_cache.items(), key=lambda x: x[0]) diff --git a/spirit/topic/models.py b/spirit/topic/models.py index 0bf7e6a7e..11093c95d 100644 --- a/spirit/topic/models.py +++ b/spirit/topic/models.py @@ -102,18 +102,16 @@ def is_visited(self): return bool(self.bookmark) def increase_view_count(self): - (Topic.objects.filter(pk=self.pk).update(view_count=F("view_count") + 1)) + Topic.objects.filter(pk=self.pk).update(view_count=F("view_count") + 1) def increase_comment_count(self): - ( - Topic.objects.filter(pk=self.pk).update( - comment_count=F("comment_count") + 1, last_active=timezone.now() - ) + Topic.objects.filter(pk=self.pk).update( + comment_count=F("comment_count") + 1, last_active=timezone.now() ) def decrease_comment_count(self): # todo: update last_active to last() comment - (Topic.objects.filter(pk=self.pk).update(comment_count=F("comment_count") - 1)) + Topic.objects.filter(pk=self.pk).update(comment_count=F("comment_count") - 1) def get_all_comments_html(self): """ diff --git a/spirit/topic/notification/models.py b/spirit/topic/notification/models.py index 6f5a8ed00..957aabb90 100644 --- a/spirit/topic/notification/models.py +++ b/spirit/topic/notification/models.py @@ -59,7 +59,7 @@ def mark_as_read(cls, user, topic): if not user.is_authenticated: return - (cls.objects.filter(user=user, topic=topic).update(is_read=True)) + cls.objects.filter(user=user, topic=topic).update(is_read=True) @classmethod def create_maybe(cls, user, comment, is_read=True, action=COMMENT): @@ -104,12 +104,10 @@ def notify_new_mentions(cls, comment, mentions): except IntegrityError: pass - ( - cls.objects.filter( - user__in=tuple(mentions.values()), topic=comment.topic, is_read=True - ).update( - comment=comment, is_read=False, action=cls.MENTION, date=timezone.now() - ) + cls.objects.filter( + user__in=tuple(mentions.values()), topic=comment.topic, is_read=True + ).update( + comment=comment, is_read=False, action=cls.MENTION, date=timezone.now() ) @classmethod @@ -143,14 +141,10 @@ def sync(cls, comment, topic): topic.comment_set.filter(date__gt=comment.date).order_by("date").first() ) if next_comment is None: - ( - cls.objects.filter(comment=comment, topic=topic).update( - is_read=True, action=cls.UNDEFINED - ) - ) - return - ( cls.objects.filter(comment=comment, topic=topic).update( - comment=next_comment, action=cls.COMMENT + is_read=True, action=cls.UNDEFINED ) + return + cls.objects.filter(comment=comment, topic=topic).update( + comment=next_comment, action=cls.COMMENT ) diff --git a/spirit/topic/notification/tests.py b/spirit/topic/notification/tests.py index 8c44cd76c..55e447523 100644 --- a/spirit/topic/notification/tests.py +++ b/spirit/topic/notification/tests.py @@ -275,10 +275,8 @@ def test_topic_notification_ajax_order(self): TopicNotification.objects.filter(user=self.user).update(is_read=True) old_date = timezone.now() - datetime.timedelta(days=10) - ( - TopicNotification.objects.filter(pk=self.topic_notification.pk).update( - is_read=False, date=old_date - ) + TopicNotification.objects.filter(pk=self.topic_notification.pk).update( + is_read=False, date=old_date ) utils.login(self) @@ -583,11 +581,7 @@ def test_topic_notification_create_maybe(self): self.assertEqual(notification.action, COMMENT) # Creating it again should do nothing - ( - TopicNotification.objects.filter(user=user, topic=topic).update( - is_active=False - ) - ) + TopicNotification.objects.filter(user=user, topic=topic).update(is_active=False) TopicNotification.create_maybe(user=user, comment=comment) self.assertFalse( TopicNotification.objects.get(user=user, topic=topic).is_active @@ -658,10 +652,8 @@ def test_topic_notification_notify_new_mentions_unactive(self): set is_read=False when user gets mentioned even if is_active=False """ - ( - TopicNotification.objects.filter(pk=self.topic_notification.pk).update( - is_active=False - ) + TopicNotification.objects.filter(pk=self.topic_notification.pk).update( + is_active=False ) mentions = {self.user.username: self.user} comment = utils.create_comment(topic=self.topic_notification.topic) diff --git a/spirit/topic/tests.py b/spirit/topic/tests.py index e3b03f2c2..a35a7fd00 100644 --- a/spirit/topic/tests.py +++ b/spirit/topic/tests.py @@ -344,15 +344,11 @@ def test_topic_active_view(self): topic_b = utils.create_topic(category=category, user=self.user, view_count=10) topic_c = utils.create_topic(category=category) - ( - Topic.objects.filter(pk=topic_a.pk).update( - last_active=timezone.now() - datetime.timedelta(days=10) - ) + Topic.objects.filter(pk=topic_a.pk).update( + last_active=timezone.now() - datetime.timedelta(days=10) ) - ( - Topic.objects.filter(pk=topic_c.pk).update( - last_active=timezone.now() - datetime.timedelta(days=5) - ) + Topic.objects.filter(pk=topic_c.pk).update( + last_active=timezone.now() - datetime.timedelta(days=5) ) response = self.client.get(reverse("spirit:topic:index-active")) @@ -369,10 +365,8 @@ def test_topic_active_view_pinned(self): topic_c = utils.create_topic(category=category) topic_d = utils.create_topic(category=category, is_globally_pinned=True) # show globally pinned first - ( - Topic.objects.filter(pk=topic_d.pk).update( - last_active=timezone.now() - datetime.timedelta(days=10) - ) + Topic.objects.filter(pk=topic_d.pk).update( + last_active=timezone.now() - datetime.timedelta(days=10) ) response = self.client.get(reverse("spirit:topic:index-active")) diff --git a/spirit/topic/unread/tests.py b/spirit/topic/unread/tests.py index 15482f1ce..8e2868b45 100644 --- a/spirit/topic/unread/tests.py +++ b/spirit/topic/unread/tests.py @@ -35,11 +35,9 @@ def test_topic_unread_list(self): """ topic unread list """ - ( - TopicUnread.objects.filter( - pk__in=[self.topic_unread.pk, self.topic_unread2.pk] - ).update(is_read=False) - ) + TopicUnread.objects.filter( + pk__in=[self.topic_unread.pk, self.topic_unread2.pk] + ).update(is_read=False) utils.login(self) response = self.client.get(reverse("spirit:topic:unread:index")) @@ -116,11 +114,9 @@ def test_topic_unread_list_bookmarks(self): """ topic unread list with bookmarks """ - ( - TopicUnread.objects.filter( - pk__in=[self.topic_unread.pk, self.topic_unread2.pk] - ).update(is_read=False) - ) + TopicUnread.objects.filter( + pk__in=[self.topic_unread.pk, self.topic_unread2.pk] + ).update(is_read=False) bookmark = CommentBookmark.objects.create(topic=self.topic2, user=self.user) utils.login(self) diff --git a/spirit/user/middleware.py b/spirit/user/middleware.py index 5b58f8671..e3432f8d3 100644 --- a/spirit/user/middleware.py +++ b/spirit/user/middleware.py @@ -41,7 +41,7 @@ def process_request(self, request): if request.user.st.last_ip == last_ip: return - (UserProfile.objects.filter(user__pk=request.user.pk).update(last_ip=last_ip)) + UserProfile.objects.filter(user__pk=request.user.pk).update(last_ip=last_ip) class LastSeenMiddleware(MiddlewareMixin): @@ -55,10 +55,8 @@ def process_request(self, request): if delta.total_seconds() < threshold: return - ( - UserProfile.objects.filter(pk=request.user.st.pk).update( - last_seen=timezone.now() - ) + UserProfile.objects.filter(pk=request.user.st.pk).update( + last_seen=timezone.now() ) diff --git a/spirit/user/signals.py b/spirit/user/signals.py index 340a4ebb3..2416ac827 100644 --- a/spirit/user/signals.py +++ b/spirit/user/signals.py @@ -29,7 +29,7 @@ def update_or_create_user_profile(sender, instance, created, **kwargs): def lower_username(sender, instance, created, **kwargs): user = instance if created and settings.ST_CASE_INSENSITIVE_USERNAMES: - (User.objects.filter(pk=user.pk).update(username=user.username.lower())) + User.objects.filter(pk=user.pk).update(username=user.username.lower()) user.username = user.username.lower()