OpenDroneMap-WebODM/coreplugins/dronedb/plugin.py

88 wiersze
3.7 KiB
Python
Czysty Zwykły widok Historia

2022-01-04 17:13:15 +00:00
from app.plugins import PluginBase, Menu, MountPoint, logger
2022-01-07 18:02:01 +00:00
from coreplugins.dronedb.app_views import LoadButtonsView
from coreplugins.dronedb.ddb import DEFAULT_HUB_URL
2022-01-04 17:13:15 +00:00
2022-01-19 15:58:12 +00:00
from .api_views import (
CheckUrlTaskView,
FoldersTaskView,
ImportDatasetTaskView,
CheckCredentialsTaskView,
OrganizationsTaskView,
DatasetsTaskView,
StatusTaskView,
VerifyUrlTaskView,
InfoTaskView,
ShareTaskView
)
2022-01-13 17:39:43 +00:00
2022-01-05 14:49:33 +00:00
from django.contrib import messages
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django import forms
2022-01-04 17:13:15 +00:00
2022-01-05 14:49:33 +00:00
class SettingsForm(forms.Form):
username = forms.CharField(label='Username', required=False, max_length=1024, widget=forms.TextInput(attrs={'placeholder': 'Username'}))
password = forms.CharField(label='Password', required=False, max_length=1024, widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
2022-01-25 14:58:57 +00:00
registry_url = forms.CharField(label='Registry URL', required=False, max_length=1024, widget=forms.TextInput(attrs={'placeholder': 'Registry Url'}))
2022-01-04 17:13:15 +00:00
class Plugin(PluginBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def main_menu(self):
2022-01-24 13:34:28 +00:00
return [Menu("DroneDB", self.public_url(""), "ddb-icon fa-fw")]
2022-01-04 17:13:15 +00:00
2022-01-07 11:55:35 +00:00
def include_js_files(self):
return ["load_buttons.js"]
2022-01-04 17:13:15 +00:00
2022-01-07 11:55:35 +00:00
def include_css_files(self):
2022-01-24 13:34:28 +00:00
return ["build/ImportView.css", "style.css"]
2022-01-04 17:13:15 +00:00
2022-01-07 11:55:35 +00:00
def build_jsx_components(self):
2022-01-24 11:17:09 +00:00
return ["ImportView.jsx", "ShareButton.jsx"]
2022-01-04 17:13:15 +00:00
2022-01-07 11:55:35 +00:00
def api_mount_points(self):
return [
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/import", ImportDatasetTaskView.as_view()),
2022-01-18 16:05:39 +00:00
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/checkforurl", CheckUrlTaskView.as_view()),
2022-01-21 10:20:31 +00:00
MountPoint("tasks/(?P<pk>[^/.]+)/status", StatusTaskView.as_view()),
MountPoint("tasks/(?P<pk>[^/.]+)/share", ShareTaskView.as_view()),
2022-01-13 12:08:32 +00:00
MountPoint("checkcredentials", CheckCredentialsTaskView.as_view()),
MountPoint("organizations/(?P<org>[^/.]+)/datasets/(?P<ds>[^/.]+)/folders", FoldersTaskView.as_view()),
MountPoint("organizations/(?P<org>[^/.]+)/datasets", DatasetsTaskView.as_view()),
MountPoint("organizations", OrganizationsTaskView.as_view()),
MountPoint("verifyurl", VerifyUrlTaskView.as_view()),
2022-01-14 16:49:44 +00:00
MountPoint("info", InfoTaskView.as_view()),
2022-01-07 11:55:35 +00:00
]
2022-01-04 17:13:15 +00:00
2022-01-05 14:49:33 +00:00
def HomeView(self):
@login_required
def home(request):
ds = self.get_user_data_store(request.user)
# if this is a POST request we need to process the form data
if request.method == 'POST':
form = SettingsForm(request.POST)
if form.is_valid():
ds.set_string('registry_url', form.cleaned_data['registry_url'])
ds.set_string('username', form.cleaned_data['username'])
ds.set_string('password', form.cleaned_data['password'])
2022-01-17 14:47:37 +00:00
ds.set_string('token', None)
2022-01-05 14:49:33 +00:00
messages.success(request, 'Settings updated.')
form = SettingsForm(initial={'username': ds.get_string('username', default=""),
'password': ds.get_string('password', default=""),
2022-01-18 12:04:36 +00:00
'registry_url': ds.get_string('registry_url', default="") or DEFAULT_HUB_URL})
2022-01-05 14:49:33 +00:00
return render(request, self.template_path("app.html"), {
'title': 'DroneDB',
'form': form
})
return home
2022-01-04 17:13:15 +00:00
def app_mount_points(self):
return [
2022-01-05 14:49:33 +00:00
MountPoint("$", self.HomeView()),
2022-01-07 11:55:35 +00:00
MountPoint("load_buttons.js$", LoadButtonsView(self)),
2022-01-05 14:49:33 +00:00
]