Skip to content

Commit

Permalink
Merge pull request #1279 from chris34/pyupgrade
Browse files Browse the repository at this point in the history
Run Pyupgrade  & Update requirements
  • Loading branch information
chris34 authored Nov 1, 2023
2 parents 61de5e7 + a57b635 commit e552f50
Show file tree
Hide file tree
Showing 252 changed files with 615 additions and 1,044 deletions.
1 change: 0 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Inyoka Changelog
🔒 Security
-----------


0.30.0 (2023-10-22)
===================

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys
import datetime
import django
Expand Down
255 changes: 130 additions & 125 deletions extra/requirements/linux-py3.9-development.txt

Large diffs are not rendered by default.

231 changes: 118 additions & 113 deletions extra/requirements/linux-py3.9-production.txt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion inyoka/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka
~~~~~~
Expand Down
1 change: 0 additions & 1 deletion inyoka/default_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.default_settings
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion inyoka/forum/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum
~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion inyoka/forum/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.apps import AppConfig


Expand Down
1 change: 0 additions & 1 deletion inyoka/forum/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.constants
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
9 changes: 4 additions & 5 deletions inyoka/forum/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.forms
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -30,7 +29,7 @@ class ForumField(forms.ChoiceField):
"""
def __init__(self, user, *args, **kwargs):
self.user = user
super(ForumField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.set_forum_choices()

def set_forum_choices(self, privilege='forum.view_forum'):
Expand Down Expand Up @@ -85,7 +84,7 @@ class EditPostForm(SurgeProtectionMixin, forms.Form):
def __init__(self, is_first_post, needs_spam_check, request, *args, **kwargs):
self.needs_spam_check = needs_spam_check
self.request = request
super(EditPostForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['ubuntu_version'].choices = get_version_choices()
self.fields['ubuntu_distro'].choices = get_distro_choices()
if not is_first_post:
Expand Down Expand Up @@ -131,7 +130,7 @@ def __init__(self, force_version, needs_spam_check, request, *args, **kwargs):
self.force_version = force_version
self.needs_spam_check = needs_spam_check
self.request = request
super(NewTopicForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['ubuntu_version'].choices = get_version_choices()
self.fields['ubuntu_distro'].choices = get_distro_choices(True)

Expand Down Expand Up @@ -164,7 +163,7 @@ class MoveTopicForm(forms.Form):
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
self.current_forum = kwargs.pop('current_forum')
super(MoveTopicForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['forum'] = ForumField(user=user)

def clean_forum(self):
Expand Down
1 change: 0 additions & 1 deletion inyoka/forum/macros.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.macros
~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import datetime

from django.db import migrations, models
Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0002_auto_20151016_1603.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0003_remove_post_rendered_text_old.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations


Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0005_auto_20151030_2009.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations


Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0006_forum_support_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0007_auto_20151221_1103.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.conf import settings
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0008_auto_20151225_1754.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0009_auto_20160106_1132.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0010_auto_20160106_1247.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0011_auto_20160702_1801.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models
import django.db.models.deletion

Expand Down
3 changes: 0 additions & 3 deletions inyoka/forum/migrations/0012_django_permissions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models


Expand Down
1 change: 0 additions & 1 deletion inyoka/forum/migrations/0013_auto_20190415_0016.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2019-04-15 00:16


Expand Down
2 changes: 0 additions & 2 deletions inyoka/forum/migrations/0014_auto_20191027_1814.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2019-10-27 18:14
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
32 changes: 15 additions & 17 deletions inyoka/forum/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.models
~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -140,12 +139,12 @@ def get_cached(self, slug=None):
if slug:
# we only select one forum and query only one if it's
# not cached yet.
forum = cache.get('forum/forums/{}'.format(slug))
forum = cache.get(f'forum/forums/{slug}')
if forum is None:
forum = super(ForumManager, self).get(slug=slug)
forum = super().get(slug=slug)
if forum:
forum.__dict__.pop('last_post', None)
cache.set('forum/forums/{}'.format(slug), forum, 300)
cache.set(f'forum/forums/{slug}', forum, 300)
return forum
# return all forums instead
return list(self.get_all_forums_cached().values())
Expand Down Expand Up @@ -471,7 +470,7 @@ def clear_welcome(self):

def invalidate_topic_cache(self):
cache.delete_many(
'forum/topics/{}/{}'.format(self.id, page + 1)
f'forum/topics/{self.id}/{page + 1}'
for page in range(CACHE_PAGES_COUNT))

@staticmethod
Expand All @@ -490,8 +489,7 @@ def get_children_recursive(forums, parent=None, offset=0):
matched_forums = [f for f in forums if f.parent_id == parent]
for f in matched_forums:
yield offset, f
for l in Forum.get_children_recursive(forums, f, offset + 1):
yield l
yield from Forum.get_children_recursive(forums, f, offset + 1)

def get_supporters(self):
if self.support_group is None:
Expand Down Expand Up @@ -521,7 +519,7 @@ def post_count(self):
pass
forums = self.descendants + [self]
self._post_count_query_counter = QueryCounter(
cache_key="forum_post_count:{}".format(self.id),
cache_key=f"forum_post_count:{self.id}",
query=Post.objects.filter(topic__forum__in=forums),
use_task=False)
return self._post_count_query_counter
Expand All @@ -541,7 +539,7 @@ def topic_count(self):
pass

self._topic_count_query_counter = QueryCounter(
cache_key="forum_topic_count:{}".format(self.id),
cache_key=f"forum_topic_count:{self.id}",
query=self.topics.all(),
use_task=False)
return self._topic_count_query_counter
Expand Down Expand Up @@ -665,7 +663,7 @@ def delete(self, *args, **kwargs):
# remove wiki page discussions and clear caches
WikiPage.objects.clear_topic(self)

return super(Topic, self).delete(*args, **kwargs)
return super().delete(*args, **kwargs)

def get_absolute_url(self, action='show', **query):
if action in ('show',):
Expand Down Expand Up @@ -744,7 +742,7 @@ def mark_read(self, user):
@property
def post_count(self):
return QueryCounter(
cache_key="topic_post_count:{}".format(self.id),
cache_key=f"topic_post_count:{self.id}",
query=self.posts.all(),
use_task=False)

Expand Down Expand Up @@ -792,7 +790,7 @@ def last_post_map(self, ids):
last_posts = query.filter(id__in=ids) \
.select_related('author') \
.only('id', 'pub_date', 'author__username').all()
last_post_map = dict([(post.id, post) for post in last_posts])
last_post_map = {post.id: post for post in last_posts}
return last_post_map


Expand Down Expand Up @@ -888,7 +886,7 @@ def delete(self, *args, **kwargs):
attachment.delete()

if not self.topic:
return super(Post, self).delete()
return super().delete()

# degrade user post count
if self.topic.forum.user_count_posts and not self.hidden:
Expand Down Expand Up @@ -921,9 +919,9 @@ def delete(self, *args, **kwargs):
# django_redis has a bug, that delete_many does not work with
# empty generators. See:
# https://github.com/niwinz/django-redis/pull/162
cache.delete_many('forum/forums/{}'.format(f.slug) for f in parent_forums)
cache.delete_many(f'forum/forums/{f.slug}' for f in parent_forums)

return super(Post, self).delete()
return super().delete()

def hide(self, change_post_counter=True):
if change_post_counter:
Expand Down Expand Up @@ -1218,7 +1216,7 @@ def delete(self):
if thumb_path and path.exists(thumb_path):
os.remove(thumb_path)
self.file.delete(save=False)
super(Attachment, self).delete()
super().delete()

@staticmethod
def update_post_ids(att_ids, post):
Expand Down Expand Up @@ -1402,7 +1400,7 @@ def can_vote(self):
return not self.ended and not self.participated


class ReadStatus(object):
class ReadStatus:
"""
Manages the read status of forums and topics for a specific user.
"""
Expand Down
5 changes: 2 additions & 3 deletions inyoka/forum/notifications.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.notifications
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -178,15 +177,15 @@ def send_notification_for_topics(request_user_id, template, template_args, subje
}
notified_users = queue_notifications(filter=topic_subscribers, **notification_args)

logger.debug('Notified for template {}: {}'.format(template, notified_users))
logger.debug(f'Notified for template {template}: {notified_users}')

if include_forums:
forum_subscribers = {
'content_type_id': ctype(Forum).pk,
'object_id__in': forum_ids
}
notified_users = queue_notifications(filter=forum_subscribers, exclude={'user_id__in': notified_users}, **notification_args)
logger.debug('Notified for include_forums with template {}: {}'.format(template, notified_users))
logger.debug(f'Notified for include_forums with template {template}: {notified_users}')


def notify_reported_topic_subscribers(subject, args):
Expand Down
1 change: 0 additions & 1 deletion inyoka/forum/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.services
~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions inyoka/forum/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.signals
~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -104,5 +103,5 @@ def post_save_post(sender, instance, created, raw, **kwargs):

# Invalidate Cache
instance.topic.forum.invalidate_topic_cache()
cache_keys = ['forum/forums/{}'.format(forum.slug) for forum in parent_forums]
cache_keys = [f'forum/forums/{forum.slug}' for forum in parent_forums]
cache.delete_many(cache_keys)
1 change: 0 additions & 1 deletion inyoka/forum/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.urls
~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 3 additions & 4 deletions inyoka/forum/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.forum.views
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1015,7 +1014,7 @@ def _add_field_choices():

def reported_topics_subscription(request, mode):
subscribers = storage['reported_topics_subscribers'] or ''
users = set(int(i) for i in subscribers.split(',') if i)
users = {int(i) for i in subscribers.split(',') if i}

if mode == 'subscribe':
if not request.user.has_perm('forum.manage_reported_topic'):
Expand Down Expand Up @@ -1761,7 +1760,7 @@ def dispatch(self, *args, **kwargs):
self.object = self.get_object()
if not self.object.welcome_title:
raise Http404()
return super(WelcomeMessageView, self).dispatch(*args, **kwargs)
return super().dispatch(*args, **kwargs)

def post(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -1813,7 +1812,7 @@ class ForumEditMixin(PermissionRequiredMixin):
def form_valid(self, form):
if self.object and ('welcome_title' in form.changed_data or 'welcome_text' in form.changed_data):
self.object.clear_welcome()
return super(ForumEditMixin, self).form_valid(form)
return super().form_valid(form)


class ForumCreateView(ForumEditMixin, CreateView):
Expand Down
1 change: 0 additions & 1 deletion inyoka/hosts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.hosts
~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion inyoka/ikhaya/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
inyoka.ikhaya
~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion inyoka/ikhaya/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.apps import AppConfig


Expand Down
Loading

0 comments on commit e552f50

Please sign in to comment.