From 45c50a8fe71af151b4d3c67a9fc8c0a5c375760c Mon Sep 17 00:00:00 2001 From: marthamareal Date: Thu, 22 Jul 2021 15:11:01 +0300 Subject: [PATCH] [Fixes #348] Trasnform detail_url to a property and return URL depending on the client --- .../0072_remove_resourcebase_detail_url.py | 17 +++++++++++++++++ geonode/base/models.py | 8 +++++++- geonode/documents/models.py | 3 ++- geonode/geoapps/models.py | 3 ++- geonode/layers/models.py | 6 ++---- geonode/maps/models.py | 2 +- 6 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 geonode/base/migrations/0072_remove_resourcebase_detail_url.py diff --git a/geonode/base/migrations/0072_remove_resourcebase_detail_url.py b/geonode/base/migrations/0072_remove_resourcebase_detail_url.py new file mode 100644 index 00000000000..95ecc954542 --- /dev/null +++ b/geonode/base/migrations/0072_remove_resourcebase_detail_url.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.4 on 2021-07-22 10:44 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0071_remove_resourcebase_ows_url'), + ] + + operations = [ + migrations.RemoveField( + model_name='resourcebase', + name='detail_url', + ), + ] diff --git a/geonode/base/models.py b/geonode/base/models.py index aa989912159..2a34651f6ec 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -938,7 +938,6 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase): # fields necessary for the apis thumbnail_url = models.TextField(_("Thumbnail url"), null=True, blank=True) - detail_url = models.CharField(max_length=255, null=True, blank=True) rating = models.IntegerField(default=0, null=True, blank=True) created = models.DateTimeField(auto_now_add=True, null=True, blank=True) last_updated = models.DateTimeField(auto_now=True, null=True, blank=True) @@ -1062,6 +1061,10 @@ def raw_supplemental_information(self): def raw_data_quality_statement(self): return self._remove_html_tags(self.data_quality_statement) + @property + def detail_url(self): + return self.get_absolute_url() + def save(self, notify=False, *args, **kwargs): """ Send a notification when a resource is created or updated @@ -1398,6 +1401,9 @@ def keyword_csv(self): except Exception: return '' + def get_absolute_url(self): + return '' + def set_bbox_polygon(self, bbox, srid): """ Set `bbox_polygon` from bbox values. diff --git a/geonode/documents/models.py b/geonode/documents/models.py index 97d402593e3..c4ec20c9b95 100644 --- a/geonode/documents/models.py +++ b/geonode/documents/models.py @@ -28,6 +28,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey +from geonode.client.hooks import hookset from geonode.maps.models import Map from geonode.layers.models import Dataset from geonode.base.models import ResourceBase @@ -56,7 +57,7 @@ def __str__(self): return str(self.title) def get_absolute_url(self): - return reverse('document_detail', args=(self.id,)) + return hookset.document_detail_url(self) @property def name(self): diff --git a/geonode/geoapps/models.py b/geonode/geoapps/models.py index a1ffc3cc630..89570c4f1a4 100644 --- a/geonode/geoapps/models.py +++ b/geonode/geoapps/models.py @@ -25,6 +25,7 @@ from guardian.shortcuts import get_anonymous_user from geonode.base.models import ResourceBase +from geonode.client.hooks import hookset logger = logging.getLogger("geonode.geoapps.models") @@ -115,7 +116,7 @@ def keywords_list(self): return [] def get_absolute_url(self): - return reverse('geoapp_detail', None, [str(self.id)]) + return hookset.geoapp_detail_url(self) @property def embed_url(self): diff --git a/geonode/layers/models.py b/geonode/layers/models.py index 94f4303fa72..58c3e3bc1bb 100644 --- a/geonode/layers/models.py +++ b/geonode/layers/models.py @@ -27,6 +27,7 @@ from tinymce.models import HTMLField +from geonode.client.hooks import hookset from geonode.utils import check_shp_columnnames from geonode.security.models import PermissionLevelMixin from geonode.base.models import ( @@ -267,10 +268,7 @@ def get_base_file(self): return base_files.get(), list_col def get_absolute_url(self): - return reverse( - 'dataset_detail', - args=(f"{self.store}:{self.alternate}",) - ) + return hookset.dataset_detail_url(self) @property def embed_url(self): diff --git a/geonode/maps/models.py b/geonode/maps/models.py index 8c0d99cb5c7..9ce98cc6699 100644 --- a/geonode/maps/models.py +++ b/geonode/maps/models.py @@ -243,7 +243,7 @@ def keyword_list(self): return [] def get_absolute_url(self): - return reverse('map_detail', None, [str(self.id)]) + return hookset.map_detail_url(self) @property def embed_url(self):