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 23, 2021
1 parent e3de4d1 commit d8e07bd
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 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
6 changes: 1 addition & 5 deletions geonode/geoapps/migrations/0003_update_detail_url.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from django.db import migrations
from django.db.models import Value
from django.db.models.functions import Concat
from django.db.migrations.operations import RunPython

from geonode.geoapps.models import GeoApp


def update_geoapps_detail_url(apps, schema_editor):
GeoApp.objects.update(detail_url=Concat(Value('/apps/'), 'id'))
pass


class Migration(migrations.Migration):
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
2 changes: 0 additions & 2 deletions geonode/resource/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ def metadata_post_save(instance, *args, **kwargs):
instance.license = license[0]

instance.thumbnail_url = instance.get_thumbnail_url()
instance.detail_url = instance.get_absolute_url()
instance.csw_insert_date = datetime.datetime.now(timezone.get_current_timezone())
instance.set_missing_info()

Expand All @@ -412,7 +411,6 @@ def metadata_post_save(instance, *args, **kwargs):
alternate=instance.alternate,
bbox_polygon=instance.bbox_polygon,
thumbnail_url=instance.get_thumbnail_url(),
detail_url=instance.get_absolute_url(),
csw_insert_date=datetime.datetime.now(timezone.get_current_timezone())
)

Expand Down
6 changes: 0 additions & 6 deletions geonode/thumbs/tests/fixtures/resource_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"is_published":true,
"is_approved":true,
"thumbnail_url":"http://localhost:8000/uploaded/thumbs/layer-2062a8d0-8000-11eb-bb7a-bfe60c5757ad-thumb.png?v=a20a765c",
"detail_url":"/datasets/geonode_data:geonode:theaters_nyc",
"rating":0,
"created":"2021-03-08T11:19:19.705Z",
"last_updated":"2021-03-08T11:20:19.632Z",
Expand Down Expand Up @@ -111,7 +110,6 @@
"is_published":true,
"is_approved":true,
"thumbnail_url":"http://localhost:8000/uploaded/thumbs/map-5d9349f8-8000-11eb-bb7a-bfe60c5757ad-thumb.png",
"detail_url":"/maps/2",
"rating":0,
"created":"2021-03-08T11:21:01.938Z",
"last_updated":"2021-03-08T11:21:02.430Z",
Expand Down Expand Up @@ -177,7 +175,6 @@
"is_published":true,
"is_approved":true,
"thumbnail_url":null,
"detail_url":null,
"rating":0,
"created":"2021-03-08T12:13:13.630Z",
"last_updated":"2021-03-08T12:13:13.630Z",
Expand Down Expand Up @@ -243,7 +240,6 @@
"is_published":true,
"is_approved":true,
"thumbnail_url":"http://localhost:8000/uploaded/thumbs/layer-ff18956a-8007-11eb-bb7a-bfe60c5757ad-thumb.png?v=0116247d",
"detail_url":"/datasets/geonode_data:geonode:Meteorite_Landings_from_NASA_Open_Data_Portal1",
"rating":0,
"created":"2021-03-08T12:15:39.793Z",
"last_updated":"2021-03-08T12:15:49.726Z",
Expand Down Expand Up @@ -309,7 +305,6 @@
"is_published":true,
"is_approved":true,
"thumbnail_url":"/static/geonode/img/missing_thumb.png",
"detail_url":"/datasets/httpwww502regionetoscanaitwmsrastercomrtwmsrtmapwmsmapwmsgeologiamap_resolution91:rt_geologia.dbg_risorse_minerarie",
"rating":0,
"created":"2021-03-08T12:20:29.973Z",
"last_updated":"2021-03-08T12:20:29.973Z",
Expand Down Expand Up @@ -375,7 +370,6 @@
"is_published":true,
"is_approved":true,
"thumbnail_url":"/static/geonode/img/missing_thumb.png",
"detail_url":"/maps/9",
"rating":0,
"created":"2021-03-08T12:24:40.617Z",
"last_updated":"2021-03-08T12:24:41.447Z",
Expand Down

0 comments on commit d8e07bd

Please sign in to comment.