Sith/core/views/__init__.py

77 lines
2.5 KiB
Python
Raw Normal View History

#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
# - Sli <antoine@bartuccio.fr>
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License a published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
from django.http import (
HttpResponseForbidden,
HttpResponseNotFound,
HttpResponseServerError,
)
from django.shortcuts import render
2024-06-24 11:07:36 +00:00
from django.utils.functional import cached_property
2019-04-10 11:21:34 +00:00
from django.views.generic.detail import SingleObjectMixin
2024-06-24 11:07:36 +00:00
from django.views.generic.edit import FormView
from sentry_sdk import last_event_id
2016-08-31 00:43:49 +00:00
from core.views.forms import LoginForm
2018-10-04 19:29:19 +00:00
def forbidden(request, exception):
2024-06-27 12:46:43 +00:00
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))
2018-10-04 19:29:19 +00:00
def not_found(request, exception):
return HttpResponseNotFound(
render(request, "core/404.jinja", context={"exception": exception})
)
2018-10-04 19:29:19 +00:00
def internal_servor_error(request):
request.sentry_last_event_id = last_event_id
return HttpResponseServerError(render(request, "core/500.jinja"))
2019-04-10 11:21:34 +00:00
class DetailFormView(SingleObjectMixin, FormView):
2024-07-12 07:34:16 +00:00
"""Class that allow both a detail view and a form view."""
2019-04-10 11:21:34 +00:00
def get_object(self):
2024-07-12 07:34:16 +00:00
"""Get current group from id in url."""
2019-04-10 11:21:34 +00:00
return self.cached_object
@cached_property
def cached_object(self):
2024-07-12 07:34:16 +00:00
"""Optimisation on group retrieval."""
2024-06-27 12:46:43 +00:00
return super().get_object()
2019-04-10 11:21:34 +00:00
# F403: those star-imports would be hellish to refactor
# E402: putting those import at the top of the file would also be difficult
from .files import * # noqa: F403 E402
from .group import * # noqa: F403 E402
from .page import * # noqa: F403 E402
from .site import * # noqa: F403 E402
from .user import * # noqa: F403 E402