Skip to content

Commit d3d8a25

Browse files
author
Ross Mechanic
authored
Merge pull request #366 from treyhunner/fix-flake-8-errors
Fixed linting errors and setup flake8 to run on travis
2 parents 7ef64b8 + 12f3e97 commit d3d8a25

File tree

15 files changed

+119
-45
lines changed

15 files changed

+119
-45
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ env:
1414

1515
install:
1616
- pip install -U coverage codecov
17+
- pip install -U flake8
1718
- pip install -U $DJANGO
1819
- pip freeze
1920

20-
script: coverage run setup.py test
21+
script:
22+
- flake8 simple_history
23+
- coverage run setup.py test
2124

2225
matrix:
2326
exclude:

simple_history/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def history_view(self, request, object_id, extra_context=None):
7878
}
7979
context.update(extra_context or {})
8080
extra_kwargs = {}
81-
return render(request, self.object_history_template, context, **extra_kwargs)
81+
return render(request, self.object_history_template, context,
82+
**extra_kwargs)
8283

8384
def response_change(self, request, obj):
8485
if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
@@ -181,7 +182,8 @@ def history_form_view(self, request, object_id, version_id):
181182
'root_path': getattr(self.admin_site, 'root_path', None),
182183
}
183184
extra_kwargs = {}
184-
return render(request, self.object_history_form_template, context, **extra_kwargs)
185+
return render(request, self.object_history_form_template, context,
186+
**extra_kwargs)
185187

186188
def save_model(self, request, obj, form, change):
187189
"""Set special model attribute to user for reference after save"""

simple_history/management/commands/_populate_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ def bulk_history_create(model, history_model, batch_size):
2626
for field in instance._meta.fields
2727
}
2828
) for instance in model.objects.all()]
29-
history_model.objects.bulk_create(historical_instances, batch_size=batch_size)
29+
history_model.objects.bulk_create(historical_instances,
30+
batch_size=batch_size)

simple_history/management/commands/populate_history.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def add_arguments(self, parser):
3838
dest='batchsize',
3939
default=200,
4040
type=int,
41-
help='Set a custom batch size when bulk inserting historical records.',
41+
help='Set a custom batch size when bulk inserting historical '
42+
'records.',
4243
)
4344

4445
def handle(self, *args, **options):

simple_history/models.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def copy_fields(self, model):
165165
if isinstance(field, models.ForeignKey):
166166
old_field = field
167167
field_arguments = {'db_constraint': False}
168-
if (getattr(old_field, 'one_to_one', False) or
169-
isinstance(old_field, models.OneToOneField)):
168+
if getattr(old_field, 'one_to_one', False) \
169+
or isinstance(old_field, models.OneToOneField):
170170
FieldType = models.ForeignKey
171171
else:
172172
FieldType = type(old_field)
@@ -180,7 +180,7 @@ def copy_fields(self, model):
180180
# we need to set the `model` value of the field to a model. We
181181
# can use the old_field.model value.
182182
if isinstance(old_field.remote_field.model, str) and \
183-
old_field.remote_field.model == 'self':
183+
old_field.remote_field.model == 'self':
184184
object_to = old_field.model
185185
else:
186186
object_to = old_field.remote_field.model
@@ -212,9 +212,14 @@ def revert_url(self):
212212
"""URL for this change in the default admin site."""
213213
opts = model._meta
214214
app_label, model_name = opts.app_label, opts.model_name
215-
return reverse('%s:%s_%s_simple_history' %
216-
(admin.site.name, app_label, model_name),
217-
args=[getattr(self, opts.pk.attname), self.history_id])
215+
return reverse(
216+
'%s:%s_%s_simple_history' % (
217+
admin.site.name,
218+
app_label,
219+
model_name
220+
),
221+
args=[getattr(self, opts.pk.attname), self.history_id]
222+
)
218223

219224
def get_instance(self):
220225
return model(**{
@@ -235,7 +240,10 @@ def get_instance(self):
235240
('~', _('Changed')),
236241
('-', _('Deleted')),
237242
)),
238-
'history_object': HistoricalObjectDescriptor(model, self.fields_included(model)),
243+
'history_object': HistoricalObjectDescriptor(
244+
model,
245+
self.fields_included(model)
246+
),
239247
'instance': property(get_instance),
240248
'instance_type': model,
241249
'revert_url': revert_url,
@@ -324,7 +332,8 @@ def convert_auto_field(field):
324332
must be replaced with an IntegerField.
325333
"""
326334
connection = router.db_for_write(field.model)
327-
if settings.DATABASES[connection].get('ENGINE') in ('django_mongodb_engine',):
335+
if settings.DATABASES[connection].get('ENGINE') in \
336+
('django_mongodb_engine',):
328337
# Check if AutoField is string for django-non-rel support
329338
return models.TextField
330339
return models.IntegerField

simple_history/registry_tests/tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33
import unittest
44
from datetime import datetime, timedelta
55

6-
import django
6+
from django.apps import apps
77
from django.contrib.auth import get_user_model
88
from django.core import management
99
from django.test import TestCase
10-
from simple_history import exceptions, register
1110
from six.moves import cStringIO as StringIO
1211

12+
from simple_history import exceptions, register
1313
from ..tests.models import (Choice, InheritTracking1, InheritTracking2,
1414
InheritTracking3, InheritTracking4, Poll,
1515
Restaurant, TrackedAbstractBaseA,
1616
TrackedAbstractBaseB, TrackedWithAbstractBase,
1717
TrackedWithConcreteBase, UserAccessorDefault,
1818
UserAccessorOverride, Voter)
1919

20-
from django.apps import apps
21-
2220
get_model = apps.get_model
2321
User = get_user_model()
2422
today = datetime(2021, 1, 1, 10, 0)

simple_history/templatetags/getattributes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ def getattribute(value, arg):
88

99
return getattr(value, arg, None)
1010

11+
1112
register.filter('getattribute', getattribute)

simple_history/tests/admin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
from django.contrib import admin
44

55
from simple_history.admin import SimpleHistoryAdmin
6-
from .models import Poll, Choice, Person, Book, Document, Paper, Employee, ConcreteExternal
6+
from .models import (
7+
Book,
8+
Choice,
9+
ConcreteExternal,
10+
Document,
11+
Employee,
12+
Paper,
13+
Person,
14+
Poll
15+
)
716

817

918
class PersonAdmin(SimpleHistoryAdmin):

simple_history/tests/external/models/model4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ class ExternalModel4(models.Model):
1010
class Meta:
1111
app_label = 'external'
1212

13+
1314
register(ExternalModel4, app='simple_history.tests',
1415
manager_name='histories')

simple_history/tests/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Choice(models.Model):
6262
choice = models.CharField(max_length=200)
6363
votes = models.IntegerField()
6464

65+
6566
register(Choice)
6667

6768

@@ -199,6 +200,7 @@ class ConcreteAttr(AbstractBase):
199200
class ConcreteUtil(AbstractBase):
200201
pass
201202

203+
202204
register(ConcreteUtil, bases=[AbstractBase])
203205

204206

@@ -225,6 +227,7 @@ class Meta:
225227
class ExternalModel3(models.Model):
226228
name = models.CharField(max_length=100)
227229

230+
228231
register(ExternalModel3, app='simple_history.tests.external',
229232
manager_name='histories')
230233

0 commit comments

Comments
 (0)