Permalink
Browse files

PEP8ification to make sure Sebastian doesn't kill me.... :-/

  • Loading branch information...
1 parent c496187 commit 77d4cde13f9655f8bcd66cab82fa353f7df892cb Moose committed Dec 6, 2012
Showing with 92 additions and 31 deletions.
  1. +1 −1 stores/admin.py
  2. +10 −2 stores/app.py
  3. +5 −1 stores/dashboard/app.py
  4. +6 −2 stores/dashboard/forms.py
  5. +1 −2 stores/managers.py
  6. +62 −20 stores/models.py
  7. +6 −2 stores/templatetags/store_stock.py
  8. +1 −1 stores/utils.py
View
@@ -9,4 +9,4 @@ class StoreAdmin(admin.ModelAdmin):
admin.site.register(models.Store, StoreAdmin)
admin.site.register(models.StoreGroup)
admin.site.register(models.OpeningPeriod)
-admin.site.register(models.StoreStock)
+admin.site.register(models.StoreStock)
View
@@ -14,8 +14,16 @@ def get_urls(self):
urlpatterns = super(StoresApplication, self).get_urls()
urlpatterns += patterns('',
- url(r'^$', self.list_view.as_view(), name='index'),
- url(r'^(?P<slug>[\w-]+)/$', self.detail_view.as_view(), name='detail'),
+ url(
+ r'^$',
+ self.list_view.as_view(),
+ name='index'
+ ),
+ url(
+ r'^(?P<slug>[\w-]+)/$',
+ self.detail_view.as_view(),
+ name='detail'
+ ),
)
return self.post_process_urls(urlpatterns)
View
@@ -26,7 +26,11 @@ class StoresDashboardApplication(Application):
def get_urls(self):
urlpatterns = patterns('',
- url(r'^$', self.store_list_view.as_view(), name='store-list'),
+ url(
+ r'^$',
+ self.store_list_view.as_view(),
+ name='store-list'
+ ),
url(
r'^create/$',
self.store_create_view.as_view(),
@@ -46,6 +46,10 @@ class Meta:
'name': forms.TextInput(
attrs={'placeholder': _("e.g. Christmas")}
),
- 'start': forms.TextInput(attrs={'placeholder': _("e.g. 9am, noon, etc.")}),
- 'end': forms.TextInput(attrs={'placeholder': _("e.g. 5pm, late, etc.")}),
+ 'start': forms.TextInput(
+ attrs={'placeholder': _("e.g. 9am, noon, etc.")}
+ ),
+ 'end': forms.TextInput(
+ attrs={'placeholder': _("e.g. 5pm, late, etc.")}
+ ),
}
View
@@ -1,4 +1,3 @@
-from django.db import models
from django.contrib.gis.db.models import GeoManager
from django.contrib.gis.db.models.query import GeoQuerySet
@@ -15,4 +14,4 @@ def get_query_set(self):
return StoreQuerySet(self.model)
def pickup_stores(self):
- return self.get_query_set().pickup_stores()
+ return self.get_query_set().pickup_stores()
View
@@ -11,7 +11,8 @@
from stores.managers import StoreManager
-STORES_SRID = getattr(settings, 'STORES_SRID', 4326)
+STORES_SRID = getattr(settings, 'STORES_SRID', 4326)
+
class StoreAddress(AbstractAddress):
store = models.OneToOneField(
@@ -40,7 +41,7 @@ class StoreContact(models.Model):
phone = models.CharField(_('Phone'), max_length=20, blank=True, null=True)
email = models.CharField(_('Email'), max_length=100, blank=True, null=True)
- store = models.OneToOneField('stores.Store', name=_("Store"),
+ store = models.OneToOneField('stores.Store', verbose_name=_("Store"),
related_name="contact_details")
def __unicode__(self):
@@ -68,10 +69,15 @@ class Store(models.Model):
blank=True, null=True
)
- location = PointField(_("Location"), null=True, blank=True, srid=STORES_SRID)
+ location = PointField(
+ _("Location"),
+ null=True,
+ blank=True,
+ srid=STORES_SRID
+ )
group = models.ForeignKey('stores.StoreGroup', related_name='stores',
- name=_("Group"), null=True, blank=True)
+ verbose_name=_("Group"), null=True, blank=True)
is_pickup_store = models.BooleanField(_("Is pickup store"), default=True)
is_active = models.BooleanField(_("Is active"), default=True)
@@ -99,18 +105,26 @@ class OpeningPeriod(models.Model):
SATURDAY: _("Saturday"),
SUNDAY: _("Sunday"),
}
- store = models.ForeignKey('stores.Store', name=_("Store"),
+ store = models.ForeignKey('stores.Store', verbose_name=_("Store"),
related_name='opening_periods')
weekday_choices = [(k, v) for k, v in WEEK_DAYS.items()]
- weekday = models.PositiveIntegerField(_("Weekday"),
- choices=weekday_choices)
+ weekday = models.PositiveIntegerField(
+ _("Weekday"),
+ choices=weekday_choices
+ )
start = models.CharField(
- _("Start"), max_length=30, null=True, blank=True,
+ _("Start"),
+ max_length=30,
+ null=True,
+ blank=True,
help_text=_("Leaving start and end time empty is displayed as 'Closed'")
)
end = models.CharField(
- _("End"), max_length=30, null=True, blank=True,
+ _("End"),
+ max_length=30,
+ null=True,
+ blank=True,
help_text=_("Leaving start and end time empty is displayed as 'Closed'")
)
@@ -135,27 +149,55 @@ class Meta:
class StoreStock(models.Model):
- store = models.ForeignKey('stores.Store',
- related_name='stock')
- product = models.ForeignKey('catalogue.Product', related_name="store_stock")
-
+ store = models.ForeignKey(
+ 'stores.Store',
+ verbose_name=_("Store"),
+ related_name='stock'
+ )
+ product = models.ForeignKey(
+ 'catalogue.Product',
+ verbose_name=_("Product"),
+ related_name="store_stock"
+ )
# Stock level information
- num_in_stock = models.PositiveIntegerField(_("Number in stock"), default=0, blank=True, null=True)
+ num_in_stock = models.PositiveIntegerField(
+ _("Number in stock"),
+ default=0,
+ blank=True,
+ null=True
+ )
# The amount of stock allocated in store but not fed back to the master
- num_allocated = models.IntegerField(_("Number allocated"), default=0, blank=True, null=True)
+ num_allocated = models.IntegerField(
+ _("Number allocated"),
+ default=0,
+ blank=True,
+ null=True
+ )
- location = models.CharField(_("In store location"), max_length=50, blank=True, null=True)
+ location = models.CharField(
+ _("In store location"),
+ max_length=50,
+ blank=True,
+ null=True
+ )
# Date information
- date_created = models.DateTimeField(_("Date Created"), auto_now_add=True)
- date_updated = models.DateTimeField(_("Date Updated"), auto_now=True, db_index=True)
+ date_created = models.DateTimeField(
+ _("Date Created"),
+ auto_now_add=True
+ )
+ date_updated = models.DateTimeField(
+ _("Date Updated"),
+ auto_now=True,
+ db_index=True
+ )
class Meta:
verbose_name = _("Store Stock Record")
verbose_name_plural = _("Store Stock Records")
- objects = GeoManager()
+ objects = GeoManager() # Needed for distance queries against stores
def __unicode__(self):
if self.store and self.product:
@@ -164,4 +206,4 @@ def __unicode__(self):
@property
def is_available_to_buy(self):
- return self.num_in_stock > self.num_allocated
+ return self.num_in_stock > self.num_allocated
@@ -5,11 +5,15 @@
register = template.Library()
+
@register.assignment_tag
def store_stock_for_product(product, location=None, limit=20):
query_set = StoreStock.objects.filter(product=product)
if location:
- query_set = query_set.distance(location, field_name='store__location').order_by('distance')
+ query_set = query_set.distance(
+ location,
+ field_name='store__location'
+ ).order_by('distance')
else:
query_set = query_set.order_by('store__name')
- return query_set[0:limit]
+ return query_set[0:limit]
View
@@ -4,4 +4,4 @@ def get_current_ip(request):
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
- return ip
+ return ip

0 comments on commit 77d4cde

Please sign in to comment.