Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/iwillig/fixcity
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Mayle committed Nov 16, 2009
2 parents f3b7721 + 111a13a commit 4320c79
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 111 deletions.
5 changes: 1 addition & 4 deletions fixcity/bmabr/models.py
Expand Up @@ -23,10 +23,9 @@ def __unicode__(self):
class Rack(models.Model):
address = models.CharField(max_length=200)
title = models.CharField(max_length=50)
date = models.DateTimeField()
date = models.DateTimeField()
description = models.CharField(max_length=300, blank=True)
email = models.EmailField()
communityboard = models.ForeignKey(CommunityBoard)
photo = ImageWithThumbnailsField(
upload_to='images/racks/',
thumbnail={'size': (100, 100)},
Expand All @@ -44,8 +43,6 @@ class Rack(models.Model):
objects = models.GeoManager()


class Meta:
ordering = ['communityboard']

def __unicode__(self):
return self.address
Expand Down
8 changes: 2 additions & 6 deletions fixcity/bmabr/templates/newrack.html
Expand Up @@ -70,17 +70,13 @@
</div>
<input type="hidden" name="date" value="{% now "Y-m-d H:i:s" %}"/>

<!-- <input type="text" id="cb_show" value="1" /> -->
<input type="hidden" id="id_communityboard" name="communityboard" value="" />

<!-- These flags will trigger server-side processing of location &
communityboard if they're set to zero. We use this to hack around
<!-- These flags will trigger server-side processing of location
if set to zero. We use this to hack around
the impossibility of knowing if asynch functions have finished
when the form submits. Also provides a bit of graceful
degrading... not like we have a lot of that in a map-heavy
site. -->
<input type="hidden" id="geocoded" name="geocoded" value="0" />
<input type="hidden" id="got_communityboard" name="got_communityboard" value="0" />

<input type="submit" value="Add this rack!" />

Expand Down
9 changes: 2 additions & 7 deletions fixcity/bmabr/templates/update_rack.html
Expand Up @@ -72,22 +72,17 @@
<!-- XXX Do we want to update date on edit? -->
<input type="hidden" name="date" value="{{rack.date}}"/>

<!-- <input type="text" id="cb_show" value="1" /> -->
<input type="hidden" id="id_communityboard" name="communityboard" value="{{rack.communityboard_id}}" />


<div id="email-wrap">
<label>Created By</label>
<div>{{creator}}</div>
</div>
<!-- These flags will trigger server-side processing of location &
communityboard if they're set to zero. We use this to hack around
<!-- These flags will trigger server-side processing of location
if set to zero. We use this to hack around
the impossibility of knowing if asynch functions have finished
when the form submits. Also provides a bit of graceful
degrading... not like we have a lot of that in a map-heavy
site. -->
<input type="hidden" id="geocoded" name="geocoded" value="0" />
<input type="hidden" id="got_communityboard" name="got_communityboard" value="0" />

<div id="verified-wrap">
<label for="verified">Verified</label>
Expand Down
70 changes: 21 additions & 49 deletions fixcity/bmabr/views.py
Expand Up @@ -120,24 +120,6 @@ def built(request):
)


def _get_communityboard_id(lon, lat):
# Cache a bit, since that's easier than ensuring that our AJAX
# code doesn't call it with the same params a bunch of times.
lon, lat = float(lon), float(lat)
key = ('_get_communityboard_id', lon, lat)
cb_id = cache.get(key)
if cb_id is None:
pnt = Point(lon, lat, srid=SRID)
cb = CommunityBoard.objects.get(the_geom__contains=pnt)
cb_id = cb.gid
cache.set(key, cb_id, 60 * 10)
return cb_id

def get_communityboard(request):
lat = request.REQUEST['lat']
lon = request.REQUEST['lon']
return HttpResponse(_get_communityboard_id(lon, lat))

def _geocode(text):
# Cache a bit, since that's easier than ensuring that our AJAX
# code doesn't call it with the same params a bunch of times.
Expand Down Expand Up @@ -259,8 +241,8 @@ def verify_by_communityboard(request,cb_id):

def _preprocess_rack_form(postdata):
"""Handle an edge case where the form is submitted before the
client-side ajax code finishes setting the location and/or
community board. This can easily happen eg. if the user types an
client-side ajax code finishes setting the location.
This can easily happen eg. if the user types an
address and immediately hits return or clicks submit.
Also do any other preprocessing needed.
Expand All @@ -278,11 +260,6 @@ def _preprocess_rack_form(postdata):
else:
postdata[u'location'] = str(Point(lon, lat, srid=SRID))

if postdata[u'got_communityboard'] != u'1' \
or not postdata[u'communityboard']:
if postdata.get('location', '').strip():
pnt = fromstr(postdata['location'], srid=SRID)
postdata['communityboard'] = _get_communityboard_id(pnt.x, pnt.y)
# Handle a registered user submitting without logging in...
# eg. via email.
user = postdata.get('user', '').strip()
Expand Down Expand Up @@ -343,32 +320,27 @@ def newrack_json(request):
post = request.POST.copy()
post.clear() # it doesn't have anything in useful form..
post.update(args)
try:
_preprocess_rack_form(post)
except CommunityBoard.DoesNotExist:
output = {'errors': {'communityboard': ['Sorry, we only handle addresses inside Brooklyn Community Board 1 at this time.']}}
_preprocess_rack_form(post)
rackresult = _newrack(post, files={})
if rackresult['errors']:
status = 400
# Annoyingly, the errors thingy is made of weird dict & list
# subclasses that I can't simply serialize.
errors = {}
for key, val in rackresult['errors'].items():
# it's a list subclass containing string subclasses.
errors[key] = [s[:] for s in val]
output = {'errors': errors}
else:
rackresult = _newrack(post, files={})
if rackresult['errors']:
status = 400
# Annoyingly, the errors thingy is made of weird dict & list
# subclasses that I can't simply serialize.
errors = {}
for key, val in rackresult['errors'].items():
# it's a list subclass containing string subclasses.
errors[key] = [s[:] for s in val]
output = {'errors': errors}
else:
status = 200
rack = rackresult['rack']
output = {'rack': rack.id,
'message': rackresult['message'],
'photo_post_url': '/rack/%d/photos/' % rack.id,
'rack_url': '/rack/%d/' % rack.id,
'user': rack.user,
'email': rack.email,
}
status = 200
rack = rackresult['rack']
output = {'rack': rack.id,
'message': rackresult['message'],
'photo_post_url': '/rack/%d/photos/' % rack.id,
'rack_url': '/rack/%d/' % rack.id,
'user': rack.user,
'email': rack.email,
}
return HttpResponse(json.dumps(output), mimetype='application/json',
status=status)

Expand Down
20 changes: 0 additions & 20 deletions fixcity/media/js/rackmap.js
Expand Up @@ -47,7 +47,6 @@ function loadMap(draggable) {
var xy = address_point.geometry.getBounds().getCenterLonLat();
xy.transform(map.projection, map.displayProjection);
getAddress(xy);
getCommunityBoard(xy);
var location_wkt = "POINT(" + xy.lon + " " + xy.lat + ")";
$("#location").val(location_wkt);
xy.transform(map.displayProjection, map.projection);
Expand Down Expand Up @@ -81,7 +80,6 @@ function loadMap(draggable) {
}
function getPointsFromAddress(address) {
$("#geocoded").val(0);
$("#got_communityboard").val(0);
$.get("/geocode/", {
geocode_text: address
},
Expand All @@ -90,7 +88,6 @@ function loadMap(draggable) {
var lon = results[0][1][1];
var lat = results[0][1][0];
var xy = new OpenLayers.LonLat(lon, lat);
getCommunityBoard(xy);
var location_wkt = "POINT(" + lon.toString() + " " + lat.toString() + ")";
$("#location").val(location_wkt);
$("#geocoded").val(1);
Expand All @@ -106,24 +103,8 @@ function loadMap(draggable) {
'json');
}

function getCommunityBoard(lonlat) {
var lat = lonlat.lat;
var lon = lonlat.lon;
$("#got_communityboard").val(0);
$.get("/getcommunityboard/", {
lat: lat,
lon: lon
},
function (data) {
$("#id_communityboard").val(data);
$("#got_communityboard").val(1);
});

}

// For users with JS, we only want to be forced to check on the back end if there's an unprocessed change
$("#geocoded").val(1);
$("#got_communityboard").val(1);

$("#address").bind("blur", function(event) {
getPointsFromAddress($("#address").val());
Expand All @@ -134,7 +115,6 @@ function loadMap(draggable) {
// For some reason, doing this on focus doesn't seem
// to be enough.
$("#geocoded").val(0);
$("#got_communityboard").val(0);
});

var navControl = map.getControlsByClass('OpenLayers.Control.Navigation')[0];
Expand Down
25 changes: 12 additions & 13 deletions fixcity/media/js/verify-rackmap.js
Expand Up @@ -82,13 +82,13 @@ function loadMap() {

// Once we support multiple statuses this will need to be updated
this_li.addClass("new");

if ( attrs.verified == null ) {
// XXX this always executes, even when the conditional is false!!
// why???
this_li.find("span.rack-verified").hide();
};

if (attrs.thumbnail != null) {
this_li.find("a.rack-thumbnail img").attr("src", attrs.thumbnail.value);
} else {
Expand All @@ -105,8 +105,7 @@ function loadMap() {
updatePagination(layer.features);
};
var load_rack_params = {
'page_size': 10,
// Make this user-controllable.
'page_size': 10, // Make this user-controllable.
'page_number': 1
};

Expand Down Expand Up @@ -152,16 +151,16 @@ function loadMap() {
var link_template = $("#pagination span[class=sectionlink]:first").clone();
$("#pagination span[class=sectionlink]").remove();
for (var i = 1; i <= num_pages; i++) {
var link = link_template.clone();
var a = link.find("a");
var pagelink = link_template.clone();
var a = pagelink.find("a");
a.click(makeClickHandler(i));
if (i == load_rack_params.page_number) {
a.removeAttr("href");
} else {
a.attr("href", "#page_number=" + i.toString());
};
a.text(i.toString());
link.insertBefore("#pagination a[rel=next]");
pagelink.insertBefore("#pagination a[rel=next]");
};
};
};
Expand All @@ -187,7 +186,7 @@ function loadMap() {
}
}
// Add new features
for (var index=0; index<newfeatures.length; ++index) {
for (index=0; index<newfeatures.length; ++index) {
var newf = newfeatures[index];
var found = false;
for (var search=0; search<layer.features.length; ++search) {
Expand Down Expand Up @@ -231,11 +230,11 @@ function loadMap() {
}
}
}


replaceFeatures(this.layer, resp.features);
this.layer.events.triggerEvent("loadend");
}
};
racks = new OpenLayers.Layer.Vector("Racks", {
projection: map.displayProjection,
strategies: [
Expand All @@ -256,15 +255,15 @@ function loadMap() {
// Big dirty hack!!!
var FixcityPopup = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
fixedRelativePosition: true,
relativePosition: "tl",
relativePosition: "tl",
initialize: function(id, lonlat, contentSize, contentHTML, anchor, closeBox, closeBoxCallback) {
OpenLayers.Popup.Framed.prototype.initialize.apply(this, arguments);
}
});
var featureSelected = function(feature) {
$('ul#racklist li').removeClass('selected').filter('#rack_' + feature.fid).addClass('selected');
var popup = new FixcityPopup(null, feature.geometry.getBounds().getCenterLonLat(),
null, feature.attributes.description,
null, '<strong>' + feature.attributes.name + '</strong><br />' + ((feature.attributes.description.length < 80 ) ? feature.attributes.description : feature.attributes.description.substr(0,80) + '…'),
{size: new OpenLayers.Size(1, 1), offset: new OpenLayers.Pixel(-40, 48)},
true, function() { selectControl.unselect(feature); });
feature.popup = popup;
Expand Down
29 changes: 17 additions & 12 deletions setup.py
Expand Up @@ -2,6 +2,22 @@

version='0.1dev'

install_requires=[
'geopy==dev,>=0.93dev-r84',
'sorl-thumbnail>=3.2.2',
'Django>=1.1.1',
'django-registration>=0.7',
'psycopg2>=2.0.12',
'PIL==1.1.6',
'wsgilog>=0.1',
'httplib2',
'poster',
]

import sys
if sys.version_info[:2] < (2, 6):
install_requires.append('ctypes>=1.0.2')

setup(name='fixcity',
version=version,
description="Build me a bike rack!",
Expand All @@ -16,16 +32,5 @@
'http://dist.repoze.org/PIL-1.1.6.tar.gz#egg=PIL-1.1.6',
'http://sourceforge.net/projects/ctypes/files/ctypes/1.0.2/ctypes-1.0.2.tar.gz/download#egg=ctypes-1.0.2',
],
install_requires=[
'geopy==dev,>=0.93dev-r84',
'sorl-thumbnail>=3.2.2',
'Django>=1.1.1',
'django-registration>=0.7',
'psycopg2>=2.0.12',
'PIL==1.1.6',
'ctypes>=1.0.2',
'wsgilog>=0.1',
'httplib2',
'poster',
],
install_requires=install_requires,
)

0 comments on commit 4320c79

Please sign in to comment.