Skip to content

Commit

Permalink
Merge 05314df into 1358d3f
Browse files Browse the repository at this point in the history
  • Loading branch information
Hisham waleed karam committed Nov 19, 2018
2 parents 1358d3f + 05314df commit baf6fe8
Show file tree
Hide file tree
Showing 29 changed files with 430 additions and 133 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
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
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',
),
]
24 changes: 23 additions & 1 deletion cartoview/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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 +147,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
7 changes: 7 additions & 0 deletions cartoview/app_manager/req_installer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import os
from os import R_OK, access

from future import standard_library

standard_library.install_aliases()


class ReqFileException(Exception):
message = "requirement file doesn't exists!"
Expand Down
2 changes: 1 addition & 1 deletion cartoview/app_manager/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class AppInstanceResource(ModelResource):
launch_app_url = fields.CharField(null=True, blank=True)
edit_url = fields.CharField(null=True, blank=True)
app = fields.ForeignKey(AppResource, 'app', full=True, null=True)
map = fields.ForeignKey(MapResource, 'map', full=True, null=True)
map = fields.ForeignKey(MapResource, 'related_map', full=True, null=True)
owner = fields.ForeignKey(
ProfileResource, 'owner', full=True, null=True, blank=True)
keywords = fields.ListField(null=True, blank=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "geonode_base.html" %}
{% load i18n %}
{% load url from future %}

{% block title %} {{ block.super }} {% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends "app_manager/appinstance_base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load url from future %}

{% block title %} {% trans "Explore Apps" %} - {{ block.super }} {% endblock %}
{% block head %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "geonode_base.html" %}
{% load i18n %}
{% load url from future %}

{% block title %} {{ block.super }} {% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% load dialogos_tags %}
{% load agon_ratings_tags %}
{% load bootstrap_tags %}
{% load url from future %}
{% load base_tags %}
{% load guardian_tags %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{% block title %}{{ appinstance.typename }} — {{ block.super }}{% endblock %}

{% block head %}
{% include "geonode/ext_header.html" %}
{{ block.super }}
{% endblock %}

Expand Down
12 changes: 10 additions & 2 deletions cartoview/app_manager/templates/app_manager/dynamic_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
RESTART_SERVER: "{% url 'restart_server' api_name='api' resource_name='app' %}",
});
angular.module('cartoview.userInfo',[]).service("cartoviewUser",function () {
this.isAuthenticated = {{ user.is_authenticated | dump_json }};
this.isSuperUser = {{ user.is_superuser | dump_json }};
{% if user.is_authenticated %}
this.isAuthenticated = true
{% else %}
this.isAuthenticated = false
{% endif %}
{% if user.is_superuser %}
this.isSuperUser = true
{% else %}
this.isSuperUser = false
{% endif %}
this.loginUrl = "{% url 'account_login' %}?next={{ request.get_full_path }}";
this.logoutUrl = "{% url 'account_logout' %}";
this.registerUrl = "{% url 'account_signup' %}";
Expand Down
51 changes: 15 additions & 36 deletions cartoview/app_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@
from django.db.models import F, Max, Min
from django.forms.utils import ErrorList
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render, render_to_response
from django.template import RequestContext, loader
from django.shortcuts import get_object_or_404, render
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST
from future import standard_library
from future.utils import with_metaclass
from guardian.shortcuts import get_perms

from cartoview.app_manager.forms import AppInstanceEditForm
from cartoview.log_handler import get_logger
from geonode.base.forms import CategoryForm
from geonode.base.models import TopicCategory
from geonode.people.forms import ProfileForm
from geonode.security.views import _perms_info_json
from geonode.utils import build_social_links
from guardian.shortcuts import get_perms

from cartoview.app_manager.forms import AppInstanceEditForm
from cartoview.log_handler import get_logger

from .decorators import (PERMISSION_MSG_DELETE, PERMISSION_MSG_METADATA,
PERMISSION_MSG_VIEW, can_change_app_instance,
Expand Down Expand Up @@ -228,20 +227,13 @@ def appinstance_detail(request, appinstanceid):
PERMISSION_MSG_VIEW)

except Http404:
return HttpResponse(
loader.render_to_string('404.html', RequestContext(request, {})),
status=404)
return render(request, '404.html', context={}, status=404)

except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html',
RequestContext(
request, {
return render(request, '401.html', context={
'error_message':
_("You are not allowed to view this document.")
})),
status=403)
}, status=403)

if appinstance is None:
return HttpResponse(
Expand Down Expand Up @@ -279,9 +271,8 @@ def appinstance_detail(request, appinstanceid):
context_dict['exif_data'] = exif
except BaseException as e:
logger.error(e.message + "Exif extraction failed.")

return render_to_response("app_manager/appinstance_detail.html",
RequestContext(request, context_dict))
return render(request, "app_manager/appinstance_detail.html",
context=context_dict)


@login_required
Expand All @@ -295,19 +286,11 @@ def appinstance_metadata(request,
PERMISSION_MSG_METADATA)

except Http404:
return HttpResponse(
loader.render_to_string('404.html', RequestContext(request, {})),
status=404)
return render(request, '404.html', context={}, status=404)

except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html',
RequestContext(
request, {
'error_message':
_("You are not allowed to edit this instance.")
})),
return render(request, '401.html', context={
'error_message': _("You are not allowed to edit this instance.")},
status=403)

if appinstance is None:
Expand Down Expand Up @@ -417,17 +400,13 @@ def appinstance_metadata(request,
else:
author_form = ProfileForm(prefix="author")
author_form.hidden = True

return render_to_response(
template,
RequestContext(
request, {
return render(request, template, context={
"appinstance": appinstance,
"appinstance_form": appinstance_form,
"poc_form": poc_form,
"author_form": author_form,
"category_form": category_form,
}))
})


def appinstance_remove(request, appinstanceid):
Expand Down
11 changes: 8 additions & 3 deletions cartoview/apps_handler/apps.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import os

from django.apps import AppConfig
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError
from future import standard_library

from cartoview.log_handler import get_logger

standard_library.install_aliases()
pending_yaml = settings.PENDING_APPS

logger = get_logger(__name__)
Expand All @@ -34,13 +39,13 @@ def execute_pending(self):
interactive=False,
ignore=['node_modules', '.git'])
call_command("migrate", app.name, interactive=False)
CartoApps.set_app_pending(app.name, False)
except CommandError as e:
error = e.message
logger.error(error)
if "you cannot selectively sync unmigrated apps"\
not in error:
if error and "does not have migrations" not in error:
self.delete_application_on_fail(app.name)
finally:
CartoApps.set_app_pending(app.name, False)

def ready(self):
apps_dir = getattr(settings, 'APPS_DIR', None)
Expand Down
7 changes: 7 additions & 0 deletions cartoview/apps_handler/db_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from urllib import urlencode

import dj_database_url
from django.conf import settings
from future import standard_library

standard_library.install_aliases()


class DBParseException(Exception):
Expand Down
6 changes: 6 additions & 0 deletions cartoview/apps_handler/handlers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import os
from contextlib import contextmanager

from django.conf import settings
from future import standard_library
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.sql.expression import func
from sqlalchemy.types import Boolean, DateTime

standard_library.install_aliases()


class AppsHandlerDBException(Exception):
pass
Expand Down
10 changes: 9 additions & 1 deletion cartoview/apps_handler/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from django.conf import settings
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import os

from django.conf import settings
from future import standard_library

from cartoview.app_manager.helpers import (change_path_permission,
create_direcotry)

standard_library.install_aliases()


def create_apps_dir(apps_dir=getattr(settings, 'APPS_DIR', None)):
if not apps_dir:
Expand Down
Loading

0 comments on commit baf6fe8

Please sign in to comment.