Skip to content

Commit

Permalink
change geodata json to ajax and restrict mapped profiles to users tha…
Browse files Browse the repository at this point in the history
…t have geo_city set
  • Loading branch information
Sancus committed Aug 31, 2014
1 parent 86c7a83 commit 483457e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion mozillians/groups/models.py
Expand Up @@ -216,7 +216,7 @@ def geodata(self, rebuild=False, timeout=300):
geodata = []
for membership in memberships:
profile = membership.userprofile or membership
if profile.lat and profile.lng:
if profile.lat and profile.lng and profile.geo_city:
labelText = "%s — %s" % (profile.full_name, profile.geo_city)
geodata.append(dict([("lat", profile.lat), ("lng", profile.lng),
("labelText", labelText),
Expand Down
2 changes: 2 additions & 0 deletions mozillians/groups/urls.py
Expand Up @@ -32,4 +32,6 @@
name='toggle_skill_subscription'),
url('^skills/search/$', 'views.search',
dict(searched_object=Skill), name='search_skills'),
url('^group/(?P<url>[-\w]+)/geodata.json$', 'views.geodata',
{'alias_model': GroupAlias}, name='show_geodata'),
)
11 changes: 8 additions & 3 deletions mozillians/groups/views.py
Expand Up @@ -88,6 +88,14 @@ def search(request, searched_object=Group):
return HttpResponseBadRequest()


def geodata(request, url, alias_model):
group_alias = get_object_or_404(alias_model, url=url)
if group_alias.alias.url != url:
return redirect('groups:show_geodata', url=group_alias.alias.url)
group = group_alias.alias
return HttpResponse(json.dumps(group.geodata()), mimetype='application/json')


@never_cache
def show(request, url, alias_model, template):
"""List all members in this group."""
Expand All @@ -106,10 +114,8 @@ def show(request, url, alias_model, template):
in_group = group.has_member(profile)
memberships = group.members.all()
data = {}
geodata = []

if isinstance(group, Group):
geodata = json.dumps(group.geodata())
# Is this user's membership pending?
is_pending = group.has_pending_member(profile)

Expand Down Expand Up @@ -163,7 +169,6 @@ def show(request, url, alias_model, template):
show_pagination = paginator.count > settings.ITEMS_PER_PAGE

extra_data = dict(people=people,
geodata=geodata,
group=group,
in_group=in_group,
is_curator=is_curator,
Expand Down
40 changes: 20 additions & 20 deletions mozillians/static/mozillians/js/map.js
Expand Up @@ -29,25 +29,25 @@
}
});

$(document).ready(function(){
var addressPoints = JSON.parse( document.getElementById('geodata').text );

for (var i = 0; i < addressPoints.length; i++) {
var labelText = addressPoints[i].labelText;
var icon = L.icon({
iconUrl: addressPoints[i].photo,
iconRetinaUrl: addressPoints[i].photo2x,
iconSize: [32, 32],
iconAnchor: [16, 16],
className: 'moz-marker-single'
});
var marker = L.marker(new L.LatLng(addressPoints[i].lat, addressPoints[i].lng), { title:labelText, icon:icon });
console.log(marker);
marker.bindPopup(labelText);
clusters.addLayer(marker);
}

map.addLayer(clusters);
$.ajax({
url: document.URL + 'geodata.json',
success: function(addressPoints){
for (var i = 0; i < addressPoints.length; i++) {
var labelText = addressPoints[i].labelText;
var icon = L.icon({
iconUrl: addressPoints[i].photo,
iconRetinaUrl: addressPoints[i].photo2x,
iconSize: [32, 32],
iconAnchor: [16, 16],
className: 'moz-marker-single'
});
var marker = L.marker(new L.LatLng(addressPoints[i].lat, addressPoints[i].lng), { title:labelText, icon:icon });
console.log(marker);
marker.bindPopup(labelText);
clusters.addLayer(marker);
}

map.addLayer(clusters);
}
});

}());
4 changes: 0 additions & 4 deletions mozillians/templates/groups/group.html
Expand Up @@ -198,12 +198,8 @@ <h3 class="members-list-header">
{% endblock content %}

{% block page_js %}
<script type="application/json" id="geodata">
{{ geodata|safe }}
</script>
<script type="text/javascript" src="https://api.tiles.mapbox.com/mapbox.js/v1.6.2/mapbox.js"></script>
<link rel="stylesheet" type="text/css" href="https://api.tiles.mapbox.com/mapbox.js/v1.6.2/mapbox.css">

<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css' rel='stylesheet' />
<link href='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.css' rel='stylesheet' />
Expand Down

0 comments on commit 483457e

Please sign in to comment.