kopia lustrzana https://github.com/OpenDroneMap/WebODM
commit
95977a55ba
43
app/admin.py
43
app/admin.py
|
@ -25,13 +25,22 @@ from django.utils.translation import gettext_lazy as _, gettext
|
||||||
|
|
||||||
admin.site.register(Project, GuardedModelAdmin)
|
admin.site.register(Project, GuardedModelAdmin)
|
||||||
|
|
||||||
|
|
||||||
class TaskAdmin(admin.ModelAdmin):
|
class TaskAdmin(admin.ModelAdmin):
|
||||||
def has_add_permission(self, request):
|
def has_add_permission(self, request):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
list_display = ('id', 'project', 'processing_node', 'created_at', 'status', 'last_error')
|
||||||
|
list_filter = ('status', 'project',)
|
||||||
|
search_fields = ('id', 'project__name')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Task, TaskAdmin)
|
admin.site.register(Task, TaskAdmin)
|
||||||
|
|
||||||
|
|
||||||
class ImageUploadAdmin(admin.ModelAdmin):
|
class ImageUploadAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ('image',)
|
readonly_fields = ('image',)
|
||||||
|
|
||||||
admin.site.register(ImageUpload, ImageUploadAdmin)
|
admin.site.register(ImageUpload, ImageUploadAdmin)
|
||||||
|
|
||||||
admin.site.register(Preset, admin.ModelAdmin)
|
admin.site.register(Preset, admin.ModelAdmin)
|
||||||
|
@ -39,12 +48,12 @@ admin.site.register(Preset, admin.ModelAdmin)
|
||||||
|
|
||||||
class SettingAdmin(admin.ModelAdmin):
|
class SettingAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
def has_add_permission(self, request):
|
||||||
# if there's already an entry, do not allow adding
|
# if there's already an entry, do not allow adding
|
||||||
count = Setting.objects.all().count()
|
count = Setting.objects.all().count()
|
||||||
return count == 0
|
return count == 0
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Setting, SettingAdmin)
|
admin.site.register(Setting, SettingAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +74,8 @@ class ThemeModelForm(forms.ModelForm):
|
||||||
label=_("HTML (after body)"),
|
label=_("HTML (after body)"),
|
||||||
required=False,
|
required=False,
|
||||||
widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
|
widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
|
||||||
html_footer = forms.CharField(help_text=_("HTML that will be displayed in the footer. You can also use the special tags such as {ORGANIZATION} and {YEAR}."),
|
html_footer = forms.CharField(help_text=_(
|
||||||
|
"HTML that will be displayed in the footer. You can also use the special tags such as {ORGANIZATION} and {YEAR}."),
|
||||||
label=_("HTML (footer)"),
|
label=_("HTML (footer)"),
|
||||||
required=False,
|
required=False,
|
||||||
widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
|
widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
|
||||||
|
@ -85,11 +95,12 @@ admin.site.register(PluginDatum, admin.ModelAdmin)
|
||||||
|
|
||||||
class PluginAdmin(admin.ModelAdmin):
|
class PluginAdmin(admin.ModelAdmin):
|
||||||
list_display = ("name", "description", "version", "author", "enabled", "plugin_actions")
|
list_display = ("name", "description", "version", "author", "enabled", "plugin_actions")
|
||||||
readonly_fields = ("name", )
|
readonly_fields = ("name",)
|
||||||
change_list_template = "admin/change_list_plugin.html"
|
change_list_template = "admin/change_list_plugin.html"
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
def has_add_permission(self, request):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def has_delete_permission(self, request, obj=None):
|
def has_delete_permission(self, request, obj=None):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -141,9 +152,11 @@ class PluginAdmin(admin.ModelAdmin):
|
||||||
try:
|
try:
|
||||||
p = enable_plugin(plugin_name)
|
p = enable_plugin(plugin_name)
|
||||||
if p.requires_restart():
|
if p.requires_restart():
|
||||||
messages.warning(request, _("Restart required. Please restart WebODM to enable %(plugin)s") % {'plugin': plugin_name})
|
messages.warning(request, _("Restart required. Please restart WebODM to enable %(plugin)s") % {
|
||||||
|
'plugin': plugin_name})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
messages.warning(request, _("Cannot enable plugin %(plugin)s: %(message)s") % {'plugin': plugin_name, 'message': str(e)})
|
messages.warning(request, _("Cannot enable plugin %(plugin)s: %(message)s") % {'plugin': plugin_name,
|
||||||
|
'message': str(e)})
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
||||||
|
|
||||||
|
@ -151,9 +164,11 @@ class PluginAdmin(admin.ModelAdmin):
|
||||||
try:
|
try:
|
||||||
p = disable_plugin(plugin_name)
|
p = disable_plugin(plugin_name)
|
||||||
if p.requires_restart():
|
if p.requires_restart():
|
||||||
messages.warning(request, _("Restart required. Please restart WebODM to fully disable %(plugin)s") % {'plugin': plugin_name})
|
messages.warning(request, _("Restart required. Please restart WebODM to fully disable %(plugin)s") % {
|
||||||
|
'plugin': plugin_name})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
messages.warning(request, _("Cannot disable plugin %(plugin)s: %(message)s") % {'plugin': plugin_name, 'message': str(e)})
|
messages.warning(request, _("Cannot disable plugin %(plugin)s: %(message)s") % {'plugin': plugin_name,
|
||||||
|
'message': str(e)})
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
||||||
|
|
||||||
|
@ -161,7 +176,8 @@ class PluginAdmin(admin.ModelAdmin):
|
||||||
try:
|
try:
|
||||||
delete_plugin(plugin_name)
|
delete_plugin(plugin_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
messages.warning(request, _("Cannot delete plugin %(plugin)s: %(message)s") % {'plugin': plugin_name, 'message': str(e)})
|
messages.warning(request, _("Cannot delete plugin %(plugin)s: %(message)s") % {'plugin': plugin_name,
|
||||||
|
'message': str(e)})
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
||||||
|
|
||||||
|
@ -193,10 +209,13 @@ class PluginAdmin(admin.ModelAdmin):
|
||||||
plugin_name = folders[0]
|
plugin_name = folders[0]
|
||||||
plugin_path = os.path.join(tmp_extract_path, plugin_name)
|
plugin_path = os.path.join(tmp_extract_path, plugin_name)
|
||||||
if not valid_plugin(plugin_path):
|
if not valid_plugin(plugin_path):
|
||||||
raise ValueError("This doesn't look like a plugin. Are plugin.py and manifest.json in the proper place?")
|
raise ValueError(
|
||||||
|
"This doesn't look like a plugin. Are plugin.py and manifest.json in the proper place?")
|
||||||
|
|
||||||
if os.path.exists(get_plugins_persistent_path(plugin_name)):
|
if os.path.exists(get_plugins_persistent_path(plugin_name)):
|
||||||
raise ValueError("A plugin with the name {} already exist. Please remove it before uploading one with the same name.".format(plugin_name))
|
raise ValueError(
|
||||||
|
"A plugin with the name {} already exist. Please remove it before uploading one with the same name.".format(
|
||||||
|
plugin_name))
|
||||||
|
|
||||||
# Move
|
# Move
|
||||||
shutil.move(plugin_path, get_plugins_persistent_path())
|
shutil.move(plugin_path, get_plugins_persistent_path())
|
||||||
|
@ -217,13 +236,13 @@ class PluginAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
return HttpResponseRedirect(reverse('admin:app_plugin_changelist'))
|
||||||
|
|
||||||
|
|
||||||
def plugin_actions(self, obj):
|
def plugin_actions(self, obj):
|
||||||
plugin = get_plugin_by_name(obj.name, only_active=False)
|
plugin = get_plugin_by_name(obj.name, only_active=False)
|
||||||
return format_html(
|
return format_html(
|
||||||
'<a class="button" href="{}" {}>{}</a> '
|
'<a class="button" href="{}" {}>{}</a> '
|
||||||
'<a class="button" href="{}" {}>{}</a>'
|
'<a class="button" href="{}" {}>{}</a>'
|
||||||
+ (' <a class="button" href="{}" onclick="return confirm(\'Are you sure you want to delete {}?\')"><i class="fa fa-trash"></i></a>' if not plugin.is_persistent() else ' ')
|
+ (
|
||||||
|
' <a class="button" href="{}" onclick="return confirm(\'Are you sure you want to delete {}?\')"><i class="fa fa-trash"></i></a>' if not plugin.is_persistent() else ' ')
|
||||||
,
|
,
|
||||||
reverse('admin:plugin-disable', args=[obj.pk]) if obj.enabled else '#',
|
reverse('admin:plugin-disable', args=[obj.pk]) if obj.enabled else '#',
|
||||||
'disabled' if not obj.enabled else '',
|
'disabled' if not obj.enabled else '',
|
||||||
|
|
Ładowanie…
Reference in New Issue