Permalink
Browse files

pep8 / pyflakes

  • Loading branch information...
Justine Tunney
Justine Tunney committed Aug 17, 2012
1 parent eeba8ae commit dec165a876100b7bf292c6eccfb091ca44fed973
Showing with 163 additions and 152 deletions.
  1. +0 −1 occupywallst/urls.py
  2. +3 −1 rideshare/admin.py
  3. +48 −34 rideshare/forms.py
  4. +30 −38 rideshare/models.py
  5. +2 −1 rideshare/settings.py
  6. +1 −1 rideshare/urls.py
  7. +79 −76 rideshare/views.py
View
@@ -40,7 +40,6 @@
url(r'^notification/(?P<id>\d+)/$', 'occupywallst.views.notification', name='notification'),
url(r'^subscribe/(?P<id>\d+)/$', 'occupywallst.views.subscribe', name='subscribe'),
url(r'^confirm/(?P<token>[a-z0-9]+)/$', 'occupywallst.views.confirm', name='confirm'),
- #rides share
url(r'^rides/', include('rideshare.urls')),
url(r'^login/$', 'occupywallst.views.login', name='login'),
url(r'^logout/$', 'occupywallst.views.logout', name='logout'),
View
@@ -1,14 +1,16 @@
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
-from django.contrib.auth.admin import UserAdmin as BaseUserAdmin, GroupAdmin
+
from rideshare import models as db
+
class GeoAdmin(OSMGeoAdmin):
default_lat = 39.95 # philadelphia
default_lon = -75.16
default_zoom = 2
map_width = 750
map_height = 500
+
admin.site.register(db.RideRequest, GeoAdmin)
admin.site.register(db.Ride, GeoAdmin)
View
@@ -6,80 +6,94 @@
HTML form definitions.
"""
+
from django import forms
+
from rideshare import models as db
-class RideForm(forms.ModelForm):
+class RideForm(forms.ModelForm):
class Meta:
model = db.Ride
- fields = ( 'title','info','ridetype', 'seats_total', 'ride_direction','depart_time','return_time','start_address','end_address','waypoints','waypoints_points')
- exclude = ['published','seats_used', 'route', 'route_data', 'forum_post','waypoints_points']
-
+ fields = ('title', 'info', 'ridetype', 'seats_total',
+ 'ride_direction', 'depart_time', 'return_time',
+ 'start_address', 'end_address', 'waypoints',
+ 'waypoints_points')
+ exclude = ['published', 'seats_used', 'route', 'route_data',
+ 'forum_post', 'waypoints_points']
+
start_address = forms.CharField(required=True)
end_address = forms.CharField(required=True)
- waypoints = forms.CharField(required=False, widget=forms.Textarea, help_text="""Add other adresses or destinations separated by newlines to make you route more accurate""")
- waypoints_points_wkt = forms.CharField(required=False, widget=forms.HiddenInput)
-
+ waypoints = forms.CharField(
+ required=False, widget=forms.Textarea, help_text="""
+ Add other adresses or destinations separated by newlines to make
+ you route more accurate""")
+ waypoints_points_wkt = forms.CharField(
+ required=False, widget=forms.HiddenInput)
+
def __init__(self, *args, **kwargs):
-
- super(RideForm,self).__init__(*args,**kwargs)
+ super(RideForm, self).__init__(*args, **kwargs)
self.fields['seats_total'].label = "Seats available"
self.fields['waypoints'].label = "Waypoints(optional)"
self.fields['info'].label = "Ride Description"
-
- if kwargs.has_key('instance') and kwargs['instance']:
+
+ if 'instance' in kwargs and kwargs['instance']:
instance = kwargs['instance']
#pdb.set_trace()
self.initial['waypoints_points_wkt'] = instance.waypoints_points
self.initial['start_address'] = instance.waypoint_list[0]
self.initial['end_address'] = instance.waypoint_list[-1]
self.initial['waypoints'] = '\n'.join(instance.waypoint_list[1:-1])
-
+
def save(self, commit=True):
from django.contrib.gis.geos import GEOSGeometry
model = super(RideForm, self).save(commit=False)
-
+
points = GEOSGeometry(self.cleaned_data['waypoints_points_wkt'])
#pdb.set_trace()
- model.waypoints_points = points
-
+ model.waypoints_points = points
+
if self.cleaned_data['waypoints'] != '':
- self.cleaned_data['waypoints'] = self.cleaned_data['waypoints'] + '\n'
- model.waypoints = self.cleaned_data['start_address'] + "\n" + self.cleaned_data['waypoints'] + self.cleaned_data['end_address']
+ self.cleaned_data['waypoints'] = \
+ self.cleaned_data['waypoints'] + '\n'
+ model.waypoints = (self.cleaned_data['start_address'] + "\n" +
+ self.cleaned_data['waypoints'] +
+ self.cleaned_data['end_address'])
if commit:
model.save()
return model
-
+
+
class RideRequestForm(forms.ModelForm):
class Meta:
model = db.RideRequest
- exclude = ('rendezvous','user','status')
-
- rendezvous_lat = forms.FloatField(required=False,widget=forms.HiddenInput)
- rendezvous_lng = forms.FloatField(required=False,widget=forms.HiddenInput)
- rendezvous_address = forms.CharField(required=False, widget=forms.HiddenInput)
- seats_wanted = forms.IntegerField(required=False, widget=forms.Select)
-
- #Override the constructor to manually set the form's latitude and
+ exclude = ('rendezvous', 'user', 'status')
+
+ rendezvous_lat = forms.FloatField(
+ required=False, widget=forms.HiddenInput)
+ rendezvous_lng = forms.FloatField(
+ required=False, widget=forms.HiddenInput)
+ rendezvous_address = forms.CharField(
+ required=False, widget=forms.HiddenInput)
+ seats_wanted = forms.IntegerField(
+ required=False, widget=forms.Select)
+
+ # Override the constructor to manually set the form's latitude and
# longitude fields if a Location instance is passed into the form
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, **kwargs):
super(RideRequestForm, self).__init__(*args, **kwargs)
-
# Set the form fields based on the model object
- if kwargs.has_key('instance') and kwargs['instance']:
+ if 'instance' in kwargs and kwargs['instance']:
instance = kwargs['instance']
self.initial['rendezvous_lat'] = instance.rendezvous_lat
- self.initial['rendezvous_lng'] = instance.rendezvous_lng
+ self.initial['rendezvous_lng'] = instance.rendezvous_lng
def save(self, commit=True):
#commit = kwargs.pop('commit', True)
model = super(RideRequestForm, self).save(commit=False)
-
# Save the latitude and longitude based on the form fields
- model.rendezvous_latlng =self.cleaned_data['rendezvous_lng'], self.cleaned_data['rendezvous_lat']
-
+ model.rendezvous_latlng = (self.cleaned_data['rendezvous_lng'],
+ self.cleaned_data['rendezvous_lat'])
if commit:
model.save()
return model
-
View
@@ -1,9 +1,11 @@
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point, LineString
-from django.contrib.auth.models import User, Group
+from django.contrib.auth.models import User
+from django.core.exceptions import ObjectDoesNotExist
from occupywallst import geo
+
class Ride(models.Model):
"""Info about a person or bus driving to Event for carpooling"""
RIDETYPE_CHOICES = (
@@ -17,17 +19,17 @@ class Ride(models.Model):
('to', 'One Way too'),
('from', 'One Way from'),
)
-
- ride_direction = models.CharField(max_length=32, choices=RIDEDIR_CHOICES,
- default="round", help_text="""
+
+ ride_direction = models.CharField(
+ max_length=32, choices=RIDEDIR_CHOICES, default="round", help_text="""
What direction are you going?""")
-
user = models.ForeignKey(User, editable=False, help_text="""
User who is driving to event.""")
- published = models.DateTimeField(auto_now_add=True, blank=True, help_text="""
+ published = models.DateTimeField(
+ auto_now_add=True, blank=True, help_text="""
When was ride posted on the site?""")
- ridetype = models.CharField(max_length=32, choices=RIDETYPE_CHOICES,
- help_text="""
+ ridetype = models.CharField(
+ max_length=32, choices=RIDETYPE_CHOICES, help_text="""
What type of vehicle is being offered?""")
title = models.CharField(max_length=255, help_text="""
A one-line title to describe ride.""")
@@ -41,7 +43,8 @@ class Ride(models.Model):
List of addresses intersected by driving route separated by newlines.
Must contain at least two lines for origin and destination. This may
be updated to include people who will be picked up.""")
- waypoints_points = models.LineStringField(null=True, default=None, help_text="""
+ waypoints_points = models.LineStringField(
+ null=True, default=None, help_text="""
the points to the address of the waypoints""")
route = models.LineStringField(null=True, default=None, help_text="""
The driving route coords Google gave us from waypoints.""")
@@ -50,8 +53,8 @@ class Ride(models.Model):
info = models.TextField(blank=True, help_text="""
A little bit about yourself, the ride, and what to expect""")
#forum_post = models.ForeignKey(ForumPost, null=True, blank=True)
- is_deleted = models.BooleanField(default=False, editable=False,
- help_text="""
+ is_deleted = models.BooleanField(
+ default=False, editable=False, help_text="""
Flag to indicate should no longer be listed on site.""")
objects = models.GeoManager()
@@ -64,13 +67,6 @@ def __unicode__(self):
else:
return "%s's %s ride" % (self.user, self.ridetype)
- # def delete(self):
- # self.is_deleted = True
- # self.save()
- # super(Ride, self).delete(*args, **kwargs) # Call the "real" save() method.
-
-
-
@property
def pending_requests(self):
return self.requests.filter(status="pending")
@@ -95,7 +91,7 @@ def retrieve_route_from_google(self):
@property
def waypoint_list(self):
return [s.strip() for s in self.waypoints.split('\n') if s.strip()]
-
+
@property
def seats_avail(self):
accepted_requests = self.accepted_requests
@@ -108,6 +104,7 @@ def seats_avail(self):
def get_absolute_url(self):
return ('rideshare.views.ride_info', [self.id])
+
class RideRequest(models.Model):
"""List of pending/accepted/denied Ride requests
@@ -125,37 +122,30 @@ class RideRequest(models.Model):
('from', 'One Way from'),
)
-
-
- ride = models.ForeignKey(Ride, editable=False,
- related_name="requests", help_text="""
+ ride = models.ForeignKey(
+ Ride, editable=False, related_name="requests", help_text="""
The ride the user wants to get in on.""")
user = models.ForeignKey(User, help_text="""
The user who needs a ride to the event.""")
- status = models.CharField(max_length=32, choices=STATUS_CHOICES,
- default="pending", help_text="""
+ status = models.CharField(
+ max_length=32, choices=STATUS_CHOICES, default="pending", help_text="""
Current acceptance status of request.""")
-
- ride_direction = models.CharField(max_length=32, choices=RIDEDIR_CHOICES,
- default="round", help_text="""
+ ride_direction = models.CharField(
+ max_length=32, choices=RIDEDIR_CHOICES, default="round", help_text="""
What direction are you going?""")
-
info = models.TextField(blank=True, help_text="""
User explains why they think they deserve a ride.""")
- is_deleted = models.BooleanField(default=False, editable=False,
- help_text="""
+ is_deleted = models.BooleanField(
+ default=False, editable=False, help_text="""
Flag to indicate should no longer be listed on site.""")
- #maybe implement later
seats_wanted = models.IntegerField(default=1, help_text="""
how many seats the person is going to take up""")
-
rendezvous = models.PointField(null=True, blank=True, help_text="""
Aproximate coordinates of where they live to display on the
attendees map.""")
-
rendezvous_address = models.TextField(blank=True, help_text="""
the address given by reverse geocoding the rendezvous point""")
-
+
objects = models.GeoManager()
@property
@@ -171,10 +161,12 @@ class Meta:
def __unicode__(self):
return "%s wants seat in %s" % (self.user, self.ride)
-
+
#this is also defined twice
- rendezvous_lat = property(lambda s: s.rendezvous.y if s.rendezvous else None)
- rendezvous_lng = property(lambda s: s.rendezvous.x if s.rendezvous else None)
+ rendezvous_lat = property(
+ lambda s: s.rendezvous.y if s.rendezvous else None)
+ rendezvous_lng = property(
+ lambda s: s.rendezvous.x if s.rendezvous else None)
rendezvous_latlng = property(
lambda s: (s.rendezvous.y, s.rendezvous.x) if s.rendezvous else None,
lambda s, v: setattr(s, 'rendezvous', Point(v[1], v[0])))
View
@@ -6,5 +6,6 @@
This file is used to configure Rideshare
"""
+
DEFAULT_CITY = "New York, NY"
-DEFAULT_LOCATION = [40.744136,-73.989487]
+DEFAULT_LOCATION = [40.744136, -73.989487]
View
@@ -1,7 +1,7 @@
from django.conf import settings
from django.conf.urls.defaults import url, patterns, include
from django.views.decorators.http import require_GET, require_POST
-from . import views, admin
+from rideshare import views, admin
from occupywallst import utils
urlpatterns = patterns('rideshare',
Oops, something went wrong.

0 comments on commit dec165a

Please sign in to comment.