Skip to content

Commit

Permalink
Define apps.py for app registration according to Django 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Jan 29, 2024
1 parent db2181d commit 04c3886
Show file tree
Hide file tree
Showing 9 changed files with 551 additions and 0 deletions.
38 changes: 38 additions & 0 deletions geonode/base/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#########################################################################
#
# Copyright (C) 2016 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
from django.utils.translation import gettext_noop as _

from geonode.notifications_helper import NotificationsAppConfigBase


class BaseAppConfig(NotificationsAppConfigBase, AppConfig):
name = "geonode.base"
NOTIFICATIONS = (
(
"request_download_resourcebase",
_("Request to download a resource"),
_("A request for downloading a resource was sent"),
),
(
"request_resource_edit",
_("Request resource change"),
_("Owner has requested permissions to modify a resource"),
),
)
58 changes: 58 additions & 0 deletions geonode/documents/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#########################################################################
#
# Copyright (C) 2016 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.utils.translation import gettext_noop as _
from geonode.notifications_helper import NotificationsAppConfigBase
from django.apps import AppConfig


class DocumentsAppConfig(NotificationsAppConfigBase, AppConfig):
name = "geonode.documents"
NOTIFICATIONS = (
(
"document_created",
_("Document Created"),
_("A Document was created"),
),
(
"document_updated",
_("Document Updated"),
_("A Document was updated"),
),
(
"document_approved",
_("Document Approved"),
_("A Document was approved by a Manager"),
),
(
"document_published",
_("Document Published"),
_("A Document was published"),
),
(
"document_deleted",
_("Document Deleted"),
_("A Document was deleted"),
),
(
"document_rated",
_("Rating for Document"),
_("A rating was given to a document"),
),
)
59 changes: 59 additions & 0 deletions geonode/geoapps/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#########################################################################
#
# Copyright (C) 2020 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
from django.utils.translation import gettext_noop as _
from geonode.notifications_helper import NotificationsAppConfigBase


class GeoNodeAppsConfig(NotificationsAppConfigBase, AppConfig):
name = "geonode.geoapps"
type = "GEONODE_APP"

NOTIFICATIONS = (
(
"geoapp_created",
_("App Created"),
_("A App was created"),
),
(
"geoapp_updated",
_("App Updated"),
_("A App was updated"),
),
(
"geoapp_approved",
_("App Approved"),
_("A App was approved by a Manager"),
),
(
"geoapp_published",
_("App Published"),
_("A App was published"),
),
(
"geoapp_deleted",
_("App Deleted"),
_("A App was deleted"),
),
(
"geoapp_rated",
_("Rating for App"),
_("A rating was given to an App"),
),
)
81 changes: 81 additions & 0 deletions geonode/geoserver/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#########################################################################
#
# Copyright (C) 2016 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/>.
#
#########################################################################

import logging
from django.conf import settings
from django.utils.translation import gettext_noop as _
from geonode.notifications_helper import NotificationsAppConfigBase
from django.apps import AppConfig


logger = logging.getLogger(__name__)


def run_setup_hooks(*args, **kwargs):
from django.db.models import signals
from geonode.layers.models import Dataset
from geonode.maps.models import MapLayer
from geonode.geoserver.signals import geoserver_pre_delete
from geonode.geoserver.signals import geoserver_pre_save_maplayer

signals.pre_delete.connect(geoserver_pre_delete, sender=Dataset)
signals.pre_save.connect(geoserver_pre_save_maplayer, sender=MapLayer)


def set_resource_links(*args, **kwargs):
from geonode.utils import set_resource_default_links
from geonode.catalogue.models import catalogue_post_save
from geonode.layers.models import Dataset

if settings.UPDATE_RESOURCE_LINKS_AT_MIGRATE:
_all_datasets = Dataset.objects.all()
for index, layer in enumerate(_all_datasets, start=1):
_lyr_name = layer.name
message = f"[{index} / {len(_all_datasets)}] Updating Dataset [{_lyr_name}] ..."
logger.debug(message)
try:
set_resource_default_links(layer, layer)
catalogue_post_save(instance=layer, sender=layer.__class__)
except Exception:
logger.exception(f"[ERROR] Dataset [{_lyr_name}] couldn't be updated")


class GeoserverAppConfig(NotificationsAppConfigBase, AppConfig):
name = "geonode.geoserver"
NOTIFICATIONS = (
(
"dataset_uploaded",
_("Dataset Uploaded"),
_("A layer was uploaded"),
),
(
"dataset_rated",
_("Rating for Dataset"),
_("A rating was given to a layer"),
),
)

def ready(self):
super().ready()
run_setup_hooks()
# Connect the post_migrate signal with the _set_resource_links
# method to update links for each resource
from django.db.models import signals

signals.post_migrate.connect(set_resource_links, sender=self)
63 changes: 63 additions & 0 deletions geonode/layers/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#########################################################################
#
# Copyright (C) 2016 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
from django.utils.translation import gettext_noop as _
from geonode.notifications_helper import NotificationsAppConfigBase


class DatasetAppConfig(NotificationsAppConfigBase, AppConfig):
name = "geonode.layers"
verbose_name = "Dataset"
verbose_name_plural = "Datasets"
NOTIFICATIONS = (
(
"dataset_created",
_("Dataset Created"),
_("A Dataset was created"),
),
(
"dataset_updated",
_("Dataset Updated"),
_("A Dataset was updated"),
),
(
"dataset_approved",
_("Dataset Approved"),
_("A Dataset was approved by a Manager"),
),
(
"dataset_published",
_("Dataset Published"),
_("A Dataset was published"),
),
(
"dataset_deleted",
_("Dataset Deleted"),
_("A Dataset was deleted"),
),
(
"dataset_rated",
_("Rating for Dataset"),
_("A rating was given to a layer"),
),
)


default_app_config = "geonode.layers.DatasetAppConfig"
59 changes: 59 additions & 0 deletions geonode/maps/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#########################################################################
#
# Copyright (C) 2016 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.utils.translation import gettext_noop as _
from geonode.notifications_helper import NotificationsAppConfigBase
from django.apps import AppConfig


class MapsAppConfig(NotificationsAppConfigBase, AppConfig):
name = "geonode.maps"
NOTIFICATIONS = (
(
"map_created",
_("Map Created"),
_("A Map was created"),
),
(
"map_updated",
_("Map Updated"),
_("A Map was updated"),
),
(
"map_approved",
_("Map Approved"),
_("A Map was approved by a Manager"),
),
(
"map_published",
_("Map Published"),
_("A Map was published"),
),
(
"map_deleted",
_("Map Deleted"),
_("A Map was deleted"),
),
(
"map_rated",
_("Rating for Map"),
_("A rating was given to a map"),
),
)
Loading

0 comments on commit 04c3886

Please sign in to comment.