diff --git a/fixcity/bmabr/models.py b/fixcity/bmabr/models.py index 4efd016..6444414 100755 --- a/fixcity/bmabr/models.py +++ b/fixcity/bmabr/models.py @@ -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)}, @@ -44,8 +43,6 @@ class Rack(models.Model): objects = models.GeoManager() - class Meta: - ordering = ['communityboard'] def __unicode__(self): return self.address diff --git a/fixcity/bmabr/templates/newrack.html b/fixcity/bmabr/templates/newrack.html index 1cd3902..38133a2 100644 --- a/fixcity/bmabr/templates/newrack.html +++ b/fixcity/bmabr/templates/newrack.html @@ -70,17 +70,13 @@ - - - - - diff --git a/fixcity/bmabr/templates/update_rack.html b/fixcity/bmabr/templates/update_rack.html index 19b089f..e56353b 100644 --- a/fixcity/bmabr/templates/update_rack.html +++ b/fixcity/bmabr/templates/update_rack.html @@ -72,22 +72,17 @@ - - - -
{{creator}}
- -
diff --git a/fixcity/bmabr/views.py b/fixcity/bmabr/views.py index c890a38..ae99c1e 100755 --- a/fixcity/bmabr/views.py +++ b/fixcity/bmabr/views.py @@ -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. @@ -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. @@ -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() @@ -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) diff --git a/fixcity/media/js/rackmap.js b/fixcity/media/js/rackmap.js index ff98446..be62ea4 100644 --- a/fixcity/media/js/rackmap.js +++ b/fixcity/media/js/rackmap.js @@ -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); @@ -81,7 +80,6 @@ function loadMap(draggable) { } function getPointsFromAddress(address) { $("#geocoded").val(0); - $("#got_communityboard").val(0); $.get("/geocode/", { geocode_text: address }, @@ -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); @@ -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()); @@ -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]; diff --git a/fixcity/media/js/verify-rackmap.js b/fixcity/media/js/verify-rackmap.js index 27ca43d..fc000ed 100644 --- a/fixcity/media/js/verify-rackmap.js +++ b/fixcity/media/js/verify-rackmap.js @@ -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 { @@ -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 }; @@ -152,8 +151,8 @@ 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"); @@ -161,7 +160,7 @@ function loadMap() { a.attr("href", "#page_number=" + i.toString()); }; a.text(i.toString()); - link.insertBefore("#pagination a[rel=next]"); + pagelink.insertBefore("#pagination a[rel=next]"); }; }; }; @@ -187,7 +186,7 @@ function loadMap() { } } // Add new features - for (var index=0; index' + feature.attributes.name + '
' + ((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; diff --git a/setup.py b/setup.py index d79590f..ecd53b9 100644 --- a/setup.py +++ b/setup.py @@ -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!", @@ -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, )