Skip to content

Commit

Permalink
Merge branch 'master' of github.com:GeoNode/geonode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Garcia Silva committed Sep 30, 2021
2 parents 43edc47 + f60653f commit bd8de19
Show file tree
Hide file tree
Showing 27 changed files with 1,423 additions and 0 deletions.
18 changes: 18 additions & 0 deletions geonode/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6669,6 +6669,24 @@ msgstr "Invalid permission level."
msgid "Permission Denied"
msgstr "Permission Denied"

#, python-brace-format
msgid ""
"You can not start the job {job.id} because its status is \"{job.status}\"."
msgstr ""
"You can not start the job {job.id} because its status is \"{job.status}\"."

msgid "Positional Arguments"
msgstr "Positional Arguments"

msgid "JSON encoded positional arguments (Example: [\"arg1\", \"arg2\"])"
msgstr "JSON encoded positional arguments (Example: [\"arg1\", \"arg2\"])"

msgid "Keyword Arguments"
msgstr "Keyword Arguments"

msgid "JSON encoded keyword arguments (Example: {\"argument\": \"value\"})"
msgstr "JSON encoded keyword arguments (Example: {\"argument\": \"value\"})"

#~ msgid "Layer name"
#~ msgstr "Layer name"

Expand Down
18 changes: 18 additions & 0 deletions geonode/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6930,6 +6930,24 @@ msgstr "Nivel de permiso inválido."
msgid "Permission Denied"
msgstr "Permiso Denegado"

msgid "Positional Arguments"
msgstr "Argumentos posicionales"

msgid "JSON encoded positional arguments (Example: [\"arg1\", \"arg2\"])"
msgstr ""
"Argumentos posicionales codificados en formato JSON. (Ejemplo: [\"arg1\", "
"\"arg2\"])"

msgid "Keyword Arguments"
msgstr "Argumentos opcionales"

msgid "JSON encoded keyword arguments (Example: {\"argument\": \"value\"})"
msgstr ""
"Argumentos opcionales codificados en formato JSON. (Ejemplo: {\"argument\": "
"\"value\"})"

#~ msgid "Home"
#~ msgstr "Inicio"
#~ msgid "Layer name"
#~ msgstr "Nombre de la Capa"

Expand Down
18 changes: 18 additions & 0 deletions geonode/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6803,3 +6803,21 @@ msgstr "Niveau d'autorisation non valide."

msgid "Permission Denied"
msgstr "Autorisation refusée"

#, python-brace-format
msgid ""
"You can not start the job {job.id} because its status is \"{job.status}\"."
msgstr ""
"Vous ne pouvez pas démarrer le travail {job.id} car son statut est \"{job.status}\"."

msgid "Positional Arguments"
msgstr "Arguments Positionnels"

msgid "JSON encoded positional arguments (Example: [\"arg1\", \"arg2\"])"
msgstr "Arguments positionnels encodés en JSON (Exemple: [\"arg1\", \"arg2\"])"

msgid "Keyword Arguments"
msgstr "Arguments Nommés"

msgid "JSON encoded keyword arguments (Example: {\"argument\": \"value\"})"
msgstr "Arguments nommés encodés en JSON (Exemple: {\"argument\": \"valeur\"})"
18 changes: 18 additions & 0 deletions geonode/locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6669,6 +6669,24 @@ msgstr "Nível de permissão inválido."
msgid "Permission Denied"
msgstr "Permissão Negada"

#, python-brace-format
msgid ""
"You can not start the job {job.id} because its status is \"{job.status}\"."
msgstr ""
"Você não pode iniciar a tarefa {job.id} pois ela possui status \"{job.status}\"."

msgid "Positional Arguments"
msgstr "Argumentos Posicionais"

msgid "JSON encoded positional arguments (Example: [\"arg1\", \"arg2\"])"
msgstr "Argumentos posicionais codificados em JSON (Exemplo: [\"arg1\", \"arg2\"])"

msgid "Keyword Arguments"
msgstr "Argumentos de Palavras-Chave"

msgid "JSON encoded keyword arguments (Example: {\"argument\": \"value\"})"
msgstr "Argumentos de palavra-chave codificados em JSON (Exemplo: {\"argumento\": \"valor\"})"

#~ msgid "Layer name"
#~ msgstr "Nome da Camada"

Expand Down
27 changes: 27 additions & 0 deletions geonode/management_commands_http/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#########################################################################
#
# Copyright (C) 2021 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from django.apps import AppConfig


class ManagementCommandsHttpAppConfig(AppConfig):
name = "geonode.management_commands_http"
verbose_name = "Management Commands Over HTTP"


default_app_config = "geonode.management_commands_http.ManagementCommandsHttpAppConfig"
106 changes: 106 additions & 0 deletions geonode/management_commands_http/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#########################################################################
#
# Copyright (C) 2021 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from django.contrib import admin, messages
from django.forms.models import ModelForm

from geonode.management_commands_http.forms import ManagementCommandJobAdminForm
from geonode.management_commands_http.models import ManagementCommandJob
from geonode.management_commands_http.utils.jobs import (
start_task,
stop_task,
get_celery_task_meta,
)


@admin.register(ManagementCommandJob)
class ManagementCommandJobAdmin(admin.ModelAdmin):
actions = ["start", "stop"]
list_per_page = 20
list_display = (
"id",
"command",
"app_name",
"user",
"args",
"kwargs",
"created_at",
"start_time",
"end_time",
"status",
"celery_result_id",
)
list_filter = ("command", "app_name", "user")
search_fields = ("command", "app_name", "user", "celery_result_id", "output_message")

def start(self, request, queryset):
for job in queryset:
try:
start_task(job)
except ValueError as exc:
messages.error(request, str(exc))

def stop(self, request, queryset):
for job in queryset:
stop_task(job)

def celery_state(self, instance):
return get_celery_task_meta(instance).get("status")

def celery_traceback(self, instance):
return get_celery_task_meta(instance).get("traceback")

def has_module_permission(self, request):
return request.user.is_superuser

def has_delete_permission(self, request, obj=None):
return obj is not None and obj.status == ManagementCommandJob.CREATED

def save_model(self, request, obj, form, change):
obj.user = request.user
obj.save()
autostart = form.cleaned_data.get("autostart", False)
if autostart and not change:
start_task(obj)

def add_view(self, request, form_url='', extra_context=None):
self.form = ManagementCommandJobAdminForm
self.fields = ("command", "args", "kwargs", "autostart",)
self.readonly_fields = []
return super().add_view(request, form_url, extra_context)

def change_view(self, request, object_id, form_url='', extra_context=None):
self.form = ModelForm
self.fields = (
"celery_result_id",
"user",
"command",
"app_name",
"args",
"kwargs",
"created_at",
"start_time",
"end_time",
"modified_at",
"status",
"output_message",
"celery_state",
"celery_traceback",
)
self.readonly_fields = self.fields
return super().change_view(request, object_id, form_url, extra_context)
34 changes: 34 additions & 0 deletions geonode/management_commands_http/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#########################################################################
#
# Copyright (C) 2021 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from django_filters import rest_framework as filters

from geonode.management_commands_http.models import ManagementCommandJob


class ManagementCommandJobFilterSet(filters.FilterSet):
class Meta:
model = ManagementCommandJob
fields = [
"celery_result_id",
"command",
"app_name",
"status",
"user",
"user__username",
]
40 changes: 40 additions & 0 deletions geonode/management_commands_http/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django import forms

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


class ManagementCommandJobAdminForm(forms.ModelForm):
autostart = forms.BooleanField(required=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.available_commands = get_management_commands()
self.fields["command"] = forms.ChoiceField(
choices=[(command, command) for command in self.available_commands]
)

class Meta:
model = ManagementCommandJob
fields = ("command", "args", "kwargs",)

def clean_args(self):
value = self.cleaned_data.get('args')

if type(value) != list:
self.add_error("args", 'args must be a list')

if "--help" in value:
self.add_error("args", 'Forbidden argument: "--help"')

return value

def clean_kwargs(self):
value = self.cleaned_data.get('kwargs')

if type(value) != dict:
self.add_error("kwargs", 'kwargs must be a dict')

return value
18 changes: 18 additions & 0 deletions geonode/management_commands_http/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#########################################################################
#
# Copyright (C) 2021 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
18 changes: 18 additions & 0 deletions geonode/management_commands_http/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#########################################################################
#
# Copyright (C) 2021 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#########################################################################
#
# Copyright (C) 2021 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from time import sleep
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = 'It writes "pong" to stdout.'

def add_arguments(self, parser):
parser.add_argument("--sleep", nargs="?", const=1, type=float)
parser.add_argument("--force_exception", nargs="?", type=bool)

def handle(self, *args, **options):
if options["sleep"]:
seconds_to_sleep = options["sleep"]
self.stdout.write(f"Sleeping for {seconds_to_sleep} seconds...")
sleep(seconds_to_sleep)
if options["force_exception"]:
self.stdout.write(
self.style.ERROR("As requested, an exception will be raised.")
)
raise RuntimeError("User Requested Exception")
self.stdout.write(self.style.SUCCESS("pong"))
Loading

0 comments on commit bd8de19

Please sign in to comment.