mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Move view mixin to plugin.views
This commit is contained in:
parent
9f15dd8e2a
commit
06e79ee91b
@ -38,8 +38,6 @@ from part.models import PartCategory
|
||||
from common.models import InvenTreeSetting, ColorTheme
|
||||
from users.models import check_user_role, RuleSet
|
||||
|
||||
from plugin.registry import registry
|
||||
|
||||
from .forms import DeleteForm, EditUserForm, SetPasswordForm
|
||||
from .forms import SettingCategorySelectForm
|
||||
from .helpers import str2bool
|
||||
@ -58,37 +56,6 @@ def auth_request(request):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
|
||||
class InvenTreePluginMixin:
|
||||
"""
|
||||
Custom view mixin which adds context data to the view,
|
||||
based on loaded plugins.
|
||||
|
||||
This allows rendered pages to be augmented by loaded plugins.
|
||||
|
||||
"""
|
||||
|
||||
def get_plugin_panels(self, ctx):
|
||||
"""
|
||||
Return a list of extra 'plugin panels' associated with this view
|
||||
"""
|
||||
|
||||
panels = []
|
||||
|
||||
for plug in registry.with_mixin('panel'):
|
||||
panels += plug.render_panels(self, self.request, ctx)
|
||||
|
||||
return panels
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
if settings.PLUGINS_ENABLED:
|
||||
ctx['plugin_panels'] = self.get_plugin_panels(ctx)
|
||||
|
||||
return ctx
|
||||
|
||||
|
||||
class InvenTreeRoleMixin(PermissionRequiredMixin):
|
||||
"""
|
||||
Permission class based on user roles, not user 'permissions'.
|
||||
|
@ -11,9 +11,11 @@ from django.views.generic import DetailView, ListView
|
||||
from .models import Build
|
||||
|
||||
from InvenTree.views import AjaxDeleteView
|
||||
from InvenTree.views import InvenTreeRoleMixin, InvenTreePluginMixin
|
||||
from InvenTree.views import InvenTreeRoleMixin
|
||||
from InvenTree.status_codes import BuildStatus
|
||||
|
||||
from plugin.views import InvenTreePluginViewMixin
|
||||
|
||||
|
||||
class BuildIndex(InvenTreeRoleMixin, ListView):
|
||||
"""
|
||||
@ -41,7 +43,7 @@ class BuildIndex(InvenTreeRoleMixin, ListView):
|
||||
return context
|
||||
|
||||
|
||||
class BuildDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class BuildDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
"""
|
||||
Detail view of a single Build object.
|
||||
"""
|
||||
|
@ -17,15 +17,16 @@ import requests
|
||||
import io
|
||||
|
||||
from InvenTree.views import AjaxUpdateView
|
||||
from InvenTree.views import InvenTreeRoleMixin, InvenTreePluginMixin
|
||||
from InvenTree.views import InvenTreeRoleMixin
|
||||
|
||||
from .models import Company
|
||||
from .models import ManufacturerPart
|
||||
from .models import SupplierPart
|
||||
|
||||
|
||||
from .forms import CompanyImageDownloadForm
|
||||
|
||||
from plugin.views import InvenTreePluginViewMixin
|
||||
|
||||
|
||||
class CompanyIndex(InvenTreeRoleMixin, ListView):
|
||||
""" View for displaying list of companies
|
||||
@ -104,7 +105,7 @@ class CompanyIndex(InvenTreeRoleMixin, ListView):
|
||||
return queryset
|
||||
|
||||
|
||||
class CompanyDetail(InvenTreePluginMixin, DetailView):
|
||||
class CompanyDetail(InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for Company object """
|
||||
context_obect_name = 'company'
|
||||
template_name = 'company/detail.html'
|
||||
@ -196,7 +197,7 @@ class CompanyImageDownloadFromURL(AjaxUpdateView):
|
||||
)
|
||||
|
||||
|
||||
class ManufacturerPartDetail(InvenTreePluginMixin, DetailView):
|
||||
class ManufacturerPartDetail(InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for ManufacturerPart """
|
||||
model = ManufacturerPart
|
||||
template_name = 'company/manufacturer_part_detail.html'
|
||||
@ -210,7 +211,7 @@ class ManufacturerPartDetail(InvenTreePluginMixin, DetailView):
|
||||
return ctx
|
||||
|
||||
|
||||
class SupplierPartDetail(InvenTreePluginMixin, DetailView):
|
||||
class SupplierPartDetail(InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for SupplierPart """
|
||||
model = SupplierPart
|
||||
template_name = 'company/supplier_part_detail.html'
|
||||
|
@ -31,7 +31,9 @@ from . import forms as order_forms
|
||||
from part.views import PartPricing
|
||||
|
||||
from InvenTree.helpers import DownloadFile
|
||||
from InvenTree.views import InvenTreeRoleMixin, InvenTreePluginMixin, AjaxView
|
||||
from InvenTree.views import InvenTreeRoleMixin, AjaxView
|
||||
|
||||
from plugin.views import InvenTreePluginViewMixin
|
||||
|
||||
|
||||
logger = logging.getLogger("inventree")
|
||||
@ -65,7 +67,7 @@ class SalesOrderIndex(InvenTreeRoleMixin, ListView):
|
||||
context_object_name = 'orders'
|
||||
|
||||
|
||||
class PurchaseOrderDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class PurchaseOrderDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for a PurchaseOrder object """
|
||||
|
||||
context_object_name = 'order'
|
||||
@ -78,7 +80,7 @@ class PurchaseOrderDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
return ctx
|
||||
|
||||
|
||||
class SalesOrderDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class SalesOrderDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for a SalesOrder object """
|
||||
|
||||
context_object_name = 'order'
|
||||
|
@ -49,10 +49,12 @@ from order.models import PurchaseOrderLineItem
|
||||
|
||||
from InvenTree.views import AjaxView, AjaxCreateView, AjaxUpdateView, AjaxDeleteView
|
||||
from InvenTree.views import QRCodeView
|
||||
from InvenTree.views import InvenTreeRoleMixin, InvenTreePluginMixin
|
||||
from InvenTree.views import InvenTreeRoleMixin
|
||||
|
||||
from InvenTree.helpers import str2bool
|
||||
|
||||
from plugin.views import InvenTreePluginViewMixin
|
||||
|
||||
|
||||
class PartIndex(InvenTreeRoleMixin, ListView):
|
||||
""" View for displaying list of Part objects
|
||||
@ -365,7 +367,7 @@ class PartImportAjax(FileManagementAjaxView, PartImport):
|
||||
return PartImport.validate(self, self.steps.current, form, **kwargs)
|
||||
|
||||
|
||||
class PartDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for Part object
|
||||
"""
|
||||
|
||||
@ -969,7 +971,7 @@ class PartParameterTemplateDelete(AjaxDeleteView):
|
||||
ajax_form_title = _("Delete Part Parameter Template")
|
||||
|
||||
|
||||
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for PartCategory """
|
||||
|
||||
model = PartCategory
|
||||
|
40
InvenTree/plugin/views.py
Normal file
40
InvenTree/plugin/views.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from plugin.registry import registry
|
||||
|
||||
|
||||
class InvenTreePluginViewMixin:
|
||||
"""
|
||||
Custom view mixin which adds context data to the view,
|
||||
based on loaded plugins.
|
||||
|
||||
This allows rendered pages to be augmented by loaded plugins.
|
||||
|
||||
"""
|
||||
|
||||
def get_plugin_panels(self, ctx):
|
||||
"""
|
||||
Return a list of extra 'plugin panels' associated with this view
|
||||
"""
|
||||
|
||||
panels = []
|
||||
|
||||
for plug in registry.with_mixin('panel'):
|
||||
panels += plug.render_panels(self, self.request, ctx)
|
||||
|
||||
return panels
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
Add plugin context data to the view
|
||||
"""
|
||||
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
if settings.PLUGINS_ENABLED:
|
||||
ctx['plugin_panels'] = self.get_plugin_panels(ctx)
|
||||
|
||||
return ctx
|
@ -15,7 +15,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||
from InvenTree.views import QRCodeView
|
||||
from InvenTree.views import InvenTreeRoleMixin, InvenTreePluginMixin
|
||||
from InvenTree.views import InvenTreeRoleMixin
|
||||
from InvenTree.forms import ConfirmForm
|
||||
|
||||
from InvenTree.helpers import str2bool
|
||||
@ -26,8 +26,10 @@ import common.settings
|
||||
|
||||
from . import forms as StockForms
|
||||
|
||||
from plugin.views import InvenTreePluginViewMixin
|
||||
|
||||
class StockIndex(InvenTreeRoleMixin, InvenTreePluginMixin, ListView):
|
||||
|
||||
class StockIndex(InvenTreeRoleMixin, InvenTreePluginViewMixin, ListView):
|
||||
""" StockIndex view loads all StockLocation and StockItem object
|
||||
"""
|
||||
model = StockItem
|
||||
@ -54,7 +56,7 @@ class StockIndex(InvenTreeRoleMixin, InvenTreePluginMixin, ListView):
|
||||
return context
|
||||
|
||||
|
||||
class StockLocationDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class StockLocationDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
"""
|
||||
Detailed view of a single StockLocation object
|
||||
"""
|
||||
@ -75,7 +77,7 @@ class StockLocationDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
return context
|
||||
|
||||
|
||||
class StockItemDetail(InvenTreeRoleMixin, InvenTreePluginMixin, DetailView):
|
||||
class StockItemDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
"""
|
||||
Detailed view of a single StockItem object
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user