From 912661c412f342977e3f4e3629ba1effa05b9ffc Mon Sep 17 00:00:00 2001 From: Sebastian Vetter Date: Mon, 29 Jul 2013 07:59:54 +1000 Subject: [PATCH] Make code PEP8 compliant --- fancypages/abstract_models.py | 4 ++- fancypages/api/serialisers.py | 2 +- fancypages/api/urls.py | 3 +- fancypages/api/views.py | 10 +++--- fancypages/assets/app.py | 3 +- fancypages/assets/forms/widgets.py | 10 ++++-- fancypages/assets/models.py | 2 +- fancypages/assets/views.py | 4 ++- fancypages/dashboard/app.py | 3 +- fancypages/dashboard/forms.py | 3 +- fancypages/dashboard/views.py | 6 ++-- fancypages/forms.py | 3 +- fancypages/loaders.py | 51 ----------------------------- fancypages/middleware.py | 11 ++++--- fancypages/mixins.py | 4 ++- fancypages/models/blocks/content.py | 10 ++++-- fancypages/urls.py | 3 +- fancypages/views.py | 3 +- 18 files changed, 54 insertions(+), 81 deletions(-) delete mode 100644 fancypages/loaders.py diff --git a/fancypages/abstract_models.py b/fancypages/abstract_models.py index 2bbf2de..750e69b 100644 --- a/fancypages/abstract_models.py +++ b/fancypages/abstract_models.py @@ -53,12 +53,14 @@ def save(self, update_slugs=True, *args, **kwargs): super(AbstractTreeNode, self).save(*args, **kwargs) def move(self, target, pos=None): + #:PEP8 -E501 """ Moves the current node and all its descendants to a new position relative to another node. - See https://tabo.pe/projects/django-treebeard/docs/1.61/api.html#treebeard.models.Node.move + See https://tabo.pe/projects/django-treebeard/docs/1.61/api.html """ + #:PEP8 +E501 super(AbstractTreeNode, self).move(target, pos) # Update the slugs and full names of all nodes in the new subtree. # We need to reload self as 'move' doesn't update the current instance, diff --git a/fancypages/api/serialisers.py b/fancypages/api/serialisers.py index 5a47438..0a3e903 100644 --- a/fancypages/api/serialisers.py +++ b/fancypages/api/serialisers.py @@ -160,4 +160,4 @@ def save(self, *args, **kwargs): class Meta: model = FancyPage fields = ['parent', 'new_index', 'old_index'] - read_only_fields = ['status',] + read_only_fields = ['status'] diff --git a/fancypages/api/urls.py b/fancypages/api/urls.py index 6b548fd..ef7f4b4 100644 --- a/fancypages/api/urls.py +++ b/fancypages/api/urls.py @@ -3,7 +3,8 @@ from fancypages.api import views -urlpatterns = patterns('', +urlpatterns = patterns( + '', url(r'^$', views.ApiV2View.as_view(), name="api-root"), url(r'^blocks$', views.BlockListView.as_view(), name='block-list'), url( diff --git a/fancypages/api/views.py b/fancypages/api/views.py index c2bd186..52ce41f 100644 --- a/fancypages/api/views.py +++ b/fancypages/api/views.py @@ -106,18 +106,16 @@ class BlockTypesView(APIView): def get(self, request): container_id = request.QUERY_PARAMS.get('container') if container_id is None: - return Response({ - 'detail': u'container ID is required for block list', - }, + return Response( + {'detail': u'container ID is required for block list'}, status=status.HTTP_400_BAD_REQUEST, ) try: Container.objects.get(pk=container_id) except Container.DoesNotExist: - return Response({ - 'detail': u'container ID is invalid', - }, + return Response( + {'detail': u'container ID is invalid'}, status=status.HTTP_400_BAD_REQUEST, ) return Response({ diff --git a/fancypages/assets/app.py b/fancypages/assets/app.py index e0c249d..c1faa94 100644 --- a/fancypages/assets/app.py +++ b/fancypages/assets/app.py @@ -15,7 +15,8 @@ class AssetApplication(Application): def get_urls(self): urlpatterns = super(AssetApplication, self).get_urls() - urlpatterns += patterns('', + urlpatterns += patterns( + '', url( r'^images/$', self.image_list_view.as_view(), diff --git a/fancypages/assets/forms/widgets.py b/fancypages/assets/forms/widgets.py index 4036b3a..aa3a09b 100644 --- a/fancypages/assets/forms/widgets.py +++ b/fancypages/assets/forms/widgets.py @@ -31,7 +31,13 @@ def render(self, name, value, attrs=None): widget_value = None if id_: final_attrs = dict(final_attrs, id='%s_%s' % (id_, i)) - output.append(widget.render(self.get_widget_id(name, i), widget_value, final_attrs)) + output.append( + widget.render( + self.get_widget_id(name, i), + widget_value, + final_attrs + ) + ) rendered_widgets = mark_safe(self.format_output(output)) tmpl = loader.get_template(self.template_name) return tmpl.render(Context({ @@ -39,7 +45,7 @@ def render(self, name, value, attrs=None): 'asset': self.get_asset(*value), })) - def get_widget_id (self, name, idx): + def get_widget_id(self, name, idx): return "%s_%s" % (name, self.widget_id_suffixes[idx]) def value_from_datadict(self, data, files, name): diff --git a/fancypages/assets/models.py b/fancypages/assets/models.py index 6b09ef5..1543815 100644 --- a/fancypages/assets/models.py +++ b/fancypages/assets/models.py @@ -31,7 +31,7 @@ class ImageAsset(AbstractAsset): ) width = models.IntegerField(_("Width"), blank=True) height = models.IntegerField(_("Height"), blank=True) - size = models.IntegerField(_("Size"), blank=True, null=True) # Bytes + size = models.IntegerField(_("Size"), blank=True, null=True) # Bytes @property def asset_type(self): diff --git a/fancypages/assets/views.py b/fancypages/assets/views.py index 1c1acc9..d908096 100644 --- a/fancypages/assets/views.py +++ b/fancypages/assets/views.py @@ -45,7 +45,9 @@ def form_valid(self, form): 'name': f.name, 'url': self.object.get_absolute_url(), 'thumbnailMarkup': thumbnail_markup, - 'deleteUrl': '', #reverse('upload-delete', args=[self.object.id]), + #TODO add the delete URL back in again + # reverse('upload-delete', args=[self.object.id]), + 'deleteUrl': '', 'deleteType': 'DELETE', }] } diff --git a/fancypages/dashboard/app.py b/fancypages/dashboard/app.py index bdc55de..c93032c 100644 --- a/fancypages/dashboard/app.py +++ b/fancypages/dashboard/app.py @@ -20,7 +20,8 @@ class FancypagesDashboardApplication(Application): block_delete_view = views.BlockDeleteView def get_urls(self): - urlpatterns = patterns('', + urlpatterns = patterns( + '', url(r'^assets/', include(self.assets_app.urls)), url( diff --git a/fancypages/dashboard/forms.py b/fancypages/dashboard/forms.py index 2d42e5d..903784e 100644 --- a/fancypages/dashboard/forms.py +++ b/fancypages/dashboard/forms.py @@ -34,7 +34,8 @@ def set_field_choices(self): if 'page_type' in self.fields: self.fields['page_type'].queryset = PageType.objects.all() if 'visibility_types' in self.fields: - self.fields['visibility_types'].queryset = VisibilityType.objects.all() + self.fields['visibility_types'].queryset = \ + VisibilityType.objects.all() class PageForm(PageFormMixin, forms.ModelForm): diff --git a/fancypages/dashboard/views.py b/fancypages/dashboard/views.py index f870f5f..9ffc9d9 100644 --- a/fancypages/dashboard/views.py +++ b/fancypages/dashboard/views.py @@ -143,8 +143,10 @@ def get_object(self, queryset=None): return self.get_block_object() def delete(self, request, *args, **kwargs): - response = super(BlockDeleteView, self).delete(request, *args, **kwargs) - for idx, block in enumerate(self.object.container.blocks.all().select_subclasses()): + response = super(BlockDeleteView, self).delete(request, *args, + **kwargs) + blocks = self.object.container.blocks.all().select_subclasses() + for idx, block in enumerate(blocks): block.display_order = idx block.save() return response diff --git a/fancypages/forms.py b/fancypages/forms.py index 0297985..85bdb7e 100644 --- a/fancypages/forms.py +++ b/fancypages/forms.py @@ -34,7 +34,8 @@ def set_field_choices(self): if 'page_type' in self.fields: self.fields['page_type'].queryset = PageType.objects.all() if 'visibility_types' in self.fields: - self.fields['visibility_types'].queryset = VisibilityType.objects.all() + self.fields['visibility_types'].queryset = \ + VisibilityType.objects.all() def save_category_data(self, category): category.name = self.cleaned_data['name'] diff --git a/fancypages/loaders.py b/fancypages/loaders.py deleted file mode 100644 index 8d0ad7a..0000000 --- a/fancypages/loaders.py +++ /dev/null @@ -1,51 +0,0 @@ -from django.db import models - -#from .renderers import BaseTileRenderer - -#__tiles = {} -# -# -#def itersubclasses(cls, _seen=None): -# """ -# I have taken this method from: -# -# http://code.activestate.com/recipes/576949-find-all-subclasses-of-a-given-class/ -# -# so that I don't have to do this all myself :) -# """ -# if not isinstance(cls, type): -# raise TypeError('itersubclasses must be called with ' -# 'new-style classes, not %.100r' % cls) -# if _seen is None: -# _seen = set() -# try: -# subs = cls.__subclasses__() -# except TypeError: # fails only when cls is type -# subs = cls.__subclasses__(cls) -# for sub in subs: -# if sub not in _seen: -# _seen.add(sub) -# yield sub -# for sub in itersubclasses(sub, _seen): -# yield sub -# -# -#if not __tiles: -# for tile_class in itersubclasses(BaseTileRenderer): -# if not issubclass(tile_class.model, models.Model): -# raise Exception('you need to specify a model for tile') -# if tile_class.model in __tiles: -# raise Exception('tile for model already registered') -# __tiles[tile_class.model.__name__] = tile_class -# -# -#def get_renderer_for_model(model): -# try: -# return __tiles[model.__class__.__name__] -# except KeyError: -# pass -# try: -# return __tiles[model.__name__] -# except KeyError: -# pass -# return None diff --git a/fancypages/middleware.py b/fancypages/middleware.py index 9adc3f7..5ad62c9 100644 --- a/fancypages/middleware.py +++ b/fancypages/middleware.py @@ -11,7 +11,8 @@ def replace_insensitive(string, target, replacement): """ Similar to string.replace() but is case insensitive Code borrowed from: - http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html + http://forums.devshed.com/python-programming-11/ + case-insensitive-string-replace-490921.html """ no_case = string.lower() index = no_case.rfind(target.lower()) @@ -53,10 +54,10 @@ def process_response(self, request, response): smart_unicode(editor_head) + self.head_tag, ) - response.content = BODY_STARTTAG.sub( - r'\g
', - response.content - ) + response.content = BODY_STARTTAG.sub( + r'\g
', + response.content + ) editor_body = render_to_string( self.body_template_name, diff --git a/fancypages/mixins.py b/fancypages/mixins.py index eb0112a..187783e 100644 --- a/fancypages/mixins.py +++ b/fancypages/mixins.py @@ -33,7 +33,9 @@ def get_json_response(self, content, **httpresponse_kwargs): content_type=self.get_content_type(), **httpresponse_kwargs ) - response['Content-Disposition'] = 'inline; filename=%s' % self.json_filename + response['Content-Disposition'] = 'inline; filename={0}'.format( + self.json_filename + ) return response def convert_context_to_json(self, context): diff --git a/fancypages/models/blocks/content.py b/fancypages/models/blocks/content.py index b62c264..48cc39f 100644 --- a/fancypages/models/blocks/content.py +++ b/fancypages/models/blocks/content.py @@ -95,8 +95,10 @@ class ImageAndTextBlock(ImageMetadataMixin, ContentBlock): def __unicode__(self): if self.image_asset: - return u"Image with text '%s'" % os.path.basename(self.image_asset.image.path) - return u"Image with text #%s" % self.id + return u"Image with text '{0}'".format( + os.path.basename(self.image_asset.image.path) + ) + return u"Image with text #{0}".format(self.id) class Meta: app_label = 'fancypages' @@ -119,7 +121,9 @@ def get_images_and_links(self): image_id = getattr(self, "%s_id" % (self.image_field_name % idx)) link_field_name = self.link_field_name % idx if image_id: - results[image_id] = {'link': getattr(self, link_field_name, None)} + results[image_id] = { + 'link': getattr(self, link_field_name, None) + } query.add(models.Q(id=image_id), models.Q.OR) if not query: return {} diff --git a/fancypages/urls.py b/fancypages/urls.py index 17190d8..e624320 100644 --- a/fancypages/urls.py +++ b/fancypages/urls.py @@ -5,7 +5,8 @@ from fancypages.app import application as fancypages_app from fancypages.dashboard.app import application as dashboard_app -urlpatterns = patterns('', +urlpatterns = patterns( + '', url(r'dashboard/fancypages/', include(dashboard_app.urls)), url( API_BASE_URL, diff --git a/fancypages/views.py b/fancypages/views.py index e2cc75e..d327a7a 100644 --- a/fancypages/views.py +++ b/fancypages/views.py @@ -19,7 +19,8 @@ class FancyPageDetailView(PageMixin, DetailView): def get(self, request, *args, **kwargs): self.object = self.get_object() - response = super(FancyPageDetailView, self).get(request, *args, **kwargs) + response = super(FancyPageDetailView, self).get(request, *args, + **kwargs) if request.user.is_staff: return response