mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
replace drf by django-ninja
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
import types
|
||||
from typing import Any
|
||||
|
||||
from django.contrib.auth.mixins import AccessMixin
|
||||
from django.core.exceptions import (
|
||||
ImproperlyConfigured,
|
||||
PermissionDenied,
|
||||
@ -234,7 +235,7 @@ class UserIsRootMixin(GenericContentPermissionMixinBuilder):
|
||||
permission_function = lambda obj, user: user.is_root
|
||||
|
||||
|
||||
class FormerSubscriberMixin(View):
|
||||
class FormerSubscriberMixin(AccessMixin):
|
||||
"""Check if the user was at least an old subscriber.
|
||||
|
||||
Raises:
|
||||
@ -247,16 +248,10 @@ class FormerSubscriberMixin(View):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class UserIsLoggedMixin(View):
|
||||
"""Check if the user is logged.
|
||||
|
||||
Raises:
|
||||
PermissionDenied:
|
||||
"""
|
||||
|
||||
class SubscriberMixin(AccessMixin):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if request.user.is_anonymous:
|
||||
raise PermissionDenied
|
||||
if not request.user.is_subscribed:
|
||||
return self.handle_no_permission()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
|
@ -104,7 +104,7 @@ class MarkdownInput(Textarea):
|
||||
"fullscreen": _("Toggle fullscreen"),
|
||||
"guide": _("Markdown guide"),
|
||||
}
|
||||
context["markdown_api_url"] = reverse("api:api_markdown")
|
||||
context["markdown_api_url"] = reverse("api:markdown")
|
||||
return context
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@ from smtplib import SMTPException
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import login, views
|
||||
from django.contrib.auth.forms import PasswordChangeForm
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.forms.models import modelform_factory
|
||||
@ -50,7 +51,6 @@ from django.views.generic.dates import MonthMixin, YearMixin
|
||||
from django.views.generic.edit import FormView, UpdateView
|
||||
from honeypot.decorators import check_honeypot
|
||||
|
||||
from api.views.sas import all_pictures_of_user
|
||||
from core.models import Gift, Preferences, SithFile, User
|
||||
from core.views import (
|
||||
CanEditMixin,
|
||||
@ -58,7 +58,6 @@ from core.views import (
|
||||
CanViewMixin,
|
||||
QuickNotifMixin,
|
||||
TabedViewMixin,
|
||||
UserIsLoggedMixin,
|
||||
)
|
||||
from core.views.forms import (
|
||||
GiftForm,
|
||||
@ -68,6 +67,7 @@ from core.views.forms import (
|
||||
UserProfileForm,
|
||||
)
|
||||
from counter.forms import StudentCardForm
|
||||
from sas.models import Picture
|
||||
from subscription.models import Subscription
|
||||
from trombi.views import UserTrombiForm
|
||||
|
||||
@ -313,7 +313,11 @@ class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
kwargs["albums"] = []
|
||||
kwargs["pictures"] = {}
|
||||
picture_qs = all_pictures_of_user(self.object)
|
||||
picture_qs = (
|
||||
Picture.objects.filter(people__user_id=self.object.id)
|
||||
.order_by("parent__date", "id")
|
||||
.all()
|
||||
)
|
||||
last_album = None
|
||||
for picture in picture_qs:
|
||||
album = picture.parent
|
||||
@ -720,7 +724,7 @@ class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
|
||||
current_tab = "groups"
|
||||
|
||||
|
||||
class UserToolsView(QuickNotifMixin, UserTabsMixin, UserIsLoggedMixin, TemplateView):
|
||||
class UserToolsView(LoginRequiredMixin, QuickNotifMixin, UserTabsMixin, TemplateView):
|
||||
"""Displays the logged user's tools."""
|
||||
|
||||
template_name = "core/user_tools.jinja"
|
||||
|
Reference in New Issue
Block a user