Skip to content

Commit

Permalink
Backport from master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Fabiani committed Jun 12, 2018
1 parent 304ac29 commit 75baa8f
Show file tree
Hide file tree
Showing 31 changed files with 282 additions and 166 deletions.
3 changes: 1 addition & 2 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ def filter_bbox(self, queryset, bbox):
northeast_lng,northeast_lat'
returns the modified query
"""
bbox = bbox.split(
',') # TODO: Why is this different when done through haystack?
bbox = bbox.split(',') # TODO: Why is this different when done through haystack?
bbox = map(str, bbox) # 2.6 compat - float to decimal conversion
intersects = ~(Q(bbox_x0__gt=bbox[2]) | Q(bbox_x1__lt=bbox[0]) |
Q(bbox_y0__gt=bbox[3]) | Q(bbox_y1__lt=bbox[1]))
Expand Down
40 changes: 40 additions & 0 deletions geonode/base/management/commands/set_all_layers_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2017 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.core.management.base import BaseCommand
from geonode.layers.models import Layer
from geonode.catalogue.models import catalogue_post_save


class Command(BaseCommand):
"""Resets Permissions to Public for All Layers
"""

def handle(self, *args, **options):
all_layers = Layer.objects.all()

for index, layer in enumerate(all_layers):
print "[%s / %s] Updating Layer [%s] ..." % ((index + 1), len(all_layers), layer.name)
try:
catalogue_post_save(instance=layer, sender=layer.__class__)
except:
# import traceback
# traceback.print_exc()
print "[ERROR] Layer [%s] couldn't be updated" % (layer.name)
12 changes: 9 additions & 3 deletions geonode/base/management/commands/updategeoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
URL = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz'
OLD_FORMAT = False
except ImportError:
from django.contrib.gis.geoip import GeoIP
URL = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'
OLD_FORMAT = True
try:
from django.contrib.gis.geoip import GeoIP
URL = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'
OLD_FORMAT = True
except:
URL = None


class Command(BaseCommand):
Expand All @@ -54,6 +57,9 @@ def add_arguments(self, parser):
help=_("Overwrite file if exists"))

def handle(self, *args, **options):
if not settings.MONITORING_ENABLED or not URL:
return

fname = options['file']
fbase = '.'.join(os.path.basename(options['url']).split('.')[:-1])
if not options['overwrite'] and os.path.exists(fname):
Expand Down
55 changes: 51 additions & 4 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,34 @@ def __unicode__(self):
def get_upload_session(self):
raise NotImplementedError()

@property
def creator(self):
return self.owner.get_full_name() or self.owner.username

@property
def organizationname(self):
return self.owner.organization

@property
def restriction_code(self):
return self.restriction_code_type.gn_description

@property
def publisher(self):
return self.poc.get_full_name() or self.poc.username

@property
def contributor(self):
return self.metadata_author.get_full_name() or self.metadata_author.username

@property
def topiccategory(self):
return self.category.identifier

@property
def csw_crs(self):
return self.srid

@property
def group_name(self):
if self.group:
Expand All @@ -784,6 +812,24 @@ def bbox(self):
self.bbox_y1,
self.srid]

@property
def ll_bbox(self):
"""BBOX is in the format: [x0,x1,y0,y1]."""
from geonode.utils import bbox_to_projection
llbbox = self.bbox[0:4]
if self.srid and 'EPSG:' in self.srid:
try:
llbbox = bbox_to_projection([float(coord) for coord in llbbox] + [self.srid, ],
target_srid=4326)
except BaseException:
pass
return [
llbbox[0], # x0
llbbox[1], # x1
llbbox[2], # y0
llbbox[3], # y1
self.srid]

@property
def bbox_string(self):
"""BBOX is in the format: [x0,y0,x1,y1]."""
Expand All @@ -793,11 +839,12 @@ def bbox_string(self):
@property
def geographic_bounding_box(self):
"""BBOX is in the format: [x0,x1,y0,y1]."""
llbbox = self.ll_bbox[0:4]
return bbox_to_wkt(
self.bbox_x0,
self.bbox_x1,
self.bbox_y0,
self.bbox_y1,
llbbox[0], # x0
llbbox[1], # x1
llbbox[2], # y0
llbbox[3], # y1
srid=self.srid)

@property
Expand Down
4 changes: 2 additions & 2 deletions geonode/catalogue/backends/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def csw_gen_xml(self, layer, template):
id_pname = 'dc:identifier'
if self.type == 'deegree':
id_pname = 'apiso:Identifier'

site_url = settings.SITEURL[:-1] if settings.SITEURL.endswith("/") else settings.SITEURL
tpl = get_template(template)
ctx = {'layer': layer,
'SITEURL': settings.SITEURL[:-1],
'SITEURL': site_url,
'id_pname': id_pname,
'LICENSES_METADATA': getattr(settings,
'LICENSES',
Expand Down
4 changes: 2 additions & 2 deletions geonode/catalogue/backends/pycsw_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
# 'loglevel': 'DEBUG',
# 'logfile': '/tmp/pycsw.log',
# 'federatedcatalogues': 'http://geo.data.gov/geoportal/csw/discovery',
# 'pretty_print': 'true',
# 'domainquerytype': 'range',
'pretty_print': 'true',
'domainquerytype': 'range',
'domaincounts': 'true',
'profiles': 'apiso,ebrim',
},
Expand Down
11 changes: 6 additions & 5 deletions geonode/catalogue/backends/pycsw_local_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@
'pycsw:Modified': 'date',
'pycsw:Type': 'csw_type',
'pycsw:BoundingBox': 'csw_wkt_geometry',
'pycsw:CRS': 'crs',
'pycsw:CRS': 'csw_crs',
'pycsw:AlternateTitle': 'alternate',
'pycsw:RevisionDate': 'date',
'pycsw:CreationDate': 'date',
'pycsw:PublicationDate': 'date',
'pycsw:OrganizationName': 'uuid',
'pycsw:Organization': 'organizationname',
'pycsw:OrganizationName': 'organizationname',
'pycsw:SecurityConstraints': 'securityconstraints',
'pycsw:ParentIdentifier': 'parentidentifier',
'pycsw:TopicCategory': 'topiccategory',
'pycsw:ResourceLanguage': 'resourcelanguage',
'pycsw:ResourceLanguage': 'language',
'pycsw:GeographicDescriptionCode': 'geodescode',
'pycsw:Denominator': 'denominator',
'pycsw:DistanceValue': 'distancevalue',
Expand All @@ -64,8 +65,8 @@
'pycsw:OperatesOnIdentifier': 'operatesonidentifier',
'pycsw:OperatesOnName': 'operatesoname',
'pycsw:Degree': 'degree',
'pycsw:AccessConstraints': 'accessconstraints',
'pycsw:OtherConstraints': 'otherconstraints',
'pycsw:AccessConstraints': 'restriction_code',
'pycsw:OtherConstraints': 'constraints_other',
'pycsw:Classification': 'classification',
'pycsw:ConditionApplyingToAccessAndUse': 'conditionapplyingtoaccessanduse',
'pycsw:Lineage': 'lineage',
Expand Down
6 changes: 2 additions & 4 deletions geonode/catalogue/backends/pycsw_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,13 @@ def query(self, constraint, sortby=None, typenames=None,
# search engine
if 'where' in constraint: # GetRecords with constraint
query = self._get_repo_filter(
Layer.objects).filter(
is_published=True).extra(
Layer.objects).filter(alternate__isnull=False).extra(
where=[
constraint['where']],
params=constraint['values'])
else: # GetRecords sans constraint
query = self._get_repo_filter(
Layer.objects).filter(
is_published=True)
Layer.objects).filter(alternate__isnull=False)

total = query.count()

Expand Down
8 changes: 4 additions & 4 deletions geonode/catalogue/templates/catalogue/full_metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,16 @@
<gmd:geographicElement>
<gmd:EX_GeographicBoundingBox>
<gmd:westBoundLongitude>
<gco:Decimal>{{layer.bbox_x0}}</gco:Decimal>
<gco:Decimal>{{layer.ll_bbox.0}}</gco:Decimal>
</gmd:westBoundLongitude>
<gmd:eastBoundLongitude>
<gco:Decimal>{{layer.bbox_x1}}</gco:Decimal>
<gco:Decimal>{{layer.ll_bbox.1}}</gco:Decimal>
</gmd:eastBoundLongitude>
<gmd:southBoundLatitude>
<gco:Decimal>{{layer.bbox_y0}}</gco:Decimal>
<gco:Decimal>{{layer.ll_bbox.2}}</gco:Decimal>
</gmd:southBoundLatitude>
<gmd:northBoundLatitude>
<gco:Decimal>{{layer.bbox_y1}}</gco:Decimal>
<gco:Decimal>{{layer.ll_bbox.3}}</gco:Decimal>
</gmd:northBoundLatitude>
</gmd:EX_GeographicBoundingBox>
</gmd:geographicElement>
Expand Down
8 changes: 4 additions & 4 deletions geonode/catalogue/templates/geonode_metadata_full.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ <h2 class="page-title">{{ resource.title }}</h2>
<dt>Extent</dt>
<dd>
<ul class="nop">
<li>long min: {{resource.bbox_x0}}</li>
<li>long max: {{resource.bbox_x1}}</li>
<li>lat min: {{resource.bbox_y0}}</li>
<li>lat max: {{resource.bbox_y1}}</li>
<li>x0: {{resource.bbox_x0}}</li>
<li>x1: {{resource.bbox_x1}}</li>
<li>y0: {{resource.bbox_y0}}</li>
<li>y1: {{resource.bbox_y1}}</li>
</ul>
</dd>

Expand Down
7 changes: 5 additions & 2 deletions geonode/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def csw_global_dispatch(request):
for e in authorized_ids)) + ")"
authorized_layers_filter = "id IN " + authorized_layers
mdict['repository']['filter'] += " AND " + authorized_layers_filter
if request.user and request.user.is_authenticated():
mdict['repository']['filter'] = "({}) OR ({})".format(mdict['repository']['filter'],
authorized_layers_filter)
else:
authorized_layers_filter = "id = -9999"
mdict['repository']['filter'] += " AND " + authorized_layers_filter
Expand All @@ -108,7 +111,7 @@ def csw_global_dispatch(request):

if not is_admin and settings.GROUP_PRIVATE_RESOURCES:
groups_ids = []
if request.user:
if request.user and request.user.is_authenticated():
for group in request.user.groups.all():
groups_ids.append(group.id)
group_list_all = []
Expand All @@ -124,7 +127,7 @@ def csw_global_dispatch(request):
groups_ids.append(group.id)

public_groups = GroupProfile.objects.exclude(
access="private").exclude(access="public-invite").values('group')
access="private").values('group')
for group in public_groups:
if isinstance(group, dict):
if 'group' in group:
Expand Down
4 changes: 3 additions & 1 deletion geonode/contrib/metadataxsl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#
#########################################################################

from urlparse import urljoin

from django.conf import settings
from django.core.urlresolvers import reverse
from django.db.models import signals
Expand Down Expand Up @@ -45,7 +47,7 @@ def add_xsl_link(resourcebase):

urlpath = reverse('prefix_xsl_line', args=[resourcebase.id])

url = '{}{}'.format(settings.SITEURL, urlpath)
url = urljoin(settings.SITEURL, urlpath)

link, created = Link.objects.get_or_create(
resource=resourcebase,
Expand Down
3 changes: 2 additions & 1 deletion geonode/contrib/metadataxsl/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ def prefix_xsl_line(req, id):
try:
catalogue = get_catalogue()
record = catalogue.get_record(resource.uuid)
if record:
logger.debug(record.xml)
except Exception as err:
msg = 'Could not connect to catalogue to save information for layer "%s"' % str(resource.title)
logger.warn(msg)
raise err

try:
xml = record.xml
# generate an XML document (GeoNode's default is ISO)
if resource.metadata_uploaded and resource.metadata_uploaded_preserve:
md_doc = etree.tostring(etree.fromstring(resource.metadata_xml))
Expand Down
5 changes: 4 additions & 1 deletion geonode/contrib/monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
try:
from django.contrib.gis.geoip2 import GeoIP2 as GeoIP
except ImportError:
from django.contrib.gis.geoip import GeoIP
try:
from django.contrib.gis.geoip import GeoIP
except ImportError:
pass

import user_agents
from ipware import get_client_ip
Expand Down

0 comments on commit 75baa8f

Please sign in to comment.