ruff rules UP008 and UP009

This commit is contained in:
thomas girod
2024-06-27 14:46:43 +02:00
parent 688871a680
commit cfc19434d0
258 changed files with 473 additions and 824 deletions

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2017
# - Skia <skia@libskia.so>

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2018
# - Skia <skia@libskia.so>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright 2019
# - Sli <antoine@bartuccio.fr>
@ -41,4 +40,4 @@ class Command(compilemessages.Command):
def handle(self, *args, **options):
os.chdir("sith")
super(Command, self).handle(*args, **options)
super().handle(*args, **options)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright 2017
# - Sli <antoine@bartuccio.fr>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright 2019
# - Sli <antoine@bartuccio.fr>

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2024 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2017
# - Skia <skia@libskia.so>

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017,2023
# - Skia <skia@hya.sk>

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2018
# - Skia <skia@libskia.so>

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
@ -51,13 +50,11 @@ class SithRenderer(Renderer):
if not width.endswith("%"):
width += "px"
style = "width: %s; " % width
try:
height = m.group(3)
height = m.group(3)
if height is not None:
if not height.endswith("%"):
height += "px"
style += "height: %s; " % height
except:
pass
else:
params = None
src = original_src
@ -163,7 +160,7 @@ class SithInlineLexer(InlineLexer):
link = reverse("core:file_detail", kwargs={"file_id": id}) + suffix
except:
pass
return super(SithInlineLexer, self)._process_link(m, link, title)
return super()._process_link(m, link, title)
renderer = SithRenderer(escape=True)

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.contrib.auth.models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.core.validators

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.utils.timezone

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.core.validators

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.core.validators

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.db.models.deletion

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-04 13:00
from __future__ import unicode_literals

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.24 on 2019-09-06 14:15
from __future__ import unicode_literals

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.24 on 2019-09-08 22:43
from __future__ import unicode_literals

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017,2018
# - Skia <skia@libskia.so>
@ -60,12 +59,12 @@ from core import utils
class RealGroupManager(AuthGroupManager):
def get_queryset(self):
return super(RealGroupManager, self).get_queryset().filter(is_meta=False)
return super().get_queryset().filter(is_meta=False)
class MetaGroupManager(AuthGroupManager):
def get_queryset(self):
return super(MetaGroupManager, self).get_queryset().filter(is_meta=True)
return super().get_queryset().filter(is_meta=True)
class Group(AuthGroup):
@ -120,7 +119,7 @@ class MetaGroup(Group):
proxy = True
def __init__(self, *args, **kwargs):
super(MetaGroup, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.is_meta = True
@cached_property
@ -548,7 +547,7 @@ class User(AbstractBaseUser):
self._change_username(self.username)
else:
create = True
super(User, self).save(*args, **kwargs)
super().save(*args, **kwargs)
def make_home(self):
if self.home is None:
@ -746,7 +745,7 @@ class User(AbstractBaseUser):
class AnonymousUser(AuthAnonymousUser):
def __init__(self):
super(AnonymousUser, self).__init__()
super().__init__()
@property
def can_create_subscription(self):
@ -987,13 +986,13 @@ class SithFile(models.Model):
self.compressed.delete()
if self.thumbnail:
self.thumbnail.delete()
return super(SithFile, self).delete()
return super().delete()
def clean(self):
"""
Cleans up the file
"""
super(SithFile, self).clean()
super().clean()
if "/" in self.name:
raise ValidationError(_("Character '/' not authorized in name"))
if self == self.parent:
@ -1040,7 +1039,7 @@ class SithFile(models.Model):
copy_rights = False
if self.id is None:
copy_rights = True
super(SithFile, self).save(*args, **kwargs)
super().save(*args, **kwargs)
if copy_rights:
self.copy_rights()
if self.is_in_sas:
@ -1156,7 +1155,7 @@ class SithFile(models.Model):
if attr == "is_file":
return not self.is_folder
else:
return super(SithFile, self).__getattribute__(attr)
return super().__getattribute__(attr)
@cached_property
def as_picture(self):
@ -1295,7 +1294,7 @@ class Page(models.Model):
return Page.objects.filter(_full_name=name).first()
def __init__(self, *args, **kwargs):
super(Page, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
def clean(self):
"""
@ -1309,7 +1308,7 @@ class Page(models.Model):
.exists()
):
raise ValidationError(_("Duplicate page"), code="duplicate")
super(Page, self).clean()
super().clean()
if self.parent is not None and self in self.get_parent_list():
raise ValidationError(_("Loop in page tree"), code="loop")
@ -1345,7 +1344,7 @@ class Page(models.Model):
raise NotLocked("The page is not locked and thus can not be saved")
self.full_clean()
if not self.id:
super(Page, self).save(
super().save(
*args, **kwargs
) # Save a first time to correctly set _full_name
# This reset the _full_name just before saving to maintain a coherent field quicker for queries than the
@ -1354,7 +1353,7 @@ class Page(models.Model):
self._full_name = self.get_full_name()
for c in self.children.all():
c.save()
super(Page, self).save(*args, **kwargs)
super().save(*args, **kwargs)
self.unset_lock()
def is_locked(self):
@ -1382,7 +1381,7 @@ class Page(models.Model):
raise AlreadyLocked("The page is already locked by someone else")
self.lock_user = user
self.lock_timeout = timezone.now()
super(Page, self).save()
super().save()
# print("Locking page")
def set_lock_recursive(self, user):
@ -1405,7 +1404,7 @@ class Page(models.Model):
"""Always try to unlock, even if there is no lock"""
self.lock_user = None
self.lock_timeout = None
super(Page, self).save()
super().save()
# print("Unlocking page")
def get_lock(self):
@ -1459,7 +1458,7 @@ class Page(models.Model):
child.parent = self.parent
child.save()
child.unset_lock_recursive()
super(Page, self).delete()
super().delete()
class PageRev(models.Model):
@ -1508,7 +1507,7 @@ class PageRev(models.Model):
def save(self, *args, **kwargs):
if self.revision is None:
self.revision = self.page.revisions.all().count() + 1
super(PageRev, self).save(*args, **kwargs)
super().save(*args, **kwargs)
# Don't forget to unlock, otherwise, people will have to wait for the page's timeout
self.page.unset_lock()
@ -1546,7 +1545,7 @@ class Notification(models.Model):
old_notif.callback()
old_notif.save()
return
super(Notification, self).save(*args, **kwargs)
super().save(*args, **kwargs)
class Gift(models.Model):

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Sli <antoine@bartuccio.fr>
@ -47,4 +46,4 @@ class PsqlRunOnly(migrations.RunSQL):
def _run_sql(self, schema_editor, sqls):
if connection.vendor == "postgresql":
super(PsqlRunOnly, self)._run_sql(schema_editor, sqls)
super()._run_sql(schema_editor, sqls)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Sli <antoine@bartuccio.fr>
@ -50,5 +49,5 @@ class ScssFinder(FileSystemFinder):
def find(self, path, all=False): # noqa A002 (shadows the builtin `all` function)
if path.endswith(".css"):
return super(ScssFinder, self).find(path, all)
return super().find(path, all)
return []

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright 2017
# - Sli <antoine@bartuccio.fr>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Copyright 2017
# - Sli <antoine@bartuccio.fr>
@ -34,7 +33,7 @@ class ScssFileStorage(FileSystemStorage):
location = settings.STATIC_ROOT
if base_url is None:
base_url = settings.STATIC_URL
super(ScssFileStorage, self).__init__(location, base_url, *args, **kwargs)
super().__init__(location, base_url, *args, **kwargs)
def find_file(path):

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
@ -85,14 +84,10 @@ class IndexSignalProcessor(signals.BaseSignalProcessor):
)
def handle_forum_message_meta_save(self, sender, instance, **kwargs):
super(IndexSignalProcessor, self).handle_save(
ForumMessage, instance.message, **kwargs
)
super().handle_save(ForumMessage, instance.message, **kwargs)
def handle_forum_message_meta_delete(self, sender, instance, **kwargs):
super(IndexSignalProcessor, self).handle_delete(
ForumMessage, instance.message, **kwargs
)
super().handle_delete(ForumMessage, instance.message, **kwargs)
class BigCharFieldIndex(indexes.CharField):
@ -102,9 +97,9 @@ class BigCharFieldIndex(indexes.CharField):
"""
def prepare(self, term):
return bytes(super(BigCharFieldIndex, self).prepare(term), "utf-8")[
:245
].decode("utf-8", errors="ignore")
return bytes(super().prepare(term), "utf-8")[:245].decode(
"utf-8", errors="ignore"
)
class ForumMessageIndex(indexes.SearchIndex, indexes.Indexable):

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
@ -44,7 +43,9 @@ def markdown(text):
@register.filter(name="phonenumber")
def phonenumber(value, country="FR", number_format=phonenumbers.PhoneNumberFormat.NATIONAL):
def phonenumber(
value, country="FR", number_format=phonenumbers.PhoneNumberFormat.NATIONAL
):
"""
This filter is kindly borrowed from https://github.com/foundertherapy/django-phonenumber-filter
"""

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
@ -44,26 +43,10 @@ from core.views.forms import LoginForm
def forbidden(request, exception):
try:
return HttpResponseForbidden(
render(
request,
"core/403.jinja",
context={
"next": request.path,
"form": LoginForm(),
"popup": request.resolver_match.kwargs["popup"] or "",
},
)
)
except:
return HttpResponseForbidden(
render(
request,
"core/403.jinja",
context={"next": request.path, "form": LoginForm()},
)
)
context = {"next": request.path, "form": LoginForm()}
if popup := request.resolver_match.kwargs.get("popup"):
context["popup"] = popup
return HttpResponseForbidden(render(request, "core/403.jinja", context=context))
def not_found(request, exception):
@ -161,9 +144,7 @@ class GenericContentPermissionMixinBuilder(View):
self.object = self.get_object()
if not self.get_permission_function(self.object, request.user):
raise self.raised_error
return super(GenericContentPermissionMixinBuilder, self).dispatch(
request, *arg, **kwargs
)
return super().dispatch(request, *arg, **kwargs)
# If we get here, it's a ListView
@ -177,9 +158,7 @@ class GenericContentPermissionMixinBuilder(View):
return self2._get_queryset().filter(id__in=l_id)
self.get_queryset = types.MethodType(get_qs, self)
return super(GenericContentPermissionMixinBuilder, self).dispatch(
request, *arg, **kwargs
)
return super().dispatch(request, *arg, **kwargs)
class CanCreateMixin(View):
@ -191,7 +170,7 @@ class CanCreateMixin(View):
"""
def dispatch(self, request, *arg, **kwargs):
res = super(CanCreateMixin, self).dispatch(request, *arg, **kwargs)
res = super().dispatch(request, *arg, **kwargs)
if not request.user.is_authenticated:
raise PermissionDenied
return res
@ -199,7 +178,7 @@ class CanCreateMixin(View):
def form_valid(self, form):
obj = form.instance
if can_edit_prop(obj, self.request.user):
return super(CanCreateMixin, self).form_valid(form)
return super().form_valid(form)
raise PermissionDenied
@ -258,7 +237,7 @@ class FormerSubscriberMixin(View):
def dispatch(self, request, *args, **kwargs):
if not request.user.was_subscribed:
raise PermissionDenied
return super(FormerSubscriberMixin, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
class UserIsLoggedMixin(View):
@ -271,7 +250,7 @@ class UserIsLoggedMixin(View):
def dispatch(self, request, *args, **kwargs):
if request.user.is_anonymous:
raise PermissionDenied
return super(UserIsLoggedMixin, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
class TabedViewMixin(View):
@ -280,25 +259,22 @@ class TabedViewMixin(View):
"""
def get_tabs_title(self):
try:
if hasattr(self, "tabs_title"):
return self.tabs_title
except:
raise ImproperlyConfigured("tabs_title is required")
raise ImproperlyConfigured("tabs_title is required")
def get_current_tab(self):
try:
if hasattr(self, "current_tab"):
return self.current_tab
except:
raise ImproperlyConfigured("current_tab is required")
raise ImproperlyConfigured("current_tab is required")
def get_list_of_tabs(self):
try:
if hasattr(self, "list_of_tabs"):
return self.list_of_tabs
except:
raise ImproperlyConfigured("list_of_tabs is required")
raise ImproperlyConfigured("list_of_tabs is required")
def get_context_data(self, **kwargs):
kwargs = super(TabedViewMixin, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["tabs_title"] = self.get_tabs_title()
kwargs["current_tab"] = self.get_current_tab()
kwargs["list_of_tabs"] = self.get_list_of_tabs()
@ -311,22 +287,20 @@ class QuickNotifMixin:
def dispatch(self, request, *arg, **kwargs):
# In some cases, the class can stay instanciated, so we need to reset the list
self.quick_notif_list = []
return super(QuickNotifMixin, self).dispatch(request, *arg, **kwargs)
return super().dispatch(request, *arg, **kwargs)
def get_success_url(self):
ret = super(QuickNotifMixin, self).get_success_url()
try:
ret = super().get_success_url()
if hasattr(self, "quick_notif_url_arg"):
if "?" in ret:
ret += "&" + self.quick_notif_url_arg
else:
ret += "?" + self.quick_notif_url_arg
except:
pass
return ret
def get_context_data(self, **kwargs):
"""Add quick notifications to context"""
kwargs = super(QuickNotifMixin, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["quick_notifs"] = []
for n in self.quick_notif_list:
kwargs["quick_notifs"].append(settings.SITH_QUICK_NOTIF[n])
@ -353,7 +327,7 @@ class DetailFormView(SingleObjectMixin, FormView):
"""
Optimisation on group retrieval
"""
return super(DetailFormView, self).get_object()
return super().get_object()
from .files import *

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
@ -171,7 +170,7 @@ class FileListView(ListView):
return SithFile.objects.filter(parent=None)
def get_context_data(self, **kwargs):
kwargs = super(FileListView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["popup"] = ""
if self.kwargs.get("popup") is not None:
kwargs["popup"] = "popup"
@ -189,7 +188,7 @@ class FileEditView(CanEditMixin, UpdateView):
if not self.object.can_be_managed_by(request.user):
raise PermissionDenied
return super(FileEditView, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)
def get_form_class(self):
fields = ["name", "is_moderated"]
@ -207,7 +206,7 @@ class FileEditView(CanEditMixin, UpdateView):
)
def get_context_data(self, **kwargs):
kwargs = super(FileEditView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["popup"] = ""
if self.kwargs.get("popup") is not None:
kwargs["popup"] = "popup"
@ -241,15 +240,15 @@ class FileEditPropView(CanEditPropMixin, UpdateView):
if not self.object.can_be_managed_by(request.user):
raise PermissionDenied
return super(FileEditPropView, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)
def get_form(self, form_class=None):
form = super(FileEditPropView, self).get_form(form_class)
form = super().get_form(form_class)
form.fields["parent"].queryset = SithFile.objects.filter(is_folder=True)
return form
def form_valid(self, form):
ret = super(FileEditPropView, self).form_valid(form)
ret = super().form_valid(form)
if form.cleaned_data["recursive"]:
self.object.apply_rights_recursively()
return ret
@ -261,7 +260,7 @@ class FileEditPropView(CanEditPropMixin, UpdateView):
)
def get_context_data(self, **kwargs):
kwargs = super(FileEditPropView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["popup"] = ""
if self.kwargs.get("popup") is not None:
kwargs["popup"] = "popup"
@ -321,7 +320,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
if "clipboard" not in request.session.keys():
request.session["clipboard"] = []
return super(FileView, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
@ -339,7 +338,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
):
self.form.process(parent=self.object, owner=request.user, files=files)
if self.form.is_valid():
return super(FileView, self).form_valid(self.form)
return super().form_valid(self.form)
return self.form_invalid(self.form)
def get_success_url(self):
@ -349,7 +348,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
)
def get_context_data(self, **kwargs):
kwargs = super(FileView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["popup"] = ""
kwargs["form"] = self.form
if self.kwargs.get("popup") is not None:
@ -371,7 +370,7 @@ class FileDeleteView(CanEditPropMixin, DeleteView):
if not self.object.can_be_managed_by(request.user):
raise PermissionDenied
return super(FileDeleteView, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)
def get_success_url(self):
self.object.file.delete() # Doing it here or overloading delete() is the same, so let's do it here
@ -390,7 +389,7 @@ class FileDeleteView(CanEditPropMixin, DeleteView):
)
def get_context_data(self, **kwargs):
kwargs = super(FileDeleteView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["popup"] = ""
if self.kwargs.get("popup") is not None:
kwargs["popup"] = "popup"
@ -401,7 +400,7 @@ class FileModerationView(TemplateView):
template_name = "core/file_moderation.jinja"
def get_context_data(self, **kwargs):
kwargs = super(FileModerationView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["files"] = SithFile.objects.filter(is_moderated=False)[:100]
return kwargs

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
@ -62,7 +61,7 @@ class SelectDateTime(DateTimeInput):
attrs["class"] = "select_datetime"
else:
attrs = {"class": "select_datetime"}
return super(SelectDateTime, self).render(name, value, attrs, renderer)
return super().render(name, value, attrs, renderer)
class SelectDate(DateInput):
@ -71,14 +70,14 @@ class SelectDate(DateInput):
attrs["class"] = "select_date"
else:
attrs = {"class": "select_date"}
return super(SelectDate, self).render(name, value, attrs, renderer)
return super().render(name, value, attrs, renderer)
class MarkdownInput(Textarea):
template_name = "core/markdown_textarea.jinja"
def get_context(self, name, value, attrs):
context = super(MarkdownInput, self).get_context(name, value, attrs)
context = super().get_context(name, value, attrs)
context["statics"] = {
"js": static("core/easymde/easymde.min.js"),
@ -118,7 +117,7 @@ class SelectFile(TextInput):
output = (
'%(content)s<div name="%(name)s" class="choose_file_widget" title="%(title)s"></div>'
% {
"content": super(SelectFile, self).render(name, value, attrs, renderer),
"content": super().render(name, value, attrs, renderer),
"title": _("Choose file"),
"name": name,
}
@ -142,7 +141,7 @@ class SelectUser(TextInput):
output = (
'%(content)s<div name="%(name)s" class="choose_user_widget" title="%(title)s"></div>'
% {
"content": super(SelectUser, self).render(name, value, attrs, renderer),
"content": super().render(name, value, attrs, renderer),
"title": _("Choose user"),
"name": name,
}
@ -182,7 +181,7 @@ class LoginForm(AuthenticationForm):
except:
pass
kwargs["data"] = data
super(LoginForm, self).__init__(*arg, **kwargs)
super().__init__(*arg, **kwargs)
self.fields["username"].label = _("Username, email, or account number")
@ -196,7 +195,7 @@ class RegisteringForm(UserCreationForm):
fields = ("first_name", "last_name", "email")
def save(self, commit=True):
user = super(RegisteringForm, self).save(commit=False)
user = super().save(commit=False)
user.set_password(self.cleaned_data["password1"])
user.generate_username()
if commit:
@ -258,10 +257,10 @@ class UserProfileForm(forms.ModelForm):
}
def __init__(self, *arg, **kwargs):
super(UserProfileForm, self).__init__(*arg, **kwargs)
super().__init__(*arg, **kwargs)
def full_clean(self):
super(UserProfileForm, self).full_clean()
super().full_clean()
def generate_name(self, field_name, f):
field_name = field_name[:-4]
@ -363,7 +362,7 @@ class PagePropForm(forms.ModelForm):
)
def __init__(self, *arg, **kwargs):
super(PagePropForm, self).__init__(*arg, **kwargs)
super().__init__(*arg, **kwargs)
self.fields["edit_groups"].required = False
self.fields["view_groups"].required = False
@ -381,7 +380,7 @@ class PageForm(forms.ModelForm):
)
def __init__(self, *args, **kwargs):
super(PageForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields["parent"].queryset = (
self.fields["parent"]
.queryset.exclude(name=settings.SITH_CLUB_ROOT_PAGE)
@ -398,7 +397,7 @@ class GiftForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
user_id = kwargs.pop("user_id", None)
super(GiftForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if user_id:
self.fields["user"].queryset = self.fields["user"].queryset.filter(
id=user_id
@ -407,9 +406,9 @@ class GiftForm(forms.ModelForm):
class TzAwareDateTimeField(forms.DateTimeField):
def __init__(
self, input_formats=["%Y-%m-%d %H:%M:%S"], widget=SelectDateTime, **kwargs
):
def __init__(self, input_formats=None, widget=SelectDateTime, **kwargs):
if input_formats is None:
input_formats = ["%Y-%m-%d %H:%M:%S"]
super().__init__(input_formats=input_formats, widget=widget, **kwargs)
def prepare_value(self, value):
@ -420,7 +419,7 @@ class TzAwareDateTimeField(forms.DateTimeField):
# attach it to the UTC timezone (so that to_current_timezone()) if not None
# converts it to the local timezone)
if value is not None:
value = timezone.make_aware(value, timezone.utc)
value = timezone.make_aware(value, datetime.timezone.utc)
if isinstance(value, datetime.datetime):
value = to_current_timezone(value)

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
@ -38,7 +37,7 @@ class EditMembersForm(forms.Form):
def __init__(self, *args, **kwargs):
self.current_users = kwargs.pop("users", [])
super(EditMembersForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields["users_removed"] = forms.ModelMultipleChoiceField(
User.objects.filter(id__in=self.current_users).all(),
label=_("Users to remove from group"),
@ -57,7 +56,7 @@ class EditMembersForm(forms.Form):
"""
Check that the user is not trying to add an user already in the group
"""
cleaned_data = super(EditMembersForm, self).clean()
cleaned_data = super().clean()
users_added = cleaned_data.get("users_added", None)
if not users_added:
return users_added
@ -120,7 +119,7 @@ class GroupTemplateView(CanEditMixin, DetailFormView):
template_name = "core/group_detail.jinja"
def form_valid(self, form):
resp = super(GroupTemplateView, self).form_valid(form)
resp = super().form_valid(form)
data = form.clean()
group = self.get_object()
@ -138,7 +137,7 @@ class GroupTemplateView(CanEditMixin, DetailFormView):
)
def get_form_kwargs(self):
kwargs = super(GroupTemplateView, self).get_form_kwargs()
kwargs = super().get_form_kwargs()
kwargs["users"] = self.get_object().users.all()
return kwargs

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
@ -29,7 +28,7 @@ from core.views.forms import MarkdownInput, PageForm, PagePropForm
class CanEditPagePropMixin(CanEditPropMixin):
def dispatch(self, request, *args, **kwargs):
res = super(CanEditPagePropMixin, self).dispatch(request, *args, **kwargs)
res = super().dispatch(request, *args, **kwargs)
if self.object.is_club_page:
raise Http404
return res
@ -45,7 +44,7 @@ class PageView(CanViewMixin, DetailView):
template_name = "core/page_detail.jinja"
def dispatch(self, request, *args, **kwargs):
res = super(PageView, self).dispatch(request, *args, **kwargs)
res = super().dispatch(request, *args, **kwargs)
if self.object and self.object.need_club_redirection:
return redirect("club:club_view", club_id=self.object.club.id)
return res
@ -55,7 +54,7 @@ class PageView(CanViewMixin, DetailView):
return self.page
def get_context_data(self, **kwargs):
context = super(PageView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
if "page" not in context.keys():
context["new_page"] = self.kwargs["page_name"]
return context
@ -66,7 +65,7 @@ class PageHistView(CanViewMixin, DetailView):
template_name = "core/page_hist.jinja"
def dispatch(self, request, *args, **kwargs):
res = super(PageHistView, self).dispatch(request, *args, **kwargs)
res = super().dispatch(request, *args, **kwargs)
if self.object.need_club_redirection:
return redirect("club:club_hist", club_id=self.object.club.id)
return res
@ -81,7 +80,7 @@ class PageRevView(CanViewMixin, DetailView):
template_name = "core/page_detail.jinja"
def dispatch(self, request, *args, **kwargs):
res = super(PageRevView, self).dispatch(request, *args, **kwargs)
res = super().dispatch(request, *args, **kwargs)
self.object = self.get_object()
if self.object is None:
@ -98,7 +97,7 @@ class PageRevView(CanViewMixin, DetailView):
return self.page
def get_context_data(self, **kwargs):
context = super(PageRevView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
if self.page is not None:
context["page"] = self.page
try:
@ -129,13 +128,13 @@ class PageCreateView(CanCreateMixin, CreateView):
return init
def get_context_data(self, **kwargs):
context = super(PageCreateView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context["new_page"] = True
return context
def form_valid(self, form):
form.instance.set_lock(self.request.user)
ret = super(PageCreateView, self).form_valid(form)
ret = super().form_valid(form)
return ret
@ -147,7 +146,7 @@ class PagePropView(CanEditPagePropMixin, UpdateView):
slug_url_kwarg = "page_name"
def get_object(self):
o = super(PagePropView, self).get_object()
o = super().get_object()
# Create the page if it does not exists
# if p == None:
# parent_name = '/'.join(page_name.split('/')[:-1])
@ -191,7 +190,7 @@ class PageEditViewBase(CanEditMixin, UpdateView):
return None
def get_context_data(self, **kwargs):
context = super(PageEditViewBase, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
if self.page is not None:
context["page"] = self.page
else:
@ -205,12 +204,12 @@ class PageEditViewBase(CanEditMixin, UpdateView):
new_rev.author = self.request.user
new_rev.page = self.page
form.instance = new_rev
return super(PageEditViewBase, self).form_valid(form)
return super().form_valid(form)
class PageEditView(PageEditViewBase):
def dispatch(self, request, *args, **kwargs):
res = super(PageEditView, self).dispatch(request, *args, **kwargs)
res = super().dispatch(request, *args, **kwargs)
if self.object and self.object.page.need_club_redirection:
return redirect("club:club_edit_page", club_id=self.object.page.club.id)
return res

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
@ -144,7 +143,7 @@ class ToMarkdownView(TemplateView):
return self.render_to_response(context)
def get_context_data(self, **kwargs):
kwargs = super(ToMarkdownView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
try:
kwargs["text"] = self.text
kwargs["text_md"] = self.text_md

View File

@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
@ -294,7 +293,7 @@ class UserView(UserTabsMixin, CanViewMixin, DetailView):
current_tab = "infos"
def get_context_data(self, **kwargs):
kwargs = super(UserView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["gift_form"] = GiftForm(
user_id=self.object.id, initial={"user": self.object}
)
@ -313,7 +312,7 @@ class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView):
current_tab = "pictures"
def get_context_data(self, **kwargs):
kwargs = super(UserPicturesView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["albums"] = []
kwargs["pictures"] = {}
picture_qs = all_pictures_of_user(self.object)
@ -363,10 +362,10 @@ class UserGodfathersView(UserTabsMixin, CanViewMixin, DetailView):
self.object.godchildren.add(self.form.cleaned_data["user"])
self.object.save()
self.form = UserGodfathersForm()
return super(UserGodfathersView, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
kwargs = super(UserGodfathersView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
try:
kwargs["form"] = self.form
except:
@ -386,7 +385,7 @@ class UserGodfathersTreeView(UserTabsMixin, CanViewMixin, DetailView):
current_tab = "godfathers"
def get_context_data(self, **kwargs):
kwargs = super(UserGodfathersTreeView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
if "descent" in self.request.GET:
kwargs["param"] = "godchildren"
else:
@ -496,10 +495,10 @@ class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
):
raise PermissionDenied
return super(UserStatsView, self).dispatch(request, *arg, **kwargs)
return super().dispatch(request, *arg, **kwargs)
def get_context_data(self, **kwargs):
kwargs = super(UserStatsView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
from django.db.models import Sum
from counter.models import Counter
@ -673,11 +672,11 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
and request.user.can_edit(self.object)
and self.form.is_valid()
):
return super(UserUpdateProfileView, self).form_valid(self.form)
return super().form_valid(self.form)
return self.form_invalid(self.form)
def get_context_data(self, **kwargs):
kwargs = super(UserUpdateProfileView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["profile"] = self.form.instance
kwargs["form"] = self.form
return kwargs
@ -714,13 +713,13 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
return user
def get_form_kwargs(self):
kwargs = super(UserPreferencesView, self).get_form_kwargs()
kwargs = super().get_form_kwargs()
pref = self.object.preferences
kwargs.update({"instance": pref})
return kwargs
def get_context_data(self, **kwargs):
kwargs = super(UserPreferencesView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
if not (
hasattr(self.object, "trombi_user") and self.request.user.trombi_user.trombi
@ -759,7 +758,7 @@ class UserToolsView(QuickNotifMixin, UserTabsMixin, UserIsLoggedMixin, TemplateV
self.object = self.request.user
from launderette.models import Launderette
kwargs = super(UserToolsView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["launderettes"] = Launderette.objects.all()
kwargs["profile"] = self.request.user
kwargs["object"] = self.request.user
@ -776,7 +775,7 @@ class UserAccountBase(UserTabsMixin, DetailView):
current_tab = "account"
def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
res = super(UserAccountBase, self).dispatch(request, *arg, **kwargs)
res = super().dispatch(request, *arg, **kwargs)
if (
self.object == request.user
or request.user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)
@ -817,7 +816,7 @@ class UserAccountView(UserAccountBase):
return t
def get_context_data(self, **kwargs):
kwargs = super(UserAccountView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["profile"] = self.object
try:
kwargs["customer"] = self.object.customer
@ -846,7 +845,7 @@ class UserAccountDetailView(UserAccountBase, YearMixin, MonthMixin):
template_name = "core/user_account_detail.jinja"
def get_context_data(self, **kwargs):
kwargs = super(UserAccountDetailView, self).get_context_data(**kwargs)
kwargs = super().get_context_data(**kwargs)
kwargs["profile"] = self.object
kwargs["year"] = self.get_year()
kwargs["month"] = self.get_month()
@ -866,13 +865,13 @@ class GiftCreateView(CreateView):
if not (request.user.is_board_member or request.user.is_root):
raise PermissionDenied
self.user = get_object_or_404(User, pk=kwargs["user_id"])
return super(GiftCreateView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
def get_initial(self):
return {"user": self.user}
def get_form_kwargs(self):
kwargs = super(GiftCreateView, self).get_form_kwargs()
kwargs = super().get_form_kwargs()
kwargs["user_id"] = self.user.id
return kwargs
@ -887,7 +886,7 @@ class GiftDeleteView(CanEditPropMixin, DeleteView):
def dispatch(self, request, *args, **kwargs):
self.user = get_object_or_404(User, pk=kwargs["user_id"])
return super(GiftDeleteView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
def get_success_url(self):
return reverse_lazy("core:user_profile", kwargs={"user_id": self.user.id})