Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Cleanup and mostly stylistic changes in preparation for inclusion in …
Browse files Browse the repository at this point in the history
…the Pinax project.

git-svn-id: http://django-locations.googlecode.com/svn/trunk@10 7dd5b791-a154-0410-b265-8553752079d8
  • Loading branch information
ericflo committed Nov 28, 2008
1 parent 5918a43 commit 03d7f3b
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 179 deletions.
8 changes: 3 additions & 5 deletions locations/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Creating a HiddenBaseForm. from djangosnippets.org.
# Creating a HiddenBaseForm. from djangosnippets.org.
# Author : Yashh (www.yashh.com)

from locations.models import Location
from django import forms
from django.forms.forms import BoundField

Expand All @@ -15,9 +14,8 @@ def as_hidden(self):

class LocationForm(forms.Form):
place = forms.CharField()

class CheckinForm(HiddenBaseForm, forms.Form):
place = forms.CharField()
latitude = forms.FloatField()
longitude = forms.FloatField()

longitude = forms.FloatField()
35 changes: 35 additions & 0 deletions locations/media/locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var ymap = document.getElementById('ymap');
if(ymap) {
var map = new YMap(ymap);
// Add map type control
map.addTypeControl();
// Add map zoom (long) control
map.addZoomLong();
// Add the Pan Control
map.addPanControl();
for(var i = 0; i < _geo.length; ++i) {
var g = _geo[i];
var yPoint = new YGeoPoint(g[0], g[1]);
// Display the map centered on a geocoded location
map.drawZoomAndCenter(yPoint, 12);
// Create a new marker for an address
var myMarker = new YMarker(yPoint);
// Create some content to go inside the SmartWindow
var myMarkerContent = g[2];
// When the marker is clicked, show the SmartWindow
YEvent.Capture(myMarker, EventsList.MouseClick, function() {
myMarker.openSmartWindow(myMarkerContent);
});
// Put the marker on the map
map.addOverlay(myMarker);
var pageLink = document.getElementById('loc_' + i);
if(pageLink) {
pageLink.onclick = function() {
var geoIndex = parseInt(this.id.replace('loc_', ''), 10);
var g = _geo[geoIndex];
var yPoint = new YGeoPoint(g[0], g[1]);
map.drawZoomAndCenter(yPoint, 12);
};
}
}
}
21 changes: 11 additions & 10 deletions locations/models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Author : Yashh (www.yashh.com)
# Since i would be just showing a list of checkins, I haven't included any extra methods on the model.
# Since I would be just showing a list of checkins, I haven't included any extra
# methods on the model.


from django.db import models
from django.contrib.auth.models import User

class Location(models.Model):
user = models.ForeignKey(User)
time_checkin = models.DateTimeField()
place = models.CharField(max_length=100)
latitude = models.FloatField()
longitude = models.FloatField()

class Meta:
ordering = ('-time_checkin',)
get_latest_by = 'time_checkin'
user = models.ForeignKey(User)
time_checkin = models.DateTimeField()
place = models.CharField(max_length=100)
latitude = models.FloatField()
longitude = models.FloatField()
class Meta:
ordering = ('-time_checkin',)
get_latest_by = 'time_checkin'
12 changes: 7 additions & 5 deletions locations/templates/locations/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

{% load i18n %}

{% block rtab_id %}id="locations_tab"{% endblock %}

{% block subnav %}
{% if user.is_authenticated %}
<ul>
<li><a href="{% url your_checkins %} ">{% trans "Your Checkins" %}</a></li>
<li><a href="{% url friends_checkins %} ">{% trans "Friends Checkins" %}</a></li>
<li><a href="{% url nearby_checkins %} ">{% trans "Nearby Checkins" %}</a></li>
</ul>
<ul>
<li><a href="{% url loc_yours %} ">{% trans "Your Checkins" %}</a></li>
<li><a href="{% url loc_friends %} ">{% trans "Friends Checkins" %}</a></li>
<li><a href="{% url loc_nearby %} ">{% trans "Nearby Checkins" %}</a></li>
</ul>
{% else %}
&nbsp;
{% endif %}
Expand Down
43 changes: 9 additions & 34 deletions locations/templates/locations/checkin.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
{% extends "locations/base.html" %}


{% block head_title %}All Locations{% endblock %}
{% block extra_head %}
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=y.Z4iD9nV34EdofUSyd_B5bLj5hrf6wiNszlLacUyxedUanphrJ_ibbMjlntY9eufKwtW"></script>
<script type="text/javascript">
function initialize_ymap()
{
// Create a map object
var map = new YMap(document.getElementById('ymap'));
var yPoint = new YGeoPoint({{ location.latitude }},{{ location.longitude }});
// Display the map centered on a geocoded location
map.drawZoomAndCenter(yPoint, 12);
// Create a new marker for an address
var myMarker = new YMarker(yPoint);
// Create some content to go inside the SmartWindow
var myMarkerContent = "{{location.place}}";
// When the marker is clicked, show the SmartWindow
YEvent.Capture(myMarker, EventsList.MouseClick,
function() {
myMarker.openSmartWindow(myMarkerContent);
});
// Put the marker on the map
map.addOverlay(myMarker);
}
</script>
<style type="text/css">
div#ymap {
width: 300px; height: 200px; float: right; border: 1px solid grey;
}
</style>
{% endblock %}

{% block body %}
<p>Did you mean:
{{ location.place }}</p>

<form action="/locations/checkin/" method="POST">
<p>Did you mean: {{ location.place }}</p>
<form action="{% url loc_checkin %}" method="POST">
<input type="hidden" name="place" value="{{ location.place }}" id="id_place" />
<input type="hidden" name="latitude" value="{{ location.latitude }}" id="id_latitude" />
<input type="hidden" name="longitude" value="{{ location.longitude }}" id="id_longitude" />
<p><input type="submit" value="Checkin &rarr;"></p>
</form>
<div id="ymap"></div>
{% endblock %}

{% block extra_body %}
<script type="text/javascript">
var _geo = [[{{ location.latitude }}, {{ location.longitude }}, '{{ location.place }}']];
</script>
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid={{ YAHOO_MAPS_API_KEY }}"></script>
{% endblock %}
10 changes: 4 additions & 6 deletions locations/templates/locations/friends_checkins.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

{% block body %}
{% for friendship in friends %}
{% if friendship.friend.location_set.latest.place %}
<p><a href="{{ friendship.friend.get_absolute_url }}">{{ friendship.friend.username }}</a> checked in at {{ friendship.friend.location_set.latest.place }}</p>
{% endif %}
{% with friendship.friend.location_set.latest as location %}
{% include "locations/location.html" %}
{% endwith %}
{% endfor %}

{% endblock %}

{% endblock %}
1 change: 1 addition & 0 deletions locations/templates/locations/location.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p class="location"><a href="{{ location.user.get_absolute_url }}">{{ request.user }}</a> checked in at {% if forloop %}<a href="#" id="loc_{{ forloop.counter0 }}">{% endif %}{{ location.place }}{% if forloop %}</a>{% endif %} at {{ location.time_checkin|date:"F d Y g:i a" }}</p>
14 changes: 5 additions & 9 deletions locations/templates/locations/nearby_checkins.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{% extends "locations/base.html" %}
{% load pagination_tags %}

{% block head_title %}Near by checkins{% endblock %}
{% block head_title %}Nearby checkins{% endblock %}

{% block body %}

{% if queryset %}
{% for location in queryset %}
<p><a href="{{ location.user.get_absolute_url }}">{{ location.user }}</a> checked in at {{ location.place }} on {{ location.time_checkin|date:"F d Y g:i a" }}</p>
{% endfor %}
{% for location in queryset %}
{% include "locations/location.html" %}
{% endfor %}
{% else %}
<p>There are no users who checked in near your location.</p>
{% endif %}

{% if message %}
<p>{{ message }}</p>
<p>There are no users who checked in near your location.</p>
{% endif %}
{% endblock %}

15 changes: 1 addition & 14 deletions locations/templates/locations/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@


{% block head_title %}New Location{% endblock %}
{% block extra_head %}
<style type="text/css">
.message {
color: red; font-size: 12px;
}
</style>
{% endblock %}

{% block body %}

{% if message %}
<p class="message">{{ message }}</p>
{% endif %}

<form action="." method="POST" accept-charset="utf-8">
<form method="POST" accept-charset="utf-8">
{{ location_form }}
<p><input type="submit" value="Continue &rarr;"></p>
</form>

{% endblock %}
47 changes: 13 additions & 34 deletions locations/templates/locations/your_locations.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,26 @@
{% load pagination_tags %}

{% block head_title %}All Locations{% endblock %}
{% block extra_head %}
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=.Z4iD9nV34EdofUSyd_B5bLj5hrf6wiNszlLacUyxedUanphrJ_ibbMjlntY9eufKwtW"></script>
<style type="text/css">
div#ymap {
width: 300px; height: 200px; float: right; border: 1px solid grey;
}
</style>
{% endblock %}

{% block body %}
<form action="/locations/new/" method="POST" accept-charset="utf-8">
<form action="{% url loc_new %}" method="POST" accept-charset="utf-8">
<p>{{ location_form }}
<input type="submit" value="Search &rarr;"></p>
<input type="submit" value="Search &rarr;"></p>
</form>
<div id="ymap"></div>
{% autopaginate locations %}
{% for location in locations %}
{% if forloop.first %}
<script type="text/javascript">
function initialize_ymap()
{
// Create a map object
var map = new YMap(document.getElementById('ymap'));
var yPoint = new YGeoPoint({{ location.latitude }},{{ location.longitude }});
// Display the map centered on a geocoded location
map.drawZoomAndCenter(yPoint, 8);
// Create a new marker for an address
var myMarker = new YMarker(yPoint);
// Create some content to go inside the SmartWindow
var myMarkerContent = "{{request.user}} checked in at {{location.place}}";
// When the marker is clicked, show the SmartWindow
YEvent.Capture(myMarker, EventsList.MouseClick,
function() {
myMarker.openSmartWindow(myMarkerContent);
});
// Put the marker on the map
map.addOverlay(myMarker);
}
</script>
{% endif %}
<p><a href="{{request.user.get_absolute_url}}">{{ request.user }}</a> checked in at {{ location.place }} at {{ location.time_checkin|date:"F d Y g:i a" }}</p>
{% include "locations/location.html" %}
{% endfor %}
{% paginate %}
{% endblock %}

{% block extra_body %}
<script type="text/javascript">
var _geo = new Array();
{% for location in locations %}
_geo[{{ forloop.counter0 }}] = [{{ location.latitude }}, {{ location.longitude }}, '{{ location.place }}'];
{% endfor %}
</script>
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid={{ YAHOO_MAPS_API_KEY }}"></script>
{% endblock %}
12 changes: 6 additions & 6 deletions locations/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.conf.urls.defaults import *

# Just a few url's. One for the new form and one for displaying checkins of the user and one for getting the search result
# Just a few url's. One for the new form and one for displaying checkins of the user and one for getting the search result
# and then checkin in to that place.

urlpatterns = patterns('',
url(r'^$', 'locations.views.your_locations', name='your_checkins'),
(r'^new/$', 'locations.views.new'),
(r'^checkin/$', 'locations.views.checkin'),
url(r'^friends/checkins/$', 'locations.views.friends_checkins', name='friends_checkins'),
url(r'^nearby/checkins/$', 'locations.views.nearby_checkins', name='nearby_checkins'),
url(r'^$', 'locations.views.your_locations', name='loc_yours'),
url(r'^new/$', 'locations.views.new', name='loc_new'),
url(r'^checkin/$', 'locations.views.checkin', name='loc_checkin'),
url(r'^friends/checkins/$', 'locations.views.friends_checkins', name='loc_friends'),
url(r'^nearby/checkins/$', 'locations.views.nearby_checkins', name='loc_nearby'),
)
Loading

0 comments on commit 03d7f3b

Please sign in to comment.