Source code for geonode.maps.admin

#########################################################################
#
# 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 import forms
from django.contrib import admin

from modeltranslation.admin import TabbedTranslationAdmin

from geonode.maps.models import Map, MapLayer
from geonode.base.admin import ResourceBaseAdminForm
from geonode.base.admin import metadata_batch_edit


[docs] class MapLayerInline(admin.TabularInline):
[docs] model = MapLayer
[docs] ordering = ("dataset_id",)
[docs] autocomplete_fields = ("dataset",)
[docs] class MapAdminForm(ResourceBaseAdminForm):
[docs] class Meta(ResourceBaseAdminForm.Meta):
[docs] model = Map
[docs] fields = "__all__"
[docs] class MapAdmin(TabbedTranslationAdmin):
[docs] inlines = [ MapLayerInline, ]
[docs] exclude = ("ll_bbox_polygon", "bbox_polygon", "srid")
[docs] list_display = ( "id", "title", "owner", "category", "group", "is_approved", "is_published", "featured", )
[docs] list_editable = ( "owner", "category", "group", "is_approved", "is_published", "featured", )
[docs] list_filter = ( "owner", "category", "group", "featured", "is_approved", "is_published", )
[docs] search_fields = ( "title", "abstract", "purpose", "is_approved", "is_published", )
[docs] readonly_fields = ("geographic_bounding_box",)
[docs] form = MapAdminForm
[docs] actions = [metadata_batch_edit]
[docs] def delete_queryset(self, request, queryset): """ We need to invoke the 'ResourceBase.delete' method even when deleting through the admin batch action """ for obj in queryset: from geonode.resource.manager import resource_manager resource_manager.delete(obj.uuid, instance=obj)
[docs] class MapLayerAdmin(admin.ModelAdmin):
[docs] list_display = ("id", "map", "name")
[docs] list_filter = ("map",)
[docs] search_fields = ( "map__title", "name", )
[docs] autocomplete_fields = ("dataset",)
[docs] form = forms.modelform_factory(MapLayer, fields="__all__")
admin.site.register(Map, MapAdmin) admin.site.register(MapLayer, MapLayerAdmin)