Skip to content

Commit

Permalink
[Fixes GeoNode#348] Trasnform detail_url to a property and return URL…
Browse files Browse the repository at this point in the history
… depending on the client
  • Loading branch information
marthamareal committed Jul 22, 2021
1 parent e3de4d1 commit 45c50a8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
17 changes: 17 additions & 0 deletions geonode/base/migrations/0072_remove_resourcebase_detail_url.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
8 changes: 7 additions & 1 deletion geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion geonode/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion geonode/geoapps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion geonode/maps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 45c50a8

Please sign in to comment.