mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
core: create a DetailFormView
This commit is contained in:
@ -39,6 +39,9 @@ from django.core.exceptions import (
|
||||
ImproperlyConfigured,
|
||||
)
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.edit import FormView
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.utils.functional import cached_property
|
||||
from django.db.models import Count
|
||||
|
||||
from core.models import Group
|
||||
@ -275,6 +278,30 @@ class QuickNotifMixin:
|
||||
return kwargs
|
||||
|
||||
|
||||
class DetailFormView(SingleObjectMixin, FormView):
|
||||
"""
|
||||
Class that allow both a detail view and a form view
|
||||
"""
|
||||
|
||||
def get_object(self):
|
||||
"""
|
||||
Get current group from id in url
|
||||
"""
|
||||
return self.cached_object
|
||||
|
||||
@cached_property
|
||||
def cached_object(self):
|
||||
"""
|
||||
Optimisation on group retrieval
|
||||
"""
|
||||
return super(DetailFormView, self).get_object()
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
kwargs = super(DetailFormView, self).get_context_data()
|
||||
kwargs["object"] = self.get_object()
|
||||
return kwargs
|
||||
|
||||
|
||||
from .user import *
|
||||
from .page import *
|
||||
from .files import *
|
||||
|
Reference in New Issue
Block a user