Skip to content

Commit

Permalink
Make code PEP8 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Vetter committed Jul 29, 2013
1 parent 51cd751 commit 912661c
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 81 deletions.
4 changes: 3 additions & 1 deletion fancypages/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion fancypages/api/serialisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
3 changes: 2 additions & 1 deletion fancypages/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions fancypages/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion fancypages/assets/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 8 additions & 2 deletions fancypages/assets/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ 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({
'rendered_widgets': rendered_widgets,
'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):
Expand Down
2 changes: 1 addition & 1 deletion fancypages/assets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion fancypages/assets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}]
}
Expand Down
3 changes: 2 additions & 1 deletion fancypages/dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion fancypages/dashboard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions fancypages/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fancypages/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
51 changes: 0 additions & 51 deletions fancypages/loaders.py

This file was deleted.

11 changes: 6 additions & 5 deletions fancypages/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -53,10 +54,10 @@ def process_response(self, request, response):
smart_unicode(editor_head) + self.head_tag,
)

response.content = BODY_STARTTAG.sub(
r'\g<body_tag><div class="editable-page-wrapper">',
response.content
)
response.content = BODY_STARTTAG.sub(
r'\g<body_tag><div class="editable-page-wrapper">',
response.content
)

editor_body = render_to_string(
self.body_template_name,
Expand Down
4 changes: 3 additions & 1 deletion fancypages/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 7 additions & 3 deletions fancypages/models/blocks/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {}
Expand Down
3 changes: 2 additions & 1 deletion fancypages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion fancypages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 912661c

Please sign in to comment.