fixed WebsiteProtectedWithAjaxMixin template response
This commit is contained in:
@@ -294,13 +294,14 @@ class PlanningView(MaraudesView, generic.TemplateView):
|
|||||||
|
|
||||||
## LIEU
|
## LIEU
|
||||||
|
|
||||||
class LieuCreateView(MaraudesView, views.AjaxTemplateMixin, generic.edit.CreateView):
|
class LieuCreateView(views.WebsiteProtectedWithAjaxMixin, generic.edit.CreateView):
|
||||||
model = Lieu
|
model = Lieu
|
||||||
ajax_template_name = "maraudes/lieu_create_inner.html"
|
|
||||||
template_name = "maraudes/lieu_create.html"
|
template_name = "maraudes/lieu_create.html"
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
success_url = "/maraudes/"
|
success_url = "/maraudes/"
|
||||||
|
|
||||||
|
permissions = ['maraudes.add_lieu']
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if 'next' in self.request.POST:
|
if 'next' in self.request.POST:
|
||||||
self.success_url = self.request.POST["next"]
|
self.success_url = self.request.POST["next"]
|
||||||
|
|||||||
@@ -43,13 +43,14 @@ class SujetCreateForm(ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SujetCreateView(SujetsView, generic.edit.CreateView, views.AjaxTemplateMixin):
|
class SujetCreateView(views.WebsiteProtectedWithAjaxMixin, generic.edit.CreateView):
|
||||||
template_name = "sujets/sujet_create.html"
|
template_name = "sujets/sujet_create.html"
|
||||||
form_class = SujetCreateForm
|
form_class = SujetCreateForm
|
||||||
|
|
||||||
title = "Création : Sujet"
|
title = "Création : Sujet"
|
||||||
header = "Ajouter un sujet"
|
header = "Ajouter un sujet"
|
||||||
|
|
||||||
|
permissions = ['sujets.view_sujets', 'sujets.add_sujet']
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if 'next' in self.request.POST:
|
if 'next' in self.request.POST:
|
||||||
|
|||||||
@@ -24,18 +24,6 @@ class PermissionRequiredMixin(object):
|
|||||||
return permission_required(cls.permissions)(view)
|
return permission_required(cls.permissions)(view)
|
||||||
|
|
||||||
|
|
||||||
class AjaxTemplateMixin(object):
|
|
||||||
""" Mixin that enables the use of 'ajax_template_name' custom template
|
|
||||||
when request is Ajax.
|
|
||||||
"""
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
if not hasattr(self, 'ajax_template_name'):
|
|
||||||
raise NotImplementedError
|
|
||||||
if request.is_ajax():
|
|
||||||
self.template_name = self.ajax_template_name
|
|
||||||
return super(AjaxTemplateMixin, self).dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TemplateFieldsMetaclass(type):
|
class TemplateFieldsMetaclass(type):
|
||||||
""" Loads Template objects with given string for
|
""" Loads Template objects with given string for
|
||||||
@@ -129,8 +117,26 @@ class WebsiteTemplateMixin(TemplateResponseMixin):
|
|||||||
class WebsiteProtectedMixin(WebsiteTemplateMixin, PermissionRequiredMixin):
|
class WebsiteProtectedMixin(WebsiteTemplateMixin, PermissionRequiredMixin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class WebsiteProtectedWithAjaxMixin(WebsiteProtectedMixin, AjaxTemplateMixin):
|
class WebsiteProtectedWithAjaxMixin(WebsiteProtectedMixin):
|
||||||
pass
|
""" Mixin that enables the use of 'ajax_template_name' custom template
|
||||||
|
when request is Ajax.
|
||||||
|
"""
|
||||||
|
is_ajax = False
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if not hasattr(self, 'ajax_template_name'):
|
||||||
|
self.ajax_template_name = "%s_inner.html" % self.template_name.split(".")[0]
|
||||||
|
print('%s :' % self, self.ajax_template_name)
|
||||||
|
if request.is_ajax():
|
||||||
|
self.is_ajax = True
|
||||||
|
self.template_name = self.ajax_template_name
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_template_names(self):
|
||||||
|
if self.is_ajax:
|
||||||
|
return [self.template_name]
|
||||||
|
else:
|
||||||
|
return super().get_template_names()
|
||||||
|
|
||||||
## Views : Index ##
|
## Views : Index ##
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user