Skip to content

Commit

Permalink
Merge d8770c4 into 4a87271
Browse files Browse the repository at this point in the history
  • Loading branch information
Hisham waleed karam committed Aug 5, 2018
2 parents 4a87271 + d8770c4 commit 54b2b32
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 53 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@
INSTALLED_APPS += load_apps()
```
- **restart your server**

***


## How to run tests
- You Can run tests with the following command
```sh
python manage.py test cartoview --with-coverage --cover-package=cartoview
```
25 changes: 21 additions & 4 deletions cartoview/app_manager/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

from builtins import *

from cartoview.app_manager.models import App, AppInstance
from cartoview.site_management.models import SiteLogo
from django.conf import settings
from geonode.version import get_version
from cartoview import __version__
from django.contrib.sites.models import Site
from django.shortcuts import get_object_or_404
from future import standard_library
from geonode.groups.models import Group
from geonode.maps.models import Layer, Map
from geonode.people.models import Profile
from geonode.version import get_version
from guardian.shortcuts import get_objects_for_user

from cartoview import __version__
from cartoview.app_manager.models import App, AppInstance
from cartoview.site_management.models import SiteLogo

standard_library.install_aliases()

Expand All @@ -21,11 +26,23 @@ def apps(request):


def cartoview_processor(request):
permitted = get_objects_for_user(request.user,
'base.view_resourcebase')
cartoview_counters = {
"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(),
"users": Profile.objects.exclude(username="AnonymousUser").count(),
"groups": Group.objects.exclude(name="anonymous").count()
}

defaults = {
'apps': App.objects.all().order_by('order'),
'CARTOVIEW_VERSION': get_version(__version__),
'APPS_MENU': settings.APPS_MENU,
'apps_instance_count': AppInstance.objects.all().count(),
"cartoview_counters": cartoview_counters,
'instances': AppInstance.objects.all().order_by('app__order')[:5]
}
return defaults
Expand Down
4 changes: 1 addition & 3 deletions cartoview/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
# NOTE:set cartoview_stand_alone environment var if you are not using cartoview_proect_template
CARTOVIEW_STAND_ALONE = strtobool(os.getenv('CARTOVIEW_STAND_ALONE', 'FALSE'))
if CARTOVIEW_STAND_ALONE:
from cartoview.app_manager.settings import load_apps
INSTALLED_APPS += load_apps()
if 'test' in sys.argv:
print("CARTOVIEW_STAND_ALONE={}".format(CARTOVIEW_STAND_ALONE))
from cartoview.app_manager.settings import load_apps
INSTALLED_APPS += load_apps()
10 changes: 5 additions & 5 deletions cartoview/templates/site_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,34 @@ <h3 class="text-center">
<div class="row" style="background: rgba(13, 64, 109, 0.68);">
<div class="col-xs-6 col-sm-6 col-md-2 col-md-offset-1 text-center center-counter">
<div class="row">
<span class="count">{% layers_counts %}</span>
<span class="count">{{cartoview_counters.layers}}</span>
</div>
<a href="{% url 'layer_browse' %}">Layers</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-2 text-center center-counter">
<div class="row">
<span class="count">{% maps_counts %}</span>
<span class="count">{{cartoview_counters.maps}}</span>
</div>

<a href="{% url 'maps_browse' %}">Maps</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-2 text-center center-counter ">
<div class="row">
<span class="count">{% users_counts %}</span>
<span class="count">{{cartoview_counters.users}}</span>
</div>

<a href="{% url 'profile_browse' %}">Users</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-2 text-center center-counter ">
<div class="row">
<span class="count">{% groups_counts %}</span>
<span class="count">{{cartoview_counters.groups}}</span>
</div>

<a href="{% url 'group_list' %}">Groups</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-2 text-center center-counter">
<div class="row">
<span class="count">{% apps_counts %}</span>
<span class="count">{{cartoview_counters.apps}}</span>
</div>
<a href="{% url 'appinstance_browse' %}">Apps</a>
</div>
Expand Down
41 changes: 0 additions & 41 deletions cartoview/templatetags/cartoview_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,6 @@ def num_ratings(obj):
return len(Rating.objects.filter(object_id=obj.pk, content_type=ct))


@register.simple_tag
def layers_counts():
return Layer.objects.count()


@register.simple_tag
def maps_counts():
return Map.objects.count()


@register.simple_tag
def apps_counts():
return AppInstance.objects.count()


@register.simple_tag
def users_counts():
return Profile.objects.exclude(username="AnonymousUser").count()


@register.simple_tag
def groups_counts():
return Group.objects.exclude(name="anonymous").count()


@register.simple_tag
def apps_url(url_name, *args, **kwargs):
url = None
try:
url = reverse(url_name, args=args, kwargs=kwargs)
except:
pass
return json.dumps(url)


@register.assignment_tag(takes_context=True)
def facets(context):
request = context['request']
Expand Down Expand Up @@ -160,12 +125,6 @@ def facets(context):
return facets


@register.filter(name='jsonify')
def jsonify(values):
"""Json Object"""
return mark_safe(json.dumps(values))


@register.filter(name='objects_count')
def objects_count(instances, user):
permitted = [instance for instance in instances if user.has_perm(
Expand Down

0 comments on commit 54b2b32

Please sign in to comment.