Permalink
Browse files

Correct flake8 errors and warnings

  • Loading branch information...
1 parent 55fb5cf commit 5316b7531427942a81eead1af37e0f1cc0911041 @codeinthehole codeinthehole committed Aug 15, 2012
@@ -3,23 +3,24 @@
class Application(object):
name = None
-
+
def __init__(self, app_name=None, **kwargs):
self.app_name = app_name
# Set all kwargs as object attributes
for key, value in kwargs.iteritems():
setattr(self, key, value)
-
+
def get_urls(self):
"""
- Return the url patterns for this app, MUST be implemented in the subclass
+ Return the url patterns for this app, MUST be implemented in the
+ subclass
"""
return patterns('')
def post_process_urls(self, urlpatterns):
"""
- Customise URL patterns.
-
+ Customise URL patterns.
+
By default, this only allows custom decorators to be specified, but you
could override this method to do anything you want.
"""
@@ -35,8 +36,8 @@ def post_process_urls(self, urlpatterns):
def get_url_decorator(self, url_name):
return None
-
+
@property
def urls(self):
# We set the application and instance namespace here
- return self.get_urls(), self.app_name, self.name
+ return self.get_urls(), self.app_name, self.name
@@ -9,4 +9,5 @@ def metadata(request):
'version': getattr(settings, 'VERSION', 'N/A'),
'shop_name': settings.OSCAR_SHOP_NAME,
'shop_tagline': settings.OSCAR_SHOP_TAGLINE,
- 'google_analytics_id': getattr(settings, 'GOOGLE_ANALYTICS_ID', None)}
+ 'google_analytics_id': getattr(settings,
+ 'GOOGLE_ANALYTICS_ID', None)}
@@ -44,7 +44,7 @@ class can't be found in the overriding module, then we attempt to import it
# App must be local - check if module is in local app (it could be in
# oscar's)
app_label = module_label.split('.')[0]
- base_package = app_module_path.rsplit('.'+app_label, 1)[0]
+ base_package = app_module_path.rsplit('.' + app_label, 1)[0]
local_app = "%s.%s" % (base_package, module_label)
try:
imported_local_module = __import__(local_app, fromlist=classnames)
@@ -54,7 +54,8 @@ class can't be found in the overriding module, then we attempt to import it
oscar_app = "oscar.apps.%s" % module_label
imported_oscar_module = __import__(oscar_app, fromlist=classnames)
- return _pluck_classes([imported_local_module, imported_oscar_module], classnames)
+ return _pluck_classes([imported_local_module, imported_oscar_module],
+ classnames)
def _pluck_classes(modules, classnames):
@@ -4,11 +4,10 @@
class PciFormatter(Formatter):
"""
- Strip card numbers out of log messages to avoid leaving sensitive information
- in the logs.
+ Strip card numbers out of log messages to avoid leaving sensitive
+ information in the logs.
"""
-
+
def format(self, record):
s = Formatter.format(self, record)
return re.sub(r'\d[ \d-]{15,22}', 'XXXX-XXXX-XXXX-XXXX', s)
-
@@ -6,21 +6,21 @@ class EnvFileHandler(BaseFileHandler):
"""
Custom filehandler that uses the LOG_ROOT setting to determine the folder
to store log files in.
-
- We have to do some tricky stuff to avoid circular imports. To this end,
- we pass /dev/null to the parent handler but specify opening to be delayed.
+
+ We have to do some tricky stuff to avoid circular imports. To this end,
+ we pass /dev/null to the parent handler but specify opening to be delayed.
Then when we try to first open the file, we join the LOG_ROOT with the
passed filename.
"""
-
+
def __init__(self, filename, *args, **kwargs):
self.filename = filename
kwargs['delay'] = True
BaseFileHandler.__init__(self, "/dev/null", *args, **kwargs)
-
+
def _open(self):
# We import settings here to avoid a circular reference as this module
# will be imported when settings.py is executed.
from django.conf import settings
self.baseFilename = os.path.join(settings.LOG_ROOT, self.filename)
- return BaseFileHandler._open(self)
+ return BaseFileHandler._open(self)
@@ -1,12 +1,10 @@
-import re
-
from django.core import validators
from django.core.exceptions import ValidationError
from django.core.urlresolvers import resolve
+from django.db.models import get_model
from django.http import Http404
from django.utils.translation import ugettext_lazy as _
-from django.db.models import get_model
class ExtendedURLValidator(validators.URLValidator):
def __call__(self, value):
@@ -77,7 +75,7 @@ def __call__(self, value):
super(URLDoesNotExistValidator, self).__call__(value)
except ValidationError:
raise ValidationError(_('Specified page does already exist'),
- code='invalid')
+ code='invalid')
# check if URL exists since it seems to be valid
try:
@@ -87,4 +85,4 @@ def __call__(self, value):
return
raise ValidationError(_('Specified page does already exist'),
- code='invalid')
+ code='invalid')
View
@@ -2,7 +2,7 @@
OSCAR_SHOP_TAGLINE = 'Domain-driven e-Commerce for Django'
# Basket settings
-OSCAR_BASKET_COOKIE_LIFETIME = 7*24*60*60
+OSCAR_BASKET_COOKIE_LIFETIME = 7 * 24 * 60 * 60
OSCAR_BASKET_COOKIE_OPEN = 'oscar_open_basket'
OSCAR_BASKET_COOKIE_SAVED = 'oscar_saved_basket'
@@ -31,7 +31,8 @@
OSCAR_PARTNER_WRAPPERS = {}
# Promotions
-COUNTDOWN, LIST, SINGLE_PRODUCT, TABBED_BLOCK = ('Countdown', 'List', 'SingleProduct', 'TabbedBlock')
+COUNTDOWN, LIST, SINGLE_PRODUCT, TABBED_BLOCK = (
+ 'Countdown', 'List', 'SingleProduct', 'TabbedBlock')
OSCAR_PROMOTION_MERCHANDISING_BLOCK_TYPES = (
(COUNTDOWN, "Vertical list"),
(LIST, "Horizontal list"),
@@ -56,4 +57,5 @@
# Cookies
OSCAR_COOKIES_DELETE_ON_LOGOUT = ['oscar_recently_viewed_products', ]
-OSCAR_SETTINGS = dict([(k, v) for k, v in locals().items() if k.startswith('OSCAR_')])
+OSCAR_SETTINGS = dict(
+ [(k, v) for k, v in locals().items() if k.startswith('OSCAR_')])
View
@@ -3,19 +3,21 @@
from oscar.core import validators
+
class ExtendedURLField(fields.URLField):
"""
- Custom field similar to URLField type field, however also accepting
- and validating local relative URLs, ie. '/product/'
+ Custom field similar to URLField type field, however also accepting and
+ validating local relative URLs, ie. '/product/'
"""
def __init__(self, max_length=None, min_length=None, verify_exists=False,
validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs):
# intentionally skip one step when calling super()
super(fields.URLField, self).__init__(max_length, min_length, *args,
- **kwargs)
- validator = validators.ExtendedURLValidator(verify_exists=verify_exists,
- validator_user_agent=validator_user_agent)
+ **kwargs)
+ validator = validators.ExtendedURLValidator(
+ verify_exists=verify_exists,
+ validator_user_agent=validator_user_agent)
self.validators.append(validator)
def to_python(self, value):
@@ -24,4 +26,3 @@ def to_python(self, value):
if value and value.startswith('/'):
return value
return super(ExtendedURLField, self).to_python(value)
-
@@ -10,11 +10,6 @@
class Command(BaseCommand):
help = 'Calculate product scores based on analytics data'
-
+
def handle(self, *args, **options):
Calculator(logger).run()
-
-
-
-
-
@@ -10,16 +10,17 @@
class Command(BaseCommand):
args = '<communication_event_type> <order number>'
help = 'For testing the content of order emails'
-
+
def handle(self, *args, **options):
if len(args) != 2:
raise CommandError("Please select a event type and order number")
-
+
try:
order = Order.objects.get(number=args[1])
except Order.DoesNotExist:
raise CommandError("No order found with number %s" % args[1])
-
- messages = CommunicationEventType.objects.get_and_render(args[0], {'order': order})
- print "Subject: %s\nBody:\n\n%s\nBody HTML:\n\n%s"% (
- messages['subject'], messages['body'], messages['html'])
+
+ messages = CommunicationEventType.objects.get_and_render(
+ args[0], {'order': order})
+ print "Subject: %s\nBody:\n\n%s\nBody HTML:\n\n%s" % (
+ messages['subject'], messages['body'], messages['html'])
@@ -11,7 +11,7 @@
class Command(BaseCommand):
args = '/path/to/file1.csv /path/to/file2.csv ...'
help = 'For creating product catalogues based on a CSV file'
-
+
option_list = BaseCommand.option_list + (
make_option('--flush',
action='store_true',
@@ -28,23 +28,21 @@ def handle(self, *args, **options):
logger = self._get_logger()
if not args:
raise CommandError("Please select a CSV file to import")
-
+
logger.info("Starting catalogue import")
- importer = CatalogueImporter(logger, delimiter=options.get('delimiter'), flush=options.get('flush'))
+ importer = CatalogueImporter(logger,
+ delimiter=options.get('delimiter'),
+ flush=options.get('flush'))
for file_path in args:
logger.info(" - Importing records from '%s'" % file_path)
try:
importer.handle(file_path)
except CatalogueImportError, e:
raise CommandError(str(e))
-
+
def _get_logger(self):
logger = logging.getLogger(__file__)
stream = logging.StreamHandler(self.stdout)
logger.addHandler(stream)
logger.setLevel(logging.DEBUG)
return logger
-
-
-
-
@@ -8,10 +8,9 @@
class Command(BaseCommand):
-
args = '/path/to/folder'
help = 'For importing product images from a folder'
-
+
option_list = BaseCommand.option_list + (
make_option('--filename',
dest='filename',
@@ -21,19 +20,18 @@ class Command(BaseCommand):
def handle(self, *args, **options):
if len(args) != 1:
- raise CommandError('Command requires a path to a single folder')
-
+ raise CommandError('Command requires a path to a single folder')
+
logger = self._get_logger()
- logger.info("Starting image import...")
-
+ logger.info("Starting image import...")
+
dirname = args[0]
importer = Importer(logger, field=options.get('filename'))
importer.handle(dirname)
-
+
def _get_logger(self):
logger = logging.getLogger('oscar.apps.image')
stream = logging.StreamHandler(self.stdout)
logger.addHandler(stream)
logger.setLevel(logging.DEBUG)
return logger
-
@@ -9,10 +9,9 @@
class Command(BaseCommand):
-
args = '<partner> /path/to/file1.csv'
help = 'For updating stock for a partner based on a CSV file'
-
+
option_list = BaseCommand.option_list + (
make_option('--delimiter',
dest='delimiter',
@@ -22,21 +21,24 @@ class Command(BaseCommand):
def handle(self, *args, **options):
if len(args) != 2:
- raise CommandError('Command requires a partner and a path to a csv file')
-
+ raise CommandError(
+ 'Command requires a partner and a path to a csv file')
+
logger = self._get_logger()
-
+
try:
- importer = StockImporter(logger, partner=args[0], delimiter=options.get('delimiter'))
+ importer = StockImporter(logger,
+ partner=args[0],
+ delimiter=options.get('delimiter'))
logger.info("Starting stock import")
logger.info(" - Importing records from '%s'" % args[1])
importer.handle(args[1])
except ImportError, e:
raise CommandError(str(e))
-
+
def _get_logger(self):
logger = logging.getLogger('oscar.apps.partner.import_stock')
stream = logging.StreamHandler(self.stdout)
logger.addHandler(stream)
logger.setLevel(logging.DEBUG)
- return logger
+ return logger
@@ -10,20 +10,24 @@
pass
else:
add_introspection_rules([], ["^oscar\.models\.fields\.ExtendedURLField$"])
- add_introspection_rules([], ["^oscar\.models\.fields\.PositiveDecimalField$"])
+ add_introspection_rules([], [
+ "^oscar\.models\.fields\.PositiveDecimalField$"])
class ExtendedURLField(CharField):
description = _("URL")
- def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
+ def __init__(self, verbose_name=None, name=None,
+ verify_exists=True, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 200)
CharField.__init__(self, verbose_name, name, **kwargs)
- validator = validators.ExtendedURLValidator(verify_exists=verify_exists)
+ validator = validators.ExtendedURLValidator(
+ verify_exists=verify_exists)
self.validators.append(validator)
def formfield(self, **kwargs):
- # As with CharField, this will cause URL validation to be performed twice
+ # As with CharField, this will cause URL validation to be performed
+ # twice.
defaults = {
'form_class': fields.ExtendedURLField,
}
Oops, something went wrong.

0 comments on commit 5316b75

Please sign in to comment.