From 49e341604b29a7ea788ac269a6d962f5556a6ab0 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sat, 13 Apr 2013 20:38:14 +0100 Subject: [PATCH] Various small PEP8 cleanups --- app/stores/admin.py | 11 +++++++---- app/stores/api.py | 2 +- app/stores/context_processors.py | 1 + app/stores/forms.py | 2 +- app/stores/management/commands/import_stores.py | 12 ++++++------ app/stores/urls.py | 2 +- app/stores/views/search.py | 3 ++- app/stores/views/stores.py | 10 ++++++---- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/stores/admin.py b/app/stores/admin.py index 29e458e..b3c22d1 100644 --- a/app/stores/admin.py +++ b/app/stores/admin.py @@ -24,6 +24,7 @@ class ChainAdmin(admin.ModelAdmin): LinkInlineAdmin, ] + class StoreAdmin(admin.ModelAdmin): list_filter = ['chain', 'active'] list_display = ['name', 'store_type', 'active', 'changed'] @@ -63,7 +64,8 @@ class StoreAdmin(admin.ModelAdmin): return HttpResponseRedirect(request.get_full_path()) if not form: form = self.AddBrandForm(initial={'_selected_action': queryset.values_list('id', flat=True)}) - return render_to_response('admin/add_brand.html', {'stores': queryset, 'brand_form': form}, RequestContext(request)) + return render_to_response('admin/add_brand.html', {'stores': queryset, 'brand_form': form}, + RequestContext(request)) add_brand.short_description = "Add brand to the selected stores" @@ -88,7 +90,8 @@ class StoreAdmin(admin.ModelAdmin): return HttpResponseRedirect(request.get_full_path()) if not form: form = self.SetChainForm(initial={'_selected_action': queryset.values_list('id', flat=True)}) - return render_to_response('admin/set_chain.html', {'stores': queryset, 'chain_form': form }, RequestContext(request)) + return render_to_response('admin/set_chain.html', {'stores': queryset, 'chain_form': form}, + RequestContext(request)) set_chain.short_description = "Set the selected store's chain" @@ -98,7 +101,6 @@ class ClaimAdmin(admin.ModelAdmin): list_display = ['generic_obj', 'user', 'status', 'note'] actions = ['approve_request'] - def approve_request(self, request, queryset): qs = queryset.filter(status=ClaimRequest.CLAIM_STATUS_PENDING) with transaction.commit_on_success(): @@ -145,7 +147,8 @@ class CountyAdmin(admin.ModelAdmin): return HttpResponseRedirect(request.get_full_path()) if not form: form = self.SetCountryForm(initial={'_selected_action': queryset.values_list('id', flat=True)}) - return render_to_response('admin/set_country.html', {'stores': queryset, 'country_form': form}, RequestContext(request)) + return render_to_response('admin/set_country.html', {'stores': queryset, 'country_form': form}, + RequestContext(request)) set_country.short_description = "Set the selected county's country" diff --git a/app/stores/api.py b/app/stores/api.py index f05bc85..267bc83 100644 --- a/app/stores/api.py +++ b/app/stores/api.py @@ -1,5 +1,5 @@ from django.forms.models import model_to_dict -from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS +from tastypie.resources import ModelResource from stores.models import County, Country diff --git a/app/stores/context_processors.py b/app/stores/context_processors.py index 7040132..6dba660 100644 --- a/app/stores/context_processors.py +++ b/app/stores/context_processors.py @@ -1,6 +1,7 @@ from django.contrib.sites.models import Site from .models import ClaimRequest, Store + def site(request): return { 'site': Site.objects.get_current() diff --git a/app/stores/forms.py b/app/stores/forms.py index f4de6cf..f148560 100644 --- a/app/stores/forms.py +++ b/app/stores/forms.py @@ -40,7 +40,7 @@ class StoreForm(BootstrapModelForm): 'long_description': 'input-xxlarge', } widgets = { - 'long_description': EpicEditorWidget(attrs={'rows': 40}, themes={'editor':'epic-light.css'}) + 'long_description': EpicEditorWidget(attrs={'rows': 40}, themes={'editor': 'epic-light.css'}) } diff --git a/app/stores/management/commands/import_stores.py b/app/stores/management/commands/import_stores.py index 0b726e2..1444bae 100644 --- a/app/stores/management/commands/import_stores.py +++ b/app/stores/management/commands/import_stores.py @@ -12,13 +12,13 @@ class Command(BaseCommand): help = 'Import a list of stores from CSV' def handle(self, *args, **options): - file = args[0] - if file.startswith('http'): - self.stdout.write("Downloading %s\n" % file) - f = StringIO(requests.get(file).text) + fn = args[0] + if fn.startswith('http'): + self.stdout.write("Downloading %s\n" % fn) + f = StringIO(requests.get(fn).text) else: - self.stdout.write("Opening file %s\n" % file) - f = open(file, 'r') + self.stdout.write("Opening file %s\n" % fn) + f = open(fn, 'r') self.stdout.write('Formatting data...') # Generate the dataset diff --git a/app/stores/urls.py b/app/stores/urls.py index ea6c35e..0d214eb 100644 --- a/app/stores/urls.py +++ b/app/stores/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import patterns, url from stores.views import * from stores.forms import AddressForm, StoreForm from stores.models import Store, Chain diff --git a/app/stores/views/search.py b/app/stores/views/search.py index 6859617..2de0a70 100644 --- a/app/stores/views/search.py +++ b/app/stores/views/search.py @@ -34,7 +34,8 @@ class DistanceSearchView(ListView): return SearchQuerySet.none distance = self.get_distance() print location, distance - return SearchQuerySet().dwithin('location', location, distance).distance('location', location).order_by('-distance') + return SearchQuerySet().dwithin('location', location, distance)\ + .distance('location', location).order_by('-distance') def get_context_data(self, **kwargs): ctx = super(DistanceSearchView, self).get_context_data(**kwargs) diff --git a/app/stores/views/stores.py b/app/stores/views/stores.py index 3aab72f..b0f87a1 100644 --- a/app/stores/views/stores.py +++ b/app/stores/views/stores.py @@ -19,7 +19,7 @@ class StoreListView(HaystackSearchListMixin, ListView): if search: ctx.update({ 'search_query': search, - }) + }) return ctx def get_queryset(self): @@ -57,7 +57,7 @@ class StockistStoreListView(StoreListView): ctx = super(StockistStoreListView, self).get_context_data(**kwargs) ctx.update({ 'brand': self.brand, - }) + }) return ctx def get_queryset(self): @@ -70,7 +70,8 @@ class StoreDetailView(EditorCheckMixin, DetailView): def get_queryset(self): qs = super(StoreDetailView, self).get_queryset() - return qs.filter(active=True).select_related('address', 'address__county', 'address__country', 'chain').prefetch_related('brands') + return qs.filter(active=True).select_related('address', 'address__county', 'address__country', 'chain')\ + .prefetch_related('brands') class StoreUpdateView(UpdateView): @@ -98,7 +99,8 @@ class StoreCreateView(SessionWizardView): store_obj.active = False store_obj.save() - messages.success(self.request, "%s has been sumbitted for moderation and should be visible within the next 24 hours." % store_obj) + messages.success(self.request, "%s has been sumbitted for moderation and should be visible within the " + "next 24 hours." % store_obj) return HttpResponseRedirect(reverse('map'))