mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Add more Ruff rules (#891)
* ruff: apply rule F * ruff: apply rule E * ruff: apply rule SIM * ruff: apply rule TCH * ruff: apply rule ERA * ruff: apply rule PLW * ruff: apply rule FLY * ruff: apply rule PERF * ruff: apply rules FURB & RUF
This commit is contained in:
@ -30,7 +30,12 @@ class Migration(migrations.Migration):
|
||||
"subscription_deadline",
|
||||
models.DateField(
|
||||
default=datetime.date.today,
|
||||
help_text="Before this date, users are allowed to subscribe to this Trombi. After this date, users subscribed will be allowed to comment on each other.",
|
||||
help_text=(
|
||||
"Before this date, users are allowed "
|
||||
"to subscribe to this Trombi. "
|
||||
"After this date, users subscribed will "
|
||||
"be allowed to comment on each other."
|
||||
),
|
||||
verbose_name="subscription deadline",
|
||||
),
|
||||
),
|
||||
@ -38,7 +43,10 @@ class Migration(migrations.Migration):
|
||||
"comments_deadline",
|
||||
models.DateField(
|
||||
default=datetime.date.today,
|
||||
help_text="After this date, users won't be able to make comments anymore.",
|
||||
help_text=(
|
||||
"After this date, users won't be able "
|
||||
"to make comments anymore."
|
||||
),
|
||||
verbose_name="comments deadline",
|
||||
),
|
||||
),
|
||||
@ -92,7 +100,10 @@ class Migration(migrations.Migration):
|
||||
models.ImageField(
|
||||
upload_to="trombi",
|
||||
blank=True,
|
||||
help_text="The profile picture you want in the trombi (warning: this picture may be published)",
|
||||
help_text=(
|
||||
"The profile picture you want in the trombi "
|
||||
"(warning: this picture may be published)"
|
||||
),
|
||||
verbose_name="profile pict",
|
||||
null=True,
|
||||
),
|
||||
@ -102,7 +113,10 @@ class Migration(migrations.Migration):
|
||||
models.ImageField(
|
||||
upload_to="trombi",
|
||||
blank=True,
|
||||
help_text="The scrub picture you want in the trombi (warning: this picture may be published)",
|
||||
help_text=(
|
||||
"The scrub picture you want in the trombi "
|
||||
"(warning: this picture may be published)"
|
||||
),
|
||||
verbose_name="scrub pict",
|
||||
null=True,
|
||||
),
|
||||
|
@ -55,9 +55,9 @@ class Trombi(models.Model):
|
||||
_("subscription deadline"),
|
||||
default=date.today,
|
||||
help_text=_(
|
||||
"Before this date, users are "
|
||||
"allowed to subscribe to this Trombi. "
|
||||
"After this date, users subscribed will be allowed to comment on each other."
|
||||
"Before this date, users are allowed to subscribe to this Trombi. "
|
||||
"After this date, users subscribed will"
|
||||
" be allowed to comment on each other."
|
||||
),
|
||||
)
|
||||
comments_deadline = models.DateField(
|
||||
@ -131,7 +131,8 @@ class TrombiUser(models.Model):
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text=_(
|
||||
"The profile picture you want in the trombi (warning: this picture may be published)"
|
||||
"The profile picture you want in the trombi "
|
||||
"(warning: this picture may be published)"
|
||||
),
|
||||
)
|
||||
scrub_pict = models.ImageField(
|
||||
@ -140,7 +141,8 @@ class TrombiUser(models.Model):
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text=_(
|
||||
"The scrub picture you want in the trombi (warning: this picture may be published)"
|
||||
"The scrub picture you want in the trombi "
|
||||
"(warning: this picture may be published)"
|
||||
),
|
||||
)
|
||||
|
||||
@ -158,10 +160,7 @@ class TrombiUser(models.Model):
|
||||
role = str(settings.SITH_CLUB_ROLES[m.role])
|
||||
if m.description:
|
||||
role += " (%s)" % m.description
|
||||
if m.end_date:
|
||||
end_date = get_semester_code(m.end_date)
|
||||
else:
|
||||
end_date = ""
|
||||
end_date = get_semester_code(m.end_date) if m.end_date else ""
|
||||
TrombiClubMembership(
|
||||
user=self,
|
||||
club=str(m.club),
|
||||
|
@ -24,7 +24,25 @@
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from trombi.views import *
|
||||
from trombi.views import (
|
||||
TrombiCommentCreateView,
|
||||
TrombiCommentEditView,
|
||||
TrombiCreateView,
|
||||
TrombiDeleteUserView,
|
||||
TrombiDetailView,
|
||||
TrombiEditView,
|
||||
TrombiExportView,
|
||||
TrombiModerateCommentsView,
|
||||
TrombiModerateCommentView,
|
||||
UserTrombiAddMembershipView,
|
||||
UserTrombiDeleteMembershipView,
|
||||
UserTrombiEditMembershipView,
|
||||
UserTrombiEditPicturesView,
|
||||
UserTrombiEditProfileView,
|
||||
UserTrombiProfileView,
|
||||
UserTrombiResetClubMembershipsView,
|
||||
UserTrombiToolsView,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("<int:club_id>/new/", TrombiCreateView.as_view(), name="create"),
|
||||
@ -41,9 +59,7 @@ urlpatterns = [
|
||||
name="moderate_comment",
|
||||
),
|
||||
path(
|
||||
"user/<int:user_id>/delete/",
|
||||
TrombiDeleteUserView.as_view(),
|
||||
name="delete_user",
|
||||
"user/<int:user_id>/delete/", TrombiDeleteUserView.as_view(), name="delete_user"
|
||||
),
|
||||
path("<int:trombi_id>/", TrombiDetailView.as_view(), name="detail"),
|
||||
path(
|
||||
@ -52,9 +68,7 @@ urlpatterns = [
|
||||
name="new_comment",
|
||||
),
|
||||
path(
|
||||
"<int:user_id>/profile/",
|
||||
UserTrombiProfileView.as_view(),
|
||||
name="user_profile",
|
||||
"<int:user_id>/profile/", UserTrombiProfileView.as_view(), name="user_profile"
|
||||
),
|
||||
path(
|
||||
"comment/<int:comment_id>/edit/",
|
||||
|
@ -29,6 +29,7 @@ from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import IntegrityError
|
||||
from django.forms.models import modelform_factory
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
@ -75,7 +76,10 @@ class TrombiTabsMixin(TabedViewMixin):
|
||||
"name": _("My pictures"),
|
||||
}
|
||||
)
|
||||
try:
|
||||
if (
|
||||
hasattr(self.request.user, "trombi_user")
|
||||
and self.request.user.trombi_user.trombi
|
||||
):
|
||||
trombi = self.request.user.trombi_user.trombi
|
||||
if self.request.user.is_owner(trombi):
|
||||
tab_list.append(
|
||||
@ -87,8 +91,6 @@ class TrombiTabsMixin(TabedViewMixin):
|
||||
"name": _("Admin tools"),
|
||||
}
|
||||
)
|
||||
except:
|
||||
pass
|
||||
return tab_list
|
||||
|
||||
|
||||
@ -163,7 +165,7 @@ class TrombiDetailView(CanEditMixin, QuickNotifMixin, TrombiTabsMixin, DetailVie
|
||||
try:
|
||||
TrombiUser(user=form.cleaned_data["user"], trombi=self.object).save()
|
||||
self.quick_notif_list.append("qn_success")
|
||||
except: # We don't care about duplicate keys
|
||||
except IntegrityError: # We don't care about duplicate keys
|
||||
self.quick_notif_list.append("qn_fail")
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
@ -239,12 +241,12 @@ class TrombiModerateCommentView(DetailView):
|
||||
)
|
||||
elif request.POST["action"] == "reject":
|
||||
return super().get(request, *args, **kwargs)
|
||||
elif request.POST["action"] == "delete" and "reason" in request.POST.keys():
|
||||
elif request.POST["action"] == "delete" and "reason" in request.POST:
|
||||
self.object.author.user.email_user(
|
||||
subject="[%s] %s" % (settings.SITH_NAME, _("Rejected comment")),
|
||||
message=_(
|
||||
'Your comment to %(target)s on the Trombi "%(trombi)s" was rejected for the following '
|
||||
"reason: %(reason)s\n\n"
|
||||
'Your comment to %(target)s on the Trombi "%(trombi)s" '
|
||||
"was rejected for the following reason: %(reason)s\n\n"
|
||||
"Your comment was:\n\n%(content)s"
|
||||
)
|
||||
% {
|
||||
@ -498,7 +500,7 @@ class TrombiCommentFormView(LoginRequiredMixin, View):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
if "user_id" in self.kwargs.keys():
|
||||
if "user_id" in self.kwargs:
|
||||
kwargs["target"] = get_object_or_404(TrombiUser, id=self.kwargs["user_id"])
|
||||
else:
|
||||
kwargs["target"] = self.object.target
|
||||
|
Reference in New Issue
Block a user