mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Update view logic for is_ajax being changed to a template context processor
This commit is contained in:
@@ -30,6 +30,8 @@ from RIGS import models
|
||||
from assets import models as asset_models
|
||||
from training import models as training_models
|
||||
|
||||
# Template context processor
|
||||
|
||||
|
||||
def is_ajax(request):
|
||||
return {"is_ajax": request.headers.get('x-requested-with') == 'XMLHttpRequest'}
|
||||
@@ -183,7 +185,7 @@ class SecureAPIRequest(generic.View):
|
||||
|
||||
class ModalURLMixin:
|
||||
def get_close_url(self, update, detail):
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
url = reverse_lazy('closemodal')
|
||||
update_url = str(reverse_lazy(update, kwargs={'pk': self.object.pk}))
|
||||
messages.info(self.request, "modalobject=" + serializers.serialize("json", [self.object]))
|
||||
@@ -202,7 +204,7 @@ class GenericListView(generic.ListView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = self.model.__name__ + "s"
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
return context
|
||||
|
||||
@@ -221,7 +223,7 @@ class GenericDetailView(generic.DetailView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = f"{self.model.__name__} | {self.object.name}"
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
return context
|
||||
|
||||
@@ -232,7 +234,7 @@ class GenericUpdateView(generic.UpdateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = f"Edit {self.model.__name__}"
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
return context
|
||||
|
||||
@@ -243,7 +245,7 @@ class GenericCreateView(generic.CreateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = f"Create {self.model.__name__}"
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
return context
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends 'base_assets.html' %}
|
||||
{% extends is_ajax|yesno:"base_ajax.html,base_assets.html" %}
|
||||
{% load widget_tweaks %}
|
||||
{% load static %}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class AssetEdit(LoginRequiredMixin, AssetIDUrlMixin, generic.UpdateView):
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
url = reverse_lazy('closemodal')
|
||||
update_url = str(reverse_lazy('asset_update', kwargs={'pk': self.object.pk}))
|
||||
messages.info(self.request, "modalobject=" + serializers.serialize("json", [self.object]))
|
||||
@@ -233,7 +233,7 @@ class SupplierList(GenericListView):
|
||||
context['edit'] = 'supplier_update'
|
||||
context['can_edit'] = self.request.user.has_perm('assets.change_supplier')
|
||||
context['detail'] = 'supplier_detail'
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
context['override'] = 'base_assets.html'
|
||||
@@ -250,7 +250,7 @@ class SupplierDetail(GenericDetailView):
|
||||
context['detail_link'] = 'supplier_detail'
|
||||
context['associated'] = 'partials/associated_assets.html'
|
||||
context['associated2'] = ''
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
context['override'] = 'base_assets.html'
|
||||
@@ -264,7 +264,7 @@ class SupplierCreate(GenericCreateView, ModalURLMixin):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
context['override'] = 'base_assets.html'
|
||||
@@ -280,7 +280,7 @@ class SupplierUpdate(GenericUpdateView, ModalURLMixin):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
context['override'] = 'base_assets.html'
|
||||
|
||||
@@ -88,4 +88,5 @@ dev = [
|
||||
"pytest-reverse",
|
||||
"pytest-xdist[psutil]",
|
||||
"PyPOM[splinter]",
|
||||
"autopep8>=2.3.2",
|
||||
]
|
||||
|
||||
@@ -126,7 +126,7 @@ class AddQualification(generic.CreateView, ModalURLMixin):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||
if is_ajax(self.request):
|
||||
if is_ajax(self.request).get('is_ajax'):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
context['override'] = 'base_training.html'
|
||||
|
||||
15
uv.lock
generated
15
uv.lock
generated
@@ -32,6 +32,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", size = 63815, upload-time = "2025-03-13T11:10:21.14Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autopep8"
|
||||
version = "2.3.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pycodestyle" },
|
||||
{ name = "tomli" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/50/d8/30873d2b7b57dee9263e53d142da044c4600a46f2d28374b3e38b023df16/autopep8-2.3.2.tar.gz", hash = "sha256:89440a4f969197b69a995e4ce0661b031f455a9f776d2c5ba3dbd83466931758", size = 92210, upload-time = "2025-01-14T14:46:18.454Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/9e/43/53afb8ba17218f19b77c7834128566c5bbb100a0ad9ba2e8e89d089d7079/autopep8-2.3.2-py2.py3-none-any.whl", hash = "sha256:ce8ad498672c845a0c3de2629c15b635ec2b05ef8177a6e7c91c74f3e9b51128", size = 45807, upload-time = "2025-01-14T14:46:15.466Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backports-tempfile"
|
||||
version = "1.0"
|
||||
@@ -843,6 +856,7 @@ source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "ansicolors" },
|
||||
{ name = "asgiref" },
|
||||
{ name = "autopep8" },
|
||||
{ name = "beautifulsoup4" },
|
||||
{ name = "brotli" },
|
||||
{ name = "cachetools" },
|
||||
@@ -928,6 +942,7 @@ dev = [
|
||||
requires-dist = [
|
||||
{ name = "ansicolors" },
|
||||
{ name = "asgiref" },
|
||||
{ name = "autopep8", specifier = ">=2.3.2" },
|
||||
{ name = "beautifulsoup4" },
|
||||
{ name = "brotli" },
|
||||
{ name = "cachetools" },
|
||||
|
||||
Reference in New Issue
Block a user