OpenDroneMap-WebODM/coreplugins/cloudimport/app_views.py

66 wiersze
2.1 KiB
Python
Czysty Zwykły widok Historia

2019-08-29 02:16:39 +00:00
import requests
from django import forms
from django.contrib import messages
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from app.plugins import logger
from .platform_helper import get_all_extended_platforms
class DynamicForm(forms.Form):
2019-08-29 03:28:39 +00:00
"""This dynamic form will go through all the extended platforms, and retrieve their fields"""
2019-08-29 02:16:39 +00:00
def __init__(self, *args, **kwargs):
ds = kwargs.pop('data_store')
super(DynamicForm, self).__init__(*args, **kwargs)
extended_platforms = get_all_extended_platforms()
for platform in extended_platforms:
for form_field in platform.get_form_fields():
django_field = form_field.get_django_field(ds)
django_field.group = platform.name
self.fields[form_field.field_id] = django_field
def HomeView(plugin):
@login_required
def view(request):
ds = plugin.get_user_data_store(request.user)
# if this is a POST request we need to process the form data
if request.method == "POST":
form = DynamicForm(request.POST, data_store = ds)
if form.is_valid():
extended_platforms = get_all_extended_platforms()
for platform in extended_platforms:
for form_field in platform.get_form_fields():
form_field.save_value(ds, form)
messages.success(request, "Configuration updated successfuly!")
2019-08-31 16:26:29 +00:00
else:
form = DynamicForm(data_store = ds)
2019-08-29 02:16:39 +00:00
return render(
request,
plugin.template_path("app.html"),
{"title": "Cloud Import", "form": form},
)
return view
def LoadButtonsView(plugin):
2019-08-29 02:16:39 +00:00
def view(request):
return render(
request,
plugin.template_path("load_buttons.js"),
{
"api_url": "/api" + plugin.public_url("").rstrip("/"),
},
content_type="text/javascript",
)
return view