Skip to content

Commit

Permalink
Format parens (#347)
Browse files Browse the repository at this point in the history
Remove some unnecessary parens generated by ruff format
  • Loading branch information
nitely authored Feb 25, 2025
1 parent f3c5ba5 commit ac85548
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 104 deletions.
24 changes: 8 additions & 16 deletions spirit/category/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
14 changes: 5 additions & 9 deletions spirit/comment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions spirit/comment/poll/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 6 additions & 10 deletions spirit/comment/poll/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spirit/comment/poll/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion spirit/comment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spirit/core/utils/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
10 changes: 4 additions & 6 deletions spirit/topic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
24 changes: 9 additions & 15 deletions spirit/topic/notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
18 changes: 5 additions & 13 deletions spirit/topic/notification/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions spirit/topic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down
16 changes: 6 additions & 10 deletions spirit/topic/unread/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions spirit/user/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
)


Expand Down
2 changes: 1 addition & 1 deletion spirit/user/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit ac85548

Please sign in to comment.