mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
added settings actions
This commit is contained in:
parent
bf0129788d
commit
35d2259edf
@ -2,13 +2,35 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
from django.apps import apps
|
||||
|
||||
import plugin.models as models
|
||||
|
||||
|
||||
def plugin_update(queryset, new_status: bool):
|
||||
for model in queryset:
|
||||
model.active = new_status
|
||||
model.save(no_reload=True)
|
||||
|
||||
app = apps.get_app_config('plugin')
|
||||
app.reload_plugins()
|
||||
|
||||
|
||||
@admin.action(description='Activate plugin(s)')
|
||||
def plugin_activate(modeladmin, request, queryset):
|
||||
plugin_update(queryset, True)
|
||||
|
||||
|
||||
@admin.action(description='Deactivate plugin(s)')
|
||||
def plugin_deactivate(modeladmin, request, queryset):
|
||||
plugin_update(queryset, False)
|
||||
|
||||
|
||||
class PluginConfigAdmin(admin.ModelAdmin):
|
||||
"""Custom admin with restricted id fields"""
|
||||
readonly_fields = ["key", "name", ]
|
||||
list_display = ['key', 'name', 'active', ]
|
||||
actions = [plugin_activate, plugin_deactivate, ]
|
||||
|
||||
|
||||
admin.site.register(models.PluginConfig, PluginConfigAdmin)
|
||||
|
@ -55,13 +55,16 @@ class PluginConfig(models.Model):
|
||||
|
||||
def save(self, force_insert=False, force_update=False, *args, **kwargs):
|
||||
"""extend save method to reload plugins if the 'active' status changes"""
|
||||
reload = kwargs.pop('no_reload', False) # check if no_reload flag is set
|
||||
|
||||
ret = super().save(force_insert, force_update, *args, **kwargs)
|
||||
app = apps.get_app_config('plugin')
|
||||
|
||||
if self.active is False and self.__org_active is True:
|
||||
app.reload_plugins()
|
||||
if not reload:
|
||||
if self.active is False and self.__org_active is True:
|
||||
app.reload_plugins()
|
||||
|
||||
elif self.active is True and self.__org_active is False:
|
||||
app.reload_plugins()
|
||||
elif self.active is True and self.__org_active is False:
|
||||
app.reload_plugins()
|
||||
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user