Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds projects map to platform dashboard #137

Merged
merged 1 commit into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ vagrant.retry

.sass-cache/
.transifexrc

.DS_Store
13 changes: 5 additions & 8 deletions cadasta/config/settings/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'django_countries',
'leaflet',
'rest_framework',
'rest_framework_gis',
'rest_framework.authtoken',
'rest_framework_docs',
'djoser',
Expand Down Expand Up @@ -145,14 +146,10 @@
LEAFLET_CONFIG = {
'TILES': [('OpenStreetMap',
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{'attribution': 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'})], # noqa
'RESET_VIEW': False
}

LEAFLET_CONFIG = {
'TILES': [('OpenStreetMap',
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{'attribution': 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'})], # noqa
{'attribution': 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'}),
('DigitalGlobe Satellite',
'https://{s}.tiles.mapbox.com/v4/digitalglobe.nal0g75k/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZGlnaXRhbGdsb2JlIiwiYSI6ImNpaHhtenBmZjAzYW11a2tvY2p3MnpjcGcifQ.vF1gH0mGgK31yeHC1k1Tqw',
{'attribution': 'DigitalGlobe'})],
'RESET_VIEW': False
}

Expand Down
34 changes: 31 additions & 3 deletions cadasta/core/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
import factory
from faker import Factory
from django.contrib.gis.geos import GEOSGeometry
from datetime import datetime, timezone

from accounts.models import User
Expand Down Expand Up @@ -142,7 +143,8 @@ def add_test_projects(self):
project. This is a test project. This is a test project. This
is a test project. This is a test project.""",
organization=orgs[0],
country='KE'
country='KE',
extent='SRID=4326;POLYGON ((-5.1031494140625000 8.1299292850467957, -5.0482177734375000 7.6837733211111425, -4.6746826171875000 7.8252894725496338, -4.8641967773437491 8.2278005261522775, -5.1031494140625000 8.1299292850467957))'
))
projs.append(ProjectFactory.create(
name='H4H Test Project',
Expand All @@ -152,7 +154,8 @@ def add_test_projects(self):
project. This is a test project. This is a test project. This
is a test project. This is a test project.""",
organization=orgs[0],
country='PH'
country='PH',
extent='SRID=4326;POLYGON ((-63.6328125000000000 44.7233201889582475, -63.3691406250000000 45.3830192789906519, -61.6992187500000000 45.6140374113509282, -61.1059570312500000 45.2439534226232425, -63.6328125000000000 44.7233201889582475))'
))
projs.append(ProjectFactory.create(
name='Cadasta Indonesia Test Project',
Expand All @@ -163,7 +166,8 @@ def add_test_projects(self):
This is another test project. This is another test project.
This is another test project.""",
organization=orgs[1],
country='ID'
country='ID',
extent='SRID=4326;POLYGON ((-57.0520019531250000 -1.0793428942462329, -56.7553710937499929 -0.6646579437921112, -56.3790893554687500 -1.1562325507679554, -56.3186645507812429 -1.4774973547127075, -56.8405151367187500 -1.4500404973607948, -57.0520019531250000 -1.0793428942462329))'
))
projs.append(ProjectFactory.create(
name='Cadasta Myanmar Test Project',
Expand All @@ -176,6 +180,30 @@ def add_test_projects(self):
organization=orgs[1],
country='MM'
))
projs.append(ProjectFactory.create(
name='London 1',
project_slug='london-1',
description=""""This is another test project. This is another test
project. This is another test project. This is another test
project. This is another test project. This is a test project.
This is another test project. This is another test project.
This is another test project.""",
organization=orgs[1],
country='MM',
extent=GEOSGeometry('{"type": "Polygon","coordinates": [[[-0.17329216003417966,51.51194758264939],[-0.17303466796874997,51.511092905004745],[-0.1709747314453125,51.51023821132554],[-0.17037391662597656,51.507406923983446],[-0.1746654510498047,51.50211782162702],[-0.1533794403076172,51.503239803730864],[-0.15226364135742185,51.505964502406805],[-0.15913009643554688,51.51322956905176],[-0.17329216003417966,51.51194758264939]]]}')
))
projs.append(ProjectFactory.create(
name='London 2',
project_slug='london-2',
description=""""This is another test project. This is another test
project. This is another test project. This is another test
project. This is another test project. This is a test project.
This is another test project. This is another test project.
This is another test project.""",
organization=orgs[1],
country='MM',
extent=GEOSGeometry('{"type": "Polygon","coordinates": [[[-0.1878833770751953,51.509864277798705],[-0.18393516540527344,51.50201096474784],[-0.17500877380371094,51.501690392607],[-0.17226219177246094,51.50671243040582],[-0.171661376953125,51.51152024583139],[-0.18642425537109375,51.509864277798705],[-0.1878833770751953,51.509864277798705]]]}')
))

def delete_test_organizations(self):
orgs = Organization.objects.filter(name__startswith='Organization #')
Expand Down
19 changes: 19 additions & 0 deletions cadasta/core/sass/geolocate.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.leaflet-control-geolocate {
width: 25px;
height: 25px;
background-color: #FFFFFF;
text-align: center;
}

.leaflet-control-geolocate:hover {
background-color: #f4f4f4;
}

.leaflet-control-geolocate span {
display: inline-block;
width: 25px;
height: 25px;
line-height: 25px;
vertical-align: middle;
cursor: pointer;
}
12 changes: 11 additions & 1 deletion cadasta/core/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

@import "wizard";
@import "toggle";
@import "geolocate";

/* =Basics
-------------------------------------------------------------- */
Expand Down Expand Up @@ -133,9 +134,10 @@ header nav a:hover {
-moz-border-radius: 2px;
border-radius: 2px;
}
.reg-links li:first-child {
.reg-links-divider {
border-right: solid 1px #eee;
}

.reg-links .list-inline > li {
padding: 0;
}
Expand Down Expand Up @@ -317,3 +319,11 @@ img.org-logo-hidden {
img#org-logo {
width: 120px;
}

div#dashboard-map {
position: absolute;
left: 0;
right: 0;
top: 100px;
bottom: 30px;
}
60 changes: 60 additions & 0 deletions cadasta/core/static/css/MarkerCluster.Default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.marker-cluster-small {
background-color: rgba(181, 226, 140, 0.6);
}
.marker-cluster-small div {
background-color: rgba(110, 204, 57, 0.6);
}

.marker-cluster-medium {
background-color: rgba(241, 211, 87, 0.6);
}
.marker-cluster-medium div {
background-color: rgba(240, 194, 12, 0.6);
}

.marker-cluster-large {
background-color: rgba(253, 156, 115, 0.6);
}
.marker-cluster-large div {
background-color: rgba(241, 128, 23, 0.6);
}

/* IE 6-8 fallback colors */
.leaflet-oldie .marker-cluster-small {
background-color: rgb(181, 226, 140);
}
.leaflet-oldie .marker-cluster-small div {
background-color: rgb(110, 204, 57);
}

.leaflet-oldie .marker-cluster-medium {
background-color: rgb(241, 211, 87);
}
.leaflet-oldie .marker-cluster-medium div {
background-color: rgb(240, 194, 12);
}

.leaflet-oldie .marker-cluster-large {
background-color: rgb(253, 156, 115);
}
.leaflet-oldie .marker-cluster-large div {
background-color: rgb(241, 128, 23);
}

.marker-cluster {
background-clip: padding-box;
border-radius: 20px;
}
.marker-cluster div {
width: 30px;
height: 30px;
margin-left: 5px;
margin-top: 5px;

text-align: center;
border-radius: 15px;
font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
}
.marker-cluster span {
line-height: 30px;
}
6 changes: 6 additions & 0 deletions cadasta/core/static/css/MarkerCluster.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow {
-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in;
-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in;
-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in;
transition: transform 0.3s ease-out, opacity 0.3s ease-in;
}
26 changes: 25 additions & 1 deletion cadasta/core/static/css/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cadasta/core/static/js/L.Map.Deflate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cadasta/core/static/js/leaflet.markercluster.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions cadasta/core/views/default.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import json

from django.shortcuts import redirect
from django.views.generic import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin
from organization.models import Project
from django.core.serializers import serialize

from organization.serializers import ProjectGeometrySerializer


class IndexPage(TemplateView):
Expand All @@ -15,3 +21,9 @@ def get(self, request, *args, **kwargs):

class Dashboard(LoginRequiredMixin, TemplateView):
template_name = 'core/dashboard.html'

def get_context_data(self, **kwargs):
context = super().get_context_data( **kwargs)
projects = Project.objects.filter(extent__isnull=False)
context['geojson'] = json.dumps(ProjectGeometrySerializer(projects, many=True).data)
return context
21 changes: 21 additions & 0 deletions cadasta/organization/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from django.utils.text import slugify
from django.db.models import Q
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.template.loader import get_template
from django.template import Context
from rest_framework import serializers
from rest_framework_gis import serializers as geo_serializers
from django_countries.serializer_fields import CountryField

from core.serializers import DetailSerializer, FieldSelectorSerializer
Expand Down Expand Up @@ -62,6 +64,25 @@ def create(self, validated_data):
)


class ProjectGeometrySerializer(geo_serializers.GeoFeatureModelSerializer):
org = serializers.SerializerMethodField()
url = serializers.SerializerMethodField()

class Meta:
model = Project
geo_field = 'extent'
fields = ('name', 'org', 'url')

def get_org(self, object):
return object.organization.name

def get_url(self, object):
return reverse(
'organization:project-dashboard',
kwargs={ 'organization': object.organization.slug,
'project': object.project_slug })


class EntityUserSerializer(serializers.Serializer):
username = serializers.CharField()
role = serializers.CharField()
Expand Down
13 changes: 13 additions & 0 deletions cadasta/organization/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.test import TestCase
from django.utils.translation import gettext as _
from django.core import mail
from django.core.urlresolvers import reverse
from rest_framework.serializers import ValidationError
from rest_framework.test import APIRequestFactory

Expand Down Expand Up @@ -85,6 +86,18 @@ def test_organization_is_set(self):
assert project_instance.organization == organization


class ProjectGeometrySerializerTest(TestCase):
def test_method_fields_work(self):
project = ProjectFactory.create()
test_data = serializers.ProjectGeometrySerializer(project).data

assert test_data['properties']['org'] == project.organization.name
assert test_data['properties']['url'] == reverse(
'organization:project-dashboard',
kwargs={ 'organization': project.organization.slug,
'project': project.project_slug })


class OrganizationUserSerializerTest(TestCase):
def test_to_represenation(self):
user = UserFactory.create()
Expand Down
10 changes: 10 additions & 0 deletions cadasta/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ <h1 id="logo" class="pull-left">
{% trans "Organizations" %}
</a>
</li>
<li>
<a href="{% url 'project:list' %}">
{% trans "Projects" %}
</a>
</li>
<li class="reg-links-divider">
<a href="{% url 'user:list' %}">
{% trans "Users" %}
</a>
</li>
{% if user.is_authenticated %}
<li>
<a href="{% url 'account:profile' %}">
Expand Down
Loading