Skip to content

Commit

Permalink
Merge pull request #100 from glogiotatidis/flake8
Browse files Browse the repository at this point in the history
PEP8 all the things.
  • Loading branch information
glogiotatidis committed Mar 3, 2015
2 parents e734b2a + c8c8cc0 commit d4f3b69
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before_script:
before_install:
- git submodule update --init --recursive
- pip install flake8 requests
- flake8 snippets --exclude='*/migrations/*' --exit-zero --max-line-length=100 | python bin/comment-on-pr.py
- flake8 snippets --exit-zero | python bin/comment-on-pr.py
install:
- pip install -r requirements/compiled.txt
- pip install -r requirements/dev.txt
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length=100
exclude=migrations
8 changes: 3 additions & 5 deletions snippets/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ def cmr_to_locales_action(modeladmin, request, queryset):
'to Locale Rules')



@transaction.commit_on_success
def duplicate_snippets_action(modeladmin, request, queryset):
for snippet in queryset:
snippet.duplicate()
duplicate_snippets_action.short_description = 'Duplicate selected snippets'



class TemplateNameFilter(admin.AllValuesFieldListFilter):
def __init__(self, *args, **kwargs):
super(TemplateNameFilter, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -162,7 +160,8 @@ class SnippetAdmin(BaseSnippetAdmin):
'fields': (('on_release', 'on_beta', 'on_aurora', 'on_nightly'),)
}),
('Search Providers', {
'description': 'Would you like to <strong>exclude</strong> any search providers from this snippet?',
'description': ('Would you like to <strong>exclude</strong> '
'any search providers from this snippet?'),
'fields': (('exclude_from_search_providers',),)
}),
('Country and Locale', {
Expand Down Expand Up @@ -193,7 +192,6 @@ def lookup_allowed(self, key, value):
return super(SnippetAdmin, self).lookup_allowed(key, value)

def text(self, obj):
text = []
data = json.loads(obj.data)
text_keys = (obj.template.variable_set
.filter(type=models.SnippetTemplateVariable.TEXT)
Expand Down Expand Up @@ -251,7 +249,7 @@ def save_related(self, request, form, formsets, change):
var_manager = form.instance.variable_set

# Filter out reserved variable names.
new_vars = filter(lambda x: not x in RESERVED_VARIABLES, new_vars)
new_vars = filter(lambda x: x not in RESERVED_VARIABLES, new_vars)

# Delete variables not in the new set.
var_manager.filter(~Q(name__in=new_vars)).delete()
Expand Down
3 changes: 2 additions & 1 deletion snippets/base/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def match_client(self, client):

# Retrieve the first channel that starts with the client's channel.
# Allows things like "release-cck-mozilla14" to match "release".
client_channel = 'nightly' if client.channel == 'default' else first(CHANNELS, client.channel.startswith)
client_channel = ('nightly' if client.channel == 'default'
else first(CHANNELS, client.channel.startswith))
if client_channel:
filters.update(**{'on_{0}'.format(client_channel): True})

Expand Down
4 changes: 2 additions & 2 deletions snippets/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def generate(self):
cache.set(self.cache_key, True, settings.SNIPPET_BUNDLE_TIMEOUT)



class SnippetTemplate(CachingMixin, models.Model):
"""
A template for the body of a snippet. Can have multiple variables that the
Expand Down Expand Up @@ -356,7 +355,8 @@ def render(self):
provider.identifier for provider in self.exclude_from_search_providers.all()
]
if search_engine_identifiers:
attrs.append(('data-exclude-from-search-engines', ','.join(search_engine_identifiers)))
attrs.append(('data-exclude-from-search-engines',
','.join(search_engine_identifiers)))

attr_string = ' '.join('{0}="{1}"'.format(key, value) for key, value in
attrs)
Expand Down
3 changes: 2 additions & 1 deletion snippets/base/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from nose.tools import assert_raises, eq_, ok_
from pyquery import PyQuery as pq

from snippets.base.forms import IconWidget, TemplateDataWidget, TemplateSelect, UploadedFileAdminForm
from snippets.base.forms import (IconWidget, TemplateDataWidget,
TemplateSelect, UploadedFileAdminForm)
from snippets.base.tests import (SnippetTemplateFactory,
SnippetTemplateVariableFactory, TestCase)

Expand Down
1 change: 1 addition & 0 deletions snippets/base/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
TestCase,
UploadedFileFactory)


class DuplicateSnippetMixInTests(TestCase):
def _dup_test(self, snippet):
snippet.client_match_rules.add(*ClientMatchRuleFactory.create_batch(3))
Expand Down
3 changes: 2 additions & 1 deletion snippets/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from snippets.base.util import get_object_or_none


_http_max_age = lambda: getattr(settings, 'SNIPPET_HTTP_MAX_AGE', 90)
def _http_max_age():
return getattr(settings, 'SNIPPET_HTTP_MAX_AGE', 90)
HTTP_MAX_AGE = lazy(_http_max_age, str)()
SNIPPETS_PER_PAGE = 50

Expand Down
10 changes: 5 additions & 5 deletions snippets/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import sys


from .base import *
from .base import * # NOQA

# Load special settings for CI.
if os.environ.get('TRAVIS'):
from .travis import *
from .travis import * # NOQA
elif os.environ.get('DOCKER'):
from .docker import *
from .docker import * # NOQA
else:
try:
from .local import *
from .local import * # NOQA
except ImportError, exc:
exc.args = tuple(['%s (did you rename settings/local.py-dist?)' % exc.args[0]])
raise exc

TEST = len(sys.argv) > 1 and sys.argv[1] == 'test'
if TEST:
try:
from .test import *
from .test import * # NOQA
except ImportError:
pass
2 changes: 1 addition & 1 deletion snippets/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This is your project's main settings file that can be committed to your
# repo. If you need to override a setting locally, use settings_local.py

from funfactory.settings_base import *
from funfactory.settings_base import * # NOQA


# Defines the views served for root URLs.
Expand Down
6 changes: 3 additions & 3 deletions snippets/settings/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
'PORT': '',
'OPTIONS': {
'init_command': 'SET default_storage_engine=InnoDB',
'charset' : 'utf8',
'use_unicode' : True,
'charset': 'utf8',
'use_unicode': True,
},
'TEST_CHARSET': 'utf8',
'TEST_COLLATION': 'utf8_general_ci',
Expand All @@ -24,7 +24,7 @@
'2012-06-06': 'some secret',
}

from django_sha2 import get_password_hashers
from django_sha2 import get_password_hashers # NOQA
PASSWORD_HASHERS = get_password_hashers(base.BASE_PASSWORD_HASHERS, HMAC_KEYS)

# Make this unique, and don't share it with anybody. It cannot be blank.
Expand Down
4 changes: 2 additions & 2 deletions snippets/settings/local.py-dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import base

# To extend any settings from settings/base.py here's an example:
#INSTALLED_APPS = base.INSTALLED_APPS + ['debug_toolbar']
# INSTALLED_APPS = base.INSTALLED_APPS + ['debug_toolbar']

DATABASES = {
'default': {
Expand Down Expand Up @@ -54,7 +54,7 @@ HMAC_KEYS = {
#'2012-06-06': 'some secret',
}

from django_sha2 import get_password_hashers
from django_sha2 import get_password_hashers # NOQA
PASSWORD_HASHERS = get_password_hashers(base.BASE_PASSWORD_HASHERS, HMAC_KEYS)

# Make this unique, and don't share it with anybody. It cannot be blank.
Expand Down
6 changes: 3 additions & 3 deletions snippets/settings/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
'PORT': '',
'OPTIONS': {
'init_command': 'SET storage_engine=InnoDB',
'charset' : 'utf8',
'use_unicode' : True,
'charset': 'utf8',
'use_unicode': True,
},
'TEST_CHARSET': 'utf8',
'TEST_COLLATION': 'utf8_general_ci',
Expand All @@ -24,7 +24,7 @@
'2012-06-06': 'some secret',
}

from django_sha2 import get_password_hashers
from django_sha2 import get_password_hashers # NOQA
PASSWORD_HASHERS = get_password_hashers(base.BASE_PASSWORD_HASHERS, HMAC_KEYS)

# Make this unique, and don't share it with anybody. It cannot be blank.
Expand Down
12 changes: 6 additions & 6 deletions snippets/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.http import HttpResponse
from django.views.static import serve as static_serve
Expand All @@ -10,8 +11,6 @@
# Apply funfactory monkeypatches.
patch()

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()


Expand All @@ -20,23 +19,24 @@ def robots_txt(request):
return HttpResponse('User-agent: *\n{0}: /'.format(permission),
mimetype='text/plain')

urlpatterns = patterns('',
urlpatterns = patterns(
'',
url(r'', include('snippets.base.urls')),

url(r'^admin/', include('smuggler.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^robots\.txt$', robots_txt)
)

## In DEBUG mode, serve media files through Django.
# In DEBUG mode, serve media files through Django.
if settings.DEBUG:
# Use custom serve function that adds necessary headers.
def serve_media(*args, **kwargs):
response = static_serve(*args, **kwargs)
response['Access-Control-Allow-Origin'] = '*'
return response

urlpatterns += patterns('',
urlpatterns += patterns(
'',
url(r'^media/(?P<path>.*)$', serve_media, {
'document_root': settings.MEDIA_ROOT,
}),
Expand Down

0 comments on commit d4f3b69

Please sign in to comment.