OpenDroneMap-WebODM/app/plugins/views.py

60 wiersze
2.4 KiB
Python
Czysty Zwykły widok Historia

import os
2018-07-30 15:55:46 +00:00
from app.api.tasks import TaskNestedView as TaskView
2020-01-17 18:19:03 +00:00
from app.api.workers import CheckTask as CheckTask
from app.api.workers import GetTaskResult as GetTaskResult
from django.http import HttpResponse, Http404
from .functions import get_plugin_by_name
from django.conf.urls import url
from django.views.static import serve
def try_resolve_url(request, url):
res = url.resolve(request.get_full_path())
if res:
return res
else:
return (None, None, None)
def app_view_handler(request, plugin_name=None):
plugin = get_plugin_by_name(plugin_name) # TODO: this pings the server, which might be bad for performance with very large amount of files
if plugin is None:
raise Http404("Plugin not found")
# Try mountpoints first
for mount_point in plugin.app_mount_points():
view, args, kwargs = try_resolve_url(request, url(r'^/plugins/{}/{}'.format(plugin_name, mount_point.url),
mount_point.view,
*mount_point.args,
**mount_point.kwargs))
if view:
return view(request, *args, **kwargs)
# Try public assets
if os.path.exists(plugin.get_path("public")):
view, args, kwargs = try_resolve_url(request, url('^/plugins/{}/(.*)'.format(plugin_name),
serve,
{'document_root': plugin.get_path("public")}))
if view:
return view(request, *args, **kwargs)
raise Http404("No valid routes")
def api_view_handler(request, plugin_name=None):
plugin = get_plugin_by_name(plugin_name) # TODO: this pings the server, which might be bad for performance with very large amount of files
if plugin is None:
raise Http404("Plugin not found")
for mount_point in plugin.api_mount_points():
view, args, kwargs = try_resolve_url(request, url(r'^/api/plugins/{}/{}'.format(plugin_name, mount_point.url),
mount_point.view,
*mount_point.args,
**mount_point.kwargs))
if view:
return view(request, *args, **kwargs)
raise Http404("No valid routes")