Source code for geonode.management_commands_http.forms

from django import forms

from geonode.management_commands_http.models import ManagementCommandJob
from geonode.management_commands_http.utils.commands import (
    get_management_commands,
)


[docs] class ManagementCommandJobAdminForm(forms.ModelForm):
[docs] autostart = forms.BooleanField(required=False)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs] self.available_commands = get_management_commands()
self.fields["command"] = forms.ChoiceField(choices=[(command, command) for command in self.available_commands])
[docs] class Meta:
[docs] model = ManagementCommandJob
[docs] fields = ( "command", "args", "kwargs", )
[docs] def clean_args(self): value = self.cleaned_data.get("args") if not isinstance(value, list): self.add_error("args", "args must be a list") if "--help" in value: self.add_error("args", 'Forbidden argument: "--help"') return value
[docs] def clean_kwargs(self): value = self.cleaned_data.get("kwargs") if not isinstance(value, dict): self.add_error("kwargs", "kwargs must be a dict") return value