core: create a DetailFormView

This commit is contained in:
2019-04-10 13:21:34 +02:00
parent 34459f83ec
commit 08d03087a4
3 changed files with 35 additions and 25 deletions

View File

@ -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 *