Initial commit

This commit is contained in:
Ryan McGrath 2010-10-27 14:53:51 -04:00
commit d5c605e4ad
22 changed files with 1372 additions and 0 deletions

View file

@ -0,0 +1,95 @@
{% extends "base.html" %}
{% block extra_head %}
<style type="text/css">
#add_location_submit {
margin: 10px auto;
padding: 8px 12px !important;
}
</style>
<!--
Load this in case geoLocation isn't supported... we'll drop back to trying to match by IP address. :\
Yes, load this *now*, don't get fancy with some JS-appending solution. Mobile browsers blow, and blow moreso
when there's no GPS to begin with. We'll take the resource hit.
-->
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAaTpZjip8OppqbtRhg6vhDhTp1xR-A-7MLZUGcs3iDfyOaBUtiRTos5hyCGDaGxeW2svzPD8IOHrMPg"></script>
<script type="text/javascript">
var _GPS = {
attempts: 0,
positionSuccess: function(x) {
document.getElementById("lat").value = x.coords.latitude;
document.getElementById("long").value = x.coords.longitude;
}
}
_GPS.getLocation = function() {
++_GPS.attempts;
if(navigator && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(_GPS.positionSuccess, function() { return; }, { enableHighAccuracy:true });
} else if(google.loader.ClientLocation.latitude && google.loader.ClientLocation.longitude) {
/* Little known trick - these get filled when you download jsapi, like we do above. Free geolocation, fairly reliable. ;D */
positionSuccess({
coords: {
latitude: google.loader.ClientLocation.latitude,
longitude: google.loader.ClientLocation.longitude
},
});
} else if(_GPS.attempts < 3) {
setTimeout(_GPS.getLocation, 1000);
} else {
alert("Your device doesn't seem to support GPS! We'll still let you add something, but please be as accurate as possible since we can't get your coordinates.");
}
};
</script>
{% endblock %}
{% block content %}
{% if error %}
<div class="error">
<p>{{ error }}</p>
</div>
{% endif %}
<form method="post" action="/locations/add/">
{% csrf_token %}
<h2>What's the name?</h2>
<p>
<label for="location_name">Ex: Churchkey, Buffalo Billiards, Fili's House</label>
<input type="text" name="location_name" value="">
</p>
<h2>Know the street address?</h2>
<p>
<label for="street_address">Optional, but helps narrow it down if GPS isn't accurate enough.</label>
<input type="text" name="street_address" value="">
</p>
<h2>What type of location is this?</h2>
<p>
<label for="location_type">Optional, but useful for people to know.</label>
<select name="location_type">
<option value="">Choose a category</option>
{% for type in category_choices %}
<option value="{{ type.id }}">{{ type.name }}</option>
{% endfor %}
</select>
</p>
<input type="hidden" name="lat" id="lat" value="">
<input type="hidden" name="long" id="long" value="">
<div id="button_center">
<input type="submit" value="Add This Location" id="add_location_submit" class="button large">
</div>
</form>
{% endblock %}

View file

@ -0,0 +1,32 @@
{% extends "base.html" %}
{% block extra_head %}
{% endblock %}
{% block content %}
<h2>Checkin To: {{ location.name }}</h2>
<p>
The following two questions are optional, but helpful
if you want to be found by other Redditors. If you don't want to answer them, just hit the checkin button below.
</p>
<form method="post" action="/locations/{{ location.id }}/checkin/">
{% csrf_token %}
<h2>How long do you think you'll be here?</h2>
<p>
<label for="estimated_time_here">Ex: 2 hours, until the sun rises</label>
<input type="text" name="estimated_time_here" value="">
</p>
<h2>How can other Redditors identify you?</h2>
<p>
<label for="identify_by">Ex: At the bar, wearing peace sign earings</label>
<input type="text" name="identify_by" value="">
</p>
<div id="button_center" style="margin-bottom: 14px;">
<input type="submit" value="Check In Here!" class="button large">
</div>
</form>
{% endblock %}

View file

@ -0,0 +1,100 @@
{% extends "base.html" %}
{% block extra_head %}
<style type="text/css">
#add_location_submit {
margin: 10px auto;
padding: 8px 12px !important;
}
</style>
<!--
Load this in case geoLocation isn't supported... we'll drop back to trying to match by IP address. :\
Yes, load this *now*, don't get fancy with some JS-appending solution. Mobile browsers blow, and blow moreso
when there's no GPS to begin with. We'll take the resource hit.
-->
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAaTpZjip8OppqbtRhg6vhDhTp1xR-A-7MLZUGcs3iDfyOaBUtiRTos5hyCGDaGxeW2svzPD8IOHrMPg"></script>
<script type="text/javascript">
var _GPS = {
attempts: 0,
positionSuccess: function(x) {
document.getElementById("lat").value = x.coords.latitude;
document.getElementById("long").value = x.coords.longitude;
/*
Try to force-submit the form after we've got our values; if it fails, hide the loading text
so the user is "prompted" to submit it.
*/
try {
document.getElementById("bertform").submit();
} catch(e) {
document.getElementById("bert").style.display = "none";
}
}
}
_GPS.getLocation = function() {
++_GPS.attempts;
if(navigator && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(_GPS.positionSuccess, function() { return; }, { enableHighAccuracy:true });
} else if(google.loader.ClientLocation.latitude && google.loader.ClientLocation.longitude) {
/* Little known trick - these get filled when you download jsapi, like we do above. Free geolocation, fairly reliable. ;D */
positionSuccess({
coords: {
latitude: google.loader.ClientLocation.latitude,
longitude: google.loader.ClientLocation.longitude
},
});
} else if(_GPS.attempts < 3) {
setTimeout(_GPS.getLocation, 1000);
} else {
alert("Your device doesn't seem to support GPS! We'll still let you add something, but please be as accurate as possible since we can't get your coordinates.");
}
};
</script>
{% endblock %}
{% block content %}
<!--
If you complain about this stuff in a mobile environment that's targetting browsers
worse than IE6, you should just stop using the internet now. ;P
-->
<div style="text-align: center;">
{% if error %}
<div class="error">
<p>{{ error }}</p>
</div>
{% endif %}
<form id="bertform" method="post" action="/locations/nearby/">
{% csrf_token %}
<h2>Getting your current position...</h2>
<p>
This should automagically redirect you to nearby results.
</p>
<p>
If it doesn't, please wait until the "loading..." text below disappears,
and then click the button below to force your browser to get results (<em>older phones may need to do this</em>).
</p>
<input type="hidden" name="lat" id="lat" value="">
<input type="hidden" name="long" id="long" value="">
<div id="button_center">
<input type="submit" value="Add This Location" id="add_location_submit" class="button large">
</div>
<div id="bert" style="margin-bottom: 10px;">
Loading...
</div>
</form>
</div>
{% endblock %}

View file

@ -0,0 +1,45 @@
{% extends "base.html" %}
{% block extra_head %}
{% endblock %}
{% block content %}
<h2>Where all the DC Redditors at?</h2>
<p>
Check out where other DC Redditors are drinking! If you'd like to join in, register or log in using the buttons
at the top right of the screen.
</p>
<p>
By using this, you should be fully aware that other Redditors can find out where you're at. Consider this a little "social experiment".
This was built out of boredom by <a href="http://reddit.com/user/ryanmcgrath">Ryan McGrath</a>; if you have questions or comments, feel free
to message him on Reddit.
</p>
<h2>Redditors around DC</h2>
<ul id="results">
{% for checkin in checkins.object_list %}
<li class="top_level">
<a href="/locations/{{ checkin.location.id }}/" class="go_location button">View</a>
<a href="/locations/{{ checkin.location.id }}/">
<span class="location_name">{{ checkin.location.name }}</span>
<ul>
<li><strong>{{ checkin.user.username }}</strong> checked in here {{ checkin.timestamp|timesince }} ago</li>
</ul>
</a>
</li>
{% endfor %}
</ul>
<ul id="pagination">
{% if checkins.has_previous %}
<li><a href="?page={{ results.previous_page_number }}">Previous Results</a></li>
{% endif %}
{% if checkins.has_next %}
<li><a href="?page={{ results.previous_page_number }}">More Results</a></li>
{% endif %}
</ul>
{% endblock %}

View file

@ -0,0 +1,66 @@
{% extends "base.html" %}
{% block extra_head %}
<style type="text/css">
#search_btn {
margin: 10px auto;
padding: 8px 12px !important;
}
</style>
{% endblock %}
{% block content %}
<form method="post" action="/locations/search/">
{% csrf_token %}
<h2>Find Locations in DC</h2>
<p>
<label for="location_name">Ex: Churchkey, Buffalo Billiards, Rocket Bar</label>
<input type="text" name="search_query" value="{{ search_query|default:"" }}">
</p>
<div id="button_center">
<input type="submit" value="Find Locations" id="search_btn" class="button large">
</div>
</form>
{% if performed_search %}
{% if results.object_list %}
<h2>Results for {{ search_query }}</h2>
<ul id="results">
{% for location in results.object_list %}
<li class="top_level">
<a href="/locations/{{ checkin.location.id }}/" class="go_location button">View</a>
<a href="/locations/{{ location.id }}/">
<span class="location_name">{{ location.name }}</span>
<ul>
<li><strong>Recent Checkins:</strong> {{ location.get_recent_checkins_count }}</li>
<li><strong>Address:</strong> {{ location.street_address|default:"No address set" }}</li>
<li><strong>Category:</strong> {{ location.category|default:"No category set" }}</li>
</ul>
</a>
</li>
{% endfor %}
</ul>
<ul id="pagination">
{% if results.has_previous %}
<li><a href="?page={{ results.previous_page_number }}">Previous Results</a></li>
{% endif %}
{% if results.has_next %}
<li><a href="?page={{ results.previous_page_number }}">More Results</a></li>
{% endif %}
</ul>
{% else %}
<h2>No Results for {{ search_query }}</h2>
<p>
No locations in the Drinkkit database match what you're looking for. If where you are isn't listed,
you should feel free to add it so other Redditors can find it!
</p>
{% endif %}
{% endif %}
{% endblock %}

View file

@ -0,0 +1,44 @@
{% extends "base.html" %}
{% block extra_head %}
<style type="text/css">
#search_btn {
margin: 10px auto;
padding: 8px 12px !important;
}
</style>
{% endblock %}
{% block content %}
{% if nearby %}
<h2>Nearby you right now</h2>
<ul id="results">
{% for location in nearby %}
<li class="top_level">
<a href="/locations/{{ checkin.location.id }}/" class="go_location button">View</a>
<a href="/locations/{{ location.id }}/">
<span class="location_name">{{ location.name }}</span>
<ul>
<li><strong>Recent Checkins:</strong> {{ location.get_recent_checkins_count }}</li>
<li><strong>Address:</strong> {{ location.street_address|default:"No address set" }}</li>
<li><strong>Category:</strong> {{ location.category|default:"No category set" }}</li>
</ul>
</a>
</li>
{% endfor %}
</ul>
{% else %}
<h2>All's quiet on the Eastern Front :(</h2>
<p>
We couldn't find anything going on near you. The GPS in your device might not be accurate enough for this feature, or we
may be experiencing some difficulty. If you think it's the former (you know your device better than I do (that's what she said)),
please feel free to retry this feature in a few minutes.
</p>
<p>
The third option, of course, is that it's very possible nobody's out and about. They are Redditors, after all. ;)
</p>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,197 @@
{% extends "base.html" %}
{% block extra_head %}
<style type="text/css">
#map {
margin: 10px auto;
width: 98%;
height: 300px;
}
#bert { text-align: center; }
#tip_body {
display: block;
padding: 3px;
width: 95%;
height: 100px;
border-color: #b2b2b2;
margin: 10px auto;
-webkit-border-radius: 2px;
}
#submit_tip { margin-bottom: 10px; }
#tips li, #checkins li {
margin-bottom: 15px;
font-size: 13px;
}
.comment_header {
display: block;
border-bottom: 1px dotted #555;
padding-bottom: 2px;
margin-bottom: 2px;
}
#tips strong { font-size: 14px; }
#checkins span strong { font-size: 14px; color: #ff8070;}
#location_details { position: relative; }
.pointers { font-weight: bold; color: #666; }
#checkin_here_link, #checked_in_already {
position: absolute;
top: 10px;
right: 10px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
text-decoration: none;
color: #fff;
font-weight: bold;
}
#checkin_here_link {
background-color: #ff4500;
border: 1px solid #ff4500;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ff9f7b), to(#ff4500));
font-size: 20px;
padding: 7px 12px;
}
#checked_in_already {
background-color: #cdcdcd;
border: 1px solid #8f8f8f;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f2f2f2), to(#cdcdcd));
font-size: 14px;
padding: 7px 10px;
color: #888;
}
#annotations { padding-bottom: 0px !important; }
#annotations li {
margin-bottom: 10px;
font-size: 12px;
}
#annoations strong { display: block; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var geocoder, map;
function generateMap() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng({{ location.geometry.x }}, {{ location.geometry.y }});
var opts = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
document.getElementById("bad_browser_map").style.display = "none";
map = new google.maps.Map(document.getElementById("map"), opts);
{% if location.street_address %}
/*
Since we happen to have an address stored, we'll geocode it instead of using the stored/reported
GPS coordinates, as that'll be more accurate overall. We can still use the GPS coordinates to center
the map ahead of time, though, which we do above (see: opts/center).
*/
geocoder.geocode({'address': "{{ location.address_for_geocode}},Washington,DC"}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
{% else %}
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: '{{ location.name }}'
});
{% endif %}
}
</script>
{% endblock %}
{% block content %}
<h2>{{ location.name }}</h2>
<div id="location_details">
<ul id="annotations">
<li><strong>Category:</strong> {{ location.category|default:"Not Specified :(" }}</li>
<li><strong>Address:</strong> {{ location.street_address|default:"Not Specified :(" }}</li>
</ul>
{% if user.is_authenticated %}
{% if allow_checkin %}
<a href="/locations/{{ location.id }}/checkin/" id="checkin_here_link">Check In Here</a>
{% else %}
<div id="checked_in_already">Already Checked In</div>
{% endif %}
{% endif %}
</div>
<h2>Map of the area</h2>
<div id="map">
{% if location.street_address %}
<img id="bad_browser_map" src="http://maps.google.com/maps/api/staticmap?center={{ location.address_for_geocode}},Washington,DC&sensor=true&zoom=16&size=300x300">
{% else %}
<img id="bad_browser_map" src="http://maps.google.com/maps/api/staticmap?center={{ location.geometry.x }},{{ location.geometry.y }}&sensor=true&zoom=16&size=300x300">
{% endif %}
</div>
<script type="text/javascript">
try { generateMap(); } catch(e) { /* Bad browser, most likely. Oh well, they still got a static map. ;P */ }
</script>
<h2>Recently checked in here</h2>
{% if recent_checkins %}
<ul id="checkins">
{% for checkin in recent_checkins %}
<li>
<span class="comment_header"><strong>{{ checkin.user.username }}</strong> <em>{{ checkin.timestamp|timesince }} ago</em></span>
<span class="pointers">Can be identified by:</span> {{ checkin.identify_by|default:"Doesn't want to be found. :(" }}<br>
<span class="pointers">Estimated time spent here:</span> {{ checkin.estimated_time_here|default:"They're flying by the seat of their vintage pants (no idea)."}}
</li>
{% endfor %}
</ul>
{% else %}
<p class="none_yet">No checkins yet. You could be the first!</p>
{% endif %}
{% if user.is_authenticated %}
<h2>Leave a Tip or Todo</h2>
<form action="/locations/{{ location.id }}/add_tip/" method="post" id="bert">
{% csrf_token %}
<textarea name="tip_body" id="tip_body"></textarea>
<input type="submit" value="Post Tip" id="submit_tip" class="button large">
</form>
{% endif %}
<h2>Tips &amp; Todos from Redditors</h2>
{% if location.tip_set.all %}
<ul id="tips">
{% for tip in location.tip_set.all %}
<li>
<span class="comment_header"><strong>{{ tip.user.username }}</strong> <em>{{ tip.timestamp|timesince }} ago</em></span>
{{ tip.tip }}
</li>
{% endfor %}
</ul>
{% else %}
<p class="none_yet">No tips yet. Be the first and add one!</p>
{% endif %}
{% endblock %}