zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from rest_framework import status
from rest_framework.response import Response
 
from app.plugins import PluginBase, Menu, MountPoint, get_current_plugin
from app.plugins.views import TaskView
from django.shortcuts import render
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)
 
 
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']
 
    def build_jsx_components(self):
        return ['component.jsx']
 
    def app_mount_points(self):
        # 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
 
        return [
            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))
        ]
 
    def get_current_plugin_test(self):
        return get_current_plugin()