Skip to content

Commit

Permalink
Merge a4a17e3 into 8eea73a
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamkaram committed Jan 19, 2019
2 parents 8eea73a + a4a17e3 commit 093d092
Show file tree
Hide file tree
Showing 109 changed files with 777 additions and 18,045 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ deploy:
on:
tags: true
all_branches: true
condition: $TRAVIS_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+
condition: $TRAVIS_TAG =~ ^v([0-9]+\.?){2,3}(b[0-9]+|rc[0-9]+){0,1}
notifications:
email:
- hisham.karam@cartologic.com
- hishamwaleedkaram@gmail.com
- ahmednosman@cartologic.com
- ahmedNourElDeen@cartologic.com
54 changes: 16 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
FROM ubuntu:16.04
FROM python:2.7-slim
LABEL "MAINTAINER"="Cartologic Development Team"
ENV TERM xterm
RUN apt-get update
RUN apt-get install locales -y
RUN locale-gen en_US.UTF-8 && update-locale
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get install software-properties-common python-software-properties -y
RUN add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get update && apt-get install -y \
gcc gettext \
python-pip libpq-dev \
sqlite3 git gdal-bin lsof psmisc \
python-gdal python-psycopg2 \
python-imaging python-lxml \
python-dev libgdal-dev libgeoip-dev \
python-ldap libxml2 libxml2-dev libxslt-dev \
libmemcached-dev libsasl2-dev zlib1g-dev \
python-pylibmc python-setuptools \
curl build-essential build-essential python-dev \
--no-install-recommends
RUN mkdir /code
WORKDIR /code
RUN pip install --upgrade pip
RUN pip install --ignore-installed geoip django-geonode-client \
geonode==2.8rc11 django-jsonfield django-jsonfield-compat \
cartoview==1.8.3 cherrypy==11.0.0 cheroot==5.8.3 \
django-autocomplete-light==2.3.3 --no-cache-dir
RUN pip install git+https://github.com/GeoNode/django-osgeo-importer.git
RUN apt autoremove --purge -y && apt autoclean -y
RUN rm -rf ~/.cache/pip
RUN rm -rf /var/lib/apt/lists/* && apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN echo "Yes, do as I say!" | apt-get remove --force-yes login \
&& dpkg --remove --force-depends wget unzip
ENV PYTHONUNBUFFERED 1
ARG GEONODE_DEV=true
ARG GEONODE_SHA1=992daf724e83cdb0c1eb776d147eba841ad02cd9
ARG APP_DIR=/usr/src/carto_app
# include GDAL HEADER Files
# CPATH specifies a list of directories to be searched as if specified with -I,
# but after any paths given with -I options on the command line.
# This environment variable is used regardless of which language is being preprocessed.
ENV CPATH "$CPATH:/usr/include/gdal:/usr/include"
COPY scripts/docker/setup.sh ./
COPY . /cartoview
RUN chmod +x setup.sh
RUN ./setup.sh
# switch to project dir
WORKDIR ${APP_DIR}
CMD ["/bin/bash"]
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<img src="https://cartologic.github.io/img/cartoview-logo.png"/>
</p>

| WARNING: be careful this version(1.10.x) of Cartoview is compatibile with geonode 2.10.x only,if you want to install another version please take alook on [this section](https://github.com/cartologic/cartoview/blob/hisham-dev/README.md#previous-versions) |
| --- |

---
## What is Cartoview?
- CartoView is a GIS Web Mapping Application Market.
Expand Down Expand Up @@ -43,7 +46,7 @@

## How To Add Cartoview To Existing Geonode:
- install cartoview with pip:
- `pip install cartoview==1.8.5 --no-cache-dir`
- `pip install cartoview --no-cache-dir`
- open geonode `settings.py` and add the following lines at the end of the file:
```python
from cartoview import settings as cartoview_settings
Expand Down Expand Up @@ -84,3 +87,9 @@
```sh
paver run_test
```
___
# Previous Versions
| Cartoview Version | Geonode Version | docs Link |
|-------------------|-----------------|---------------------------------------------------------------------------------|
| 1.8.x | 2.8.x | [Here](https://github.com/cartologic/cartoview/blob/1.8.x/README.md) |
| 1.6.x | 2.6.x | [Here](https://github.com/cartologic/cartoview/blob/2.6.x_compatible/README.md) |
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, 8, 6, 'unstable', 0)
__version__ = (1, 10, 0, 'beta', 0)
__compatible_with__ = []


Expand Down
14 changes: 7 additions & 7 deletions cartoview/app_manager/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .utils import resolve_appinstance
from django.conf import settings
from django.utils.translation import ugettext as _

from .exceptions import AppAlreadyInstalledException
from .utils import resolve_appinstance

PERMISSION_MSG_DELETE = _("You are not permitted to delete this Instance")
PERMISSION_MSG_GENERIC = _("You do not have permissions for this Instance.")
PERMISSION_MSG_MODIFY = _("You are not permitted to modify this Instance")
Expand Down Expand Up @@ -40,9 +42,6 @@ def restart_enabled(func):
def wrap(*args, **kwargs):
if not getattr(settings, "CARTOVIEW_TEST", False):
return func(*args, **kwargs)
else:
pass

return wrap


Expand All @@ -52,8 +51,9 @@ def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except BaseException as e:
if hasattr(this, '_rollback'):
this._rollback()
raise e
if not isinstance(e, AppAlreadyInstalledException):
if hasattr(this, '_rollback'):
this._rollback()
raise e

return wrap
2 changes: 2 additions & 0 deletions cartoview/app_manager/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class AppAlreadyInstalledException(BaseException):
message = "Application is already installed."
22 changes: 11 additions & 11 deletions cartoview/app_manager/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import threading
import zipfile
from io import BytesIO
from os import R_OK, access
from sys import executable, exit
from threading import Timer

Expand All @@ -25,9 +24,12 @@
from cartoview.log_handler import get_logger
from cartoview.store_api.api import StoreAppResource, StoreAppVersion

from ..apps_handler.req_installer import (ReqFileException,
ReqFilePermissionException,
ReqInstaller)
from .decorators import restart_enabled, rollback_on_failure
from .exceptions import AppAlreadyInstalledException
from .models import App, AppStore, AppType
from .req_installer import ReqInstaller

logger = get_logger(__name__)
install_app_batch = getattr(settings, 'INSTALL_APP_BAT', None)
Expand Down Expand Up @@ -118,10 +120,6 @@ def get_property_value(self, p):
return getattr(self, p, None)


class AppAlreadyInstalledException(BaseException):
message = "Application is already installed."


class AppInstaller(object):
def __init__(self, name, store_id=None, version=None, user=None):
self.user = user
Expand Down Expand Up @@ -277,12 +275,14 @@ def install(self, restart=True):

@rollback_on_failure
def _install_requirements(self):
# TODO:add requirement file name as settings var
req_file = os.path.join(self.app_dir, "req.txt")
libs_dir = os.path.join(self.app_dir, "libs")
if os.path.exists(req_file) and access(req_file, R_OK):
req_installer = ReqInstaller(req_file, target=libs_dir)
try:
libs_dir = os.path.join(self.app_dir, 'libs')
req_installer = ReqInstaller(self.app_dir, target=libs_dir)
req_installer.install_all()
except BaseException as e:
if not (isinstance(e, ReqFileException) or
isinstance(e, ReqFilePermissionException)):
raise e

@rollback_on_failure
def check_then_finlize(self, restart, installed_apps):
Expand Down
10 changes: 8 additions & 2 deletions cartoview/app_manager/management/commands/install_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import print_function

from django.core.management.base import BaseCommand
from pkg_resources import parse_version

from cartoview.app_manager.installer import AppInstaller
from cartoview.app_manager.models import App, AppStore
Expand All @@ -10,6 +11,10 @@
logger = get_logger(__name__)


def compare_version(v1, v2):
return parse_version(v1) < parse_version(v2)


class Command(BaseCommand):
help = 'Install App'

Expand All @@ -29,8 +34,9 @@ def handle(self, *args, **options):
store = AppStore.objects.get(is_default=True)
q = App.objects.filter(name=app_name)
try:
if q.count() == 0 or (q.first()
and q.first().version < app_version):
if q.count() == 0 or (q.first() and
compare_version(q.first().version,
app_version)):
installer = AppInstaller(app_name, store.id, app_version)
installer.install()
except Exception as ex:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import requests
from cartoview.app_manager.installer import AppJson, remove_unwanted
from cartoview.app_manager.models import App
Expand Down
28 changes: 28 additions & 0 deletions cartoview/app_manager/migrations/0010_auto_20181118_1333.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-18 13:33
from __future__ import unicode_literals

from django.db import migrations
import django.db.models.manager


class Migration(migrations.Migration):

dependencies = [
('app_manager', '0009_auto_20180920_1659'),
]

operations = [
migrations.AlterModelManagers(
name='appinstance',
managers=[
('objects', django.db.models.manager.Manager()),
('base_objects', django.db.models.manager.Manager()),
],
),
migrations.RenameField(
model_name='appinstance',
old_name='map',
new_name='related_map',
),
]
84 changes: 83 additions & 1 deletion cartoview/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,66 @@ def settings_url(self):
logger.error(e.message)
return None

@property
def urls(self):
admin_urls = logged_in_urls = anonymous_urls = None
try:
app_module = __import__(self.name)
if hasattr(app_module, 'urls_dict'):
urls_dict = getattr(app_module, 'urls_dict')
if 'admin' in list(urls_dict.keys()):
admin_urls = urls_dict['admin']
else:
admin_urls = None
if 'logged_in' in list(urls_dict.keys()):
logged_in_urls = urls_dict['logged_in']
else:
logged_in_urls = None
if 'anonymous' in list(urls_dict.keys()):
anonymous_urls = urls_dict['anonymous']
else:
anonymous_urls = None
except ImportError as e:
logger.error(e.message)
return (admin_urls, logged_in_urls, anonymous_urls)

@property
def open_url(self):
from django.core.urlresolvers import reverse
open_url = reverse('app_manager_base_url') + self.name
try:
app_module = __import__(self.name)
if hasattr(app_module, 'OPEN_URL_NAME'):
open_url = reverse(getattr(app_module, 'OPEN_URL_NAME'))
except ImportError as e:
logger.error(e.message)
return open_url

@property
def create_new_url(self):
from django.core.urlresolvers import reverse
create_new_url = reverse('{}.new'.format(self.name))
try:
app_module = __import__(self.name)
if hasattr(app_module, 'CREATE_NEW_URL_NAME'):
create_new_url = reverse(
getattr(app_module, 'CREATE_NEW_URL_NAME'))
except ImportError as e:
logger.error(e.message)
return create_new_url

@property
def admin_urls(self):
return self.urls[0]

@property
def logged_in_urls(self):
return self.urls[1]

@property
def anonymous_urls(self):
return self.urls[2]

@property
def new_url(self):
try:
Expand Down Expand Up @@ -136,6 +196,7 @@ 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 All @@ -146,21 +207,42 @@ class AppInstance(ResourceBase):
app = models.ForeignKey(
App, null=True, blank=True, on_delete=models.CASCADE)
config = models.TextField(null=True, blank=True)
map = models.ForeignKey(
related_map = models.ForeignKey(
GeonodeMap, null=True, blank=True, on_delete=models.CASCADE)
logo = models.ImageField(
upload_to=get_app_logo_path, blank=True, null=True)

def get_absolute_url(self):
return reverse('appinstance_detail', args=(self.id, ))

def __str__(self):
return self.title

@property
def name_long(self):
if not self.title:
return str(self.id)
else:
return '%s (%s)' % (self.title, self.id)

# NOTE:backward compatibility for old map field use by apps \
# in StandardAppViews
@property
def map_id(self):
return self.related_map_id

@map_id.setter
def map_id(self, value):
self.related_map_id = value

@property
def map(self):
return self.related_map

@map.setter
def map(self, value):
self.rerelated_map = value

@property
def config_obj(self):
try:
Expand Down
Loading

0 comments on commit 093d092

Please sign in to comment.