OpenDroneMap-WebODM/plugins/test/plugin.py

51 wiersze
1.4 KiB
Python
Czysty Zwykły widok Historia

2018-07-30 15:55:46 +00:00
from rest_framework import status
from rest_framework.response import Response
2018-03-02 16:30:16 +00:00
from app.plugins import PluginBase, Menu, MountPoint
2018-07-30 15:55:46 +00:00
from app.plugins.views import TaskView
2018-03-02 16:30:16 +00:00
from django.shortcuts import render
2018-07-30 15:55:46 +00:00
from django import forms
class TestForm(forms.Form):
testField = forms.CharField(label='Test')
class TestTaskView(TaskView):
def get(self, request, pk=None):
task = self.get_and_check_task(request, pk)
return Response(task.id, status=status.HTTP_200_OK)
2018-03-02 16:30:16 +00:00
class Plugin(PluginBase):
def main_menu(self):
return [Menu("Test", self.public_url("menu_url/"), "test-icon")]
def include_js_files(self):
return ['test.js']
def include_css_files(self):
return ['test.css']
2018-07-30 15:55:46 +00:00
def build_jsx_components(self):
return ['component.jsx']
def app_mount_points(self):
2018-07-30 15:55:46 +00:00
# Show script only if '?print=1' is set
def dynamic_cb(request):
if 'print' in request.GET:
return {'name': 'WebODM'} # Test template substitution
else:
return False
2018-03-02 16:30:16 +00:00
return [
2018-07-30 15:55:46 +00:00
MountPoint('/app_mountpoint/$', lambda request: render(request, self.template_path("app.html"), {
'title': 'Test',
'test_form': TestForm()
})),
MountPoint('task/(?P<pk>[^/.]+)/', TestTaskView.as_view()),
MountPoint('/app_dynamic_script.js$', self.get_dynamic_script('dynamic.js', dynamic_cb))
2018-03-02 16:30:16 +00:00
]