Skip to content

Commit

Permalink
Merge branch 'cartologic:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef-Harby committed Jul 10, 2022
2 parents dd65e88 + e746e12 commit c62f946
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 356 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ addons:
services:
- postgresql
python:
- '3.8'
- '3.10'
env:
global:
- CARTOVIEW_TEST=True
- DATABASE_URL=postgis://cartoview:cartoview@localhost:5432/cartoview
- DATASTORE_DATABASE_URL=postgis://cartoview:cartoview@localhost:5432/cartoview_data
virtualenv:
system_site_packages: false
branches:
Expand Down Expand Up @@ -65,6 +67,7 @@ before_script:
- psql -U postgres -c "create extension postgis"
- chmod +x scripts/database/setup.sh
- scripts/database/setup.sh
- python manage.py collectstatic --no-input
script:
- flake8
- paver run_cartoview_test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8.9
FROM python:3.10.2-buster
LABEL "MAINTAINER"="Cartologic Development Team"

ENV PYTHONUNBUFFERED 1
Expand Down
2 changes: 1 addition & 1 deletion cartoview/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = (1, 33, 1, 'unstable', 0)
__version__ = (1, 40, 0, 'unstable', 0)
__compatible_with__ = []


Expand Down
4 changes: 2 additions & 2 deletions cartoview/app_manager/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from future import standard_library
from geonode.groups.models import Group
from geonode.maps.models import Layer, Map
from geonode.maps.models import Dataset, Map
from geonode.people.models import Profile
from geonode.version import get_version
from guardian.shortcuts import get_objects_for_user
Expand All @@ -27,7 +27,7 @@ def cartoview_processor(request):
"apps": App.objects.count(),
"app_instances": AppInstance.objects.filter(id__in=permitted).count(),
"maps": Map.objects.filter(id__in=permitted).count(),
"layers": Layer.objects.filter(id__in=permitted).count(),
"layers": Dataset.objects.filter(id__in=permitted).count(),
"users": Profile.objects.exclude(username="AnonymousUser").count(),
"groups": Group.objects.exclude(name="anonymous").count()
}
Expand Down
5 changes: 3 additions & 2 deletions cartoview/app_manager/migrations/0006_app_default_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import jsonfield.fields
#import jsonfield.fields
from django.db import migrations
from django.db.models import JSONField


class Migration(migrations.Migration):
Expand All @@ -14,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='app',
name='default_config',
field=jsonfield.fields.JSONField(default={}),
field=JSONField(default={}),
),
]
36 changes: 6 additions & 30 deletions cartoview/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
from datetime import datetime

from django.conf import settings as geonode_settings
from django.contrib.auth.models import Group
from django.contrib.gis.db import models
from django.urls import reverse
from django.db.models import signals
from django.db.models import signals, JSONField
from django.template.defaultfilters import slugify
from django.utils.encoding import python_2_unicode_compatible
from future import standard_library
from geonode.base.models import ResourceBase, resourcebase_post_save
from geonode.base.models import ResourceBase
from geonode.maps.models import Map as GeonodeMap
from geonode.security.models import remove_object_permissions
from guardian.shortcuts import assign_perm
from jsonfield import JSONField
from geonode.resource.utils import resourcebase_post_save

from taggit.managers import TaggableManager

from cartoview.apps_handler.config import CartoviewApp
Expand All @@ -32,7 +29,6 @@ def without_apps_duplication(self):
return super(AppTypeManager, self).get_queryset().distinct('apps')


@python_2_unicode_compatible
class AppType(models.Model):
name = models.CharField(max_length=200, unique=True)
objects = AppTypeManager()
Expand All @@ -41,7 +37,6 @@ def __str__(self):
return self.name


@python_2_unicode_compatible
class AppStore(models.Model):
"""
to store links for cartoview appstores
Expand All @@ -61,7 +56,6 @@ def __str__(self):
return self.name


@python_2_unicode_compatible
class App(models.Model):
name = models.CharField(max_length=200, null=True, blank=True)
title = models.CharField(max_length=200, null=True, blank=True)
Expand Down Expand Up @@ -198,7 +192,6 @@ def get_app_logo_path(instance, filename):
])


@python_2_unicode_compatible
class AppInstance(ResourceBase):
"""
An App Instance is any kind of App Instance that can be created
Expand Down Expand Up @@ -253,24 +246,6 @@ def config_obj(self):
logger.error(e)
return None

def set_permissions(self, perm_spec):
remove_object_permissions(self)
try:
from geonode.security.utils import (set_owner_permissions)
set_owner_permissions(self)
except BaseException:
pass
if 'users' in perm_spec and "AnonymousUser" in perm_spec['users']:
anonymous_group = Group.objects.get(name='anonymous')
for perm in perm_spec['users']['AnonymousUser']:
assign_perm(perm, anonymous_group, self.get_self_resource())

if 'groups' in perm_spec:
for group, perms in perm_spec['groups'].items():
group = Group.objects.get(name=group)
for perm in perms:
assign_perm(perm, group, self.get_self_resource())

@property
def launch_url(self):
return reverse("%s.view" % self.app.name, args=[self.pk])
Expand All @@ -292,7 +267,8 @@ def pre_save_appinstance(instance, sender, **kwargs):
def pre_delete_appinstance(instance, sender, **kwargs):
if not isinstance(instance, AppInstance):
return
remove_object_permissions(instance.get_self_resource())
from geonode.resource.manager import resource_manager
resource_manager.remove_permissions(instance.uuid, instance)


def appinstance_post_save(instance, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions cartoview/app_manager/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import json

from django.template.loader import render_to_string
from django.utils import six
from django.utils.encoding import force_text
from future import standard_library
from six import binary_type
from tastypie.exceptions import UnsupportedFormat
from tastypie.serializers import Serializer

Expand Down Expand Up @@ -65,7 +65,7 @@ def deserialize(self, content, request=None, format='application/json'):
format)

if isinstance(content,
six.binary_type) and desired_format != 'file_upload':
binary_type) and desired_format != 'file_upload':
content = force_text(content)

deserialized = getattr(self, "from_%s" % desired_format)(content, {
Expand Down
56 changes: 2 additions & 54 deletions cartoview/app_manager/templates/app_manager/apps.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "app_manager/app_install_base.html" %}
{% load bootstrap_tags staticfiles cartoview_tags base_tags %}
{% load bootstrap_tags static cartoview_tags base_tags %}
{% load client_lib_tags %}
{% load i18n %}

{% block title %} {{ block.super }} - {% trans "Applications" %} {% endblock %}
Expand Down Expand Up @@ -143,59 +144,6 @@ <h4 class="text-center">{{ app.title }}</h4>
{# <h1>{% trans "No Apps Installed" %}</h1>#}
{# </div>#}
{% endfor %}
{% with facet_type='geoapps' %}
{% facets as facets %}
<div class="flex-item">
<div class="thumbnail">
<img src="{% static 'app_manager/images/geonode-dashboard.png' %}" class="app-img">
<div class="fill-empty flex-row">
<h4 class="text-center">{% trans 'Geonode Dashboard' %}</h4>
<p class="text-center">
{% trans "Geonode Dashboard" %}
</p>
<div class="fill-empty">
</div>
<div class="text-center" style="display:flex;flex-wrap:wrap">
<div id="card-buttons">
<a href="{% url "apps_browse" %}?limit={{ CLIENT_RESULTS_LIMIT }}&app_type__in=Dashboard"
target="_parent" class="btn btn-sm btn-primary">{% trans "Explore" %} <span
class="badge">{{ facets.Dashboard }}</span></a>
</div>
<div id="card-buttons">
<a class="btn btn-sm btn-primary" href="{% url "new_geoapp" %}?appType=Dashboard">
{% trans "Create New" %}
</a>
</div>
</div>
</div>
</div>
</div>
<div class="flex-item">
<div class="thumbnail">
<img src="" class="app-img">
<div class="fill-empty flex-row">
<h4 class="text-center">{% trans 'GeoStory' %}</h4>
<p class="text-center">
{% trans "GeoStory" %}
</p>
<div class="fill-empty">
</div>
<div class="text-center" style="display:flex;flex-wrap:wrap">
<div id="card-buttons">
<a href="{% url "apps_browse" %}?limit={{ CLIENT_RESULTS_LIMIT }}&app_type__in=GeoStory"
target="_parent" class="btn btn-sm btn-primary">{% trans "Explore" %} <span
class="badge">{{ facets.GeoStory }}</span></a>
</div>
<div id="card-buttons">
<a class="btn btn-sm btn-primary" href="{% url "new_geoapp" %}?appType=GeoStory">
{% trans "Create New" %}
</a>
</div>
</div>
</div>
</div>
</div>
{% endwith %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion cartoview/app_manager/templates/app_manager/manage.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "app_manager/app_install_base.html" %}
{% load bootstrap_tags staticfiles%}
{% load bootstrap_tags static%}
{% load i18n avatar_tags cartoview_tags %}


Expand Down
2 changes: 1 addition & 1 deletion cartoview/app_manager/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
from six import StringIO

from cartoview.app_manager.models import (App, AppStore)

Expand Down
2 changes: 1 addition & 1 deletion cartoview/app_manager/tests/test_installer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import threading

from django.contrib.admin import ACTION_CHECKBOX_NAME
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.urls import reverse
from django.test import TestCase
from geonode.people.models import Profile
Expand Down
5 changes: 4 additions & 1 deletion cartoview/apps_handler/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import json
import os
from collections import Mapping
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
import portalocker


Expand Down
4 changes: 2 additions & 2 deletions cartoview/cartoview_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GeoNodeAuthorization)
from geonode.api.resourcebase_api import MapResource, ResourceBaseResource
from geonode.base.models import ResourceBase
from geonode.layers.models import Attribute, Layer
from geonode.layers.models import Attribute, Dataset
from geonode.maps.models import MapLayer
from tastypie import fields
from tastypie.authentication import MultiAuthentication, SessionAuthentication
Expand Down Expand Up @@ -202,7 +202,7 @@ def apply_filters(self, request, applicable_filters):
return filtered

def get_layer(self, name):
layer = Layer.objects.filter(alternate=name)
layer = Dataset.objects.filter(alternate=name)
if layer.count() > 0:
return layer.first()
return None
Expand Down
8 changes: 4 additions & 4 deletions cartoview/cartoview_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import requests
from django.shortcuts import HttpResponse
from geonode.geoserver.helpers import ogc_server_settings
from geonode.layers.views import (_PERMISSION_MSG_MODIFY, _resolve_layer,
layer_detail)
from geonode.layers.views import (_PERMISSION_MSG_MODIFY, _resolve_dataset,
dataset_detail)
from requests.auth import HTTPBasicAuth

from cartoview.log_handler import get_logger
Expand All @@ -30,7 +30,7 @@ def get_geoserver_credintials():


def layer_config_json(request, layername):
layer_details = layer_detail(
layer_details = dataset_detail(
request, layername)
viewer = layer_details.context_data['viewer']
layer = layer_details.context_data['resource']
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_featureType(workspace, store, lyr_name):


def update_extent(request, typename):
lyr = _resolve_layer(
lyr = _resolve_dataset(
request,
typename,
'base.change_resourcebase',
Expand Down
14 changes: 7 additions & 7 deletions cartoview/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
CARTOVIEW_TEST = 'test' in sys.argv or ast.literal_eval(
os.getenv('CARTOVIEW_TEST', "False")) or 'run_cartoview_test' in sys.argv

if CARTOVIEW_TEST:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': os.path.join(BASE_DIR, 'test.db')
}
}
# if CARTOVIEW_TEST:
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.contrib.gis.db.backends.spatialite',
# 'NAME': os.path.join(BASE_DIR, 'test.db')
# }
# }
if 'datastore' in DATABASES:
OGC_SERVER['default']['DATASTORE'] = 'datastore'

Expand Down
5 changes: 1 addition & 4 deletions cartoview/templates/cartoview/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
{% block extra_head %}
{{ block.super }}
{% endblock %}
{% block tabs %}
<li><a href="{% url 'app_manager_base_url' %}">{% trans "Apps" %}</a></li>
{{block.super}}
{% endblock %}

{% block footer %}
{% include 'cartoview/footer.html' %}
{% endblock %}
Loading

0 comments on commit c62f946

Please sign in to comment.