Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clean_old_history's days argument acccepts integer #722

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Authors
- David Grochowski (`ThePumpingLemma <https://github.com/ThePumpingLemma>`_)
- David Hite
- Dmytro Shyshov (`xahgmah <https://github.com/xahgmah>`_)
- Edouard Richard (`vied12 <https://github.com/vied12>` _)
- Eduardo Cuducos
- Erik van Widenfelt (`erikvw <https://github.com/erikvw>`_)
- Filipe Pina (@fopina)
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Unreleased
- Add optional ``manager`` argument to ``bulk_update_with_history`` to use instead of
the default manager (gh-703)
- Add support for Django 3.1 (gh-713)
- Fix a bug with ``clean_old_history`` command's `--days` argument

2.11.0 (2020-06-20)
-------------------
Expand Down
3 changes: 1 addition & 2 deletions simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ def save_model(self, request, obj, form, change):

@property
def content_type_model_cls(self):
"""Returns the ContentType model class.
"""
"""Returns the ContentType model class."""
return django_apps.get_model("contenttypes.contenttype")

@property
Expand Down
2 changes: 1 addition & 1 deletion simple_history/management/commands/clean_old_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def add_arguments(self, parser):
parser.add_argument(
"--days",
help="Only Keep the last X Days of history, default is 30",
action="store_true",
dest="days",
type=int,
default=30,
)

Expand Down
12 changes: 9 additions & 3 deletions simple_history/tests/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def test_request_user_is_overwritten_by_default_user_on_bulk_create_view(self,):
self.assertFalse(any(ph.history_user_id == self.user.id for ph in poll_history))
self.assertFalse(any(ph.history_user_id is None for ph in poll_history))

@skipIf(django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2")
@skipIf(
django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2",
)
def test_user_is_set_on_bulk_update_view_when_logged_in(self):
self.client.force_login(self.user)
poll_1 = Poll.objects.create(question="Test question 1", pub_date=date.today())
Expand All @@ -212,7 +214,9 @@ def test_user_is_set_on_bulk_update_view_when_logged_in(self):
self.user.id, poll_2.history.latest("history_date").history_user_id
)

@skipIf(django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2")
@skipIf(
django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2",
)
def test_user_is_not_set_on_bulk_update_view_when_not_logged_in(self):
poll_1 = Poll.objects.create(question="Test question 1", pub_date=date.today())
poll_2 = Poll.objects.create(
Expand All @@ -224,7 +228,9 @@ def test_user_is_not_set_on_bulk_update_view_when_not_logged_in(self):
self.assertIsNone(poll_1.history.latest("history_date").history_user_id)
self.assertIsNone(poll_2.history.latest("history_date").history_user_id)

@skipIf(django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2")
@skipIf(
django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2",
)
def test_request_user_is_overwritten_by_default_user_on_bulk_update(self):
self.client.force_login(self.user)
poll = Poll.objects.create(pub_date=date(2020, 1, 1), question="123")
Expand Down
8 changes: 6 additions & 2 deletions simple_history/tests/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ def test_bulk_create_with_history(self):
self.assertEqual(BulkCreateManyToManyModel.objects.count(), 5)


@skipIf(django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2")
@skipIf(
django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2",
)
class BulkUpdateWithHistoryTestCase(TestCase):
def setUp(self):
self.data = [
Expand Down Expand Up @@ -337,7 +339,9 @@ def test_bulk_update_history_with_batch_size(self):
self.assertEqual(Poll.history.filter(history_type="~").count(), 5)


@skipIf(django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2")
@skipIf(
django.VERSION < (2, 2,), reason="bulk_update does not exist before 2.2",
)
class BulkUpdateWithHistoryAlternativeManagersTestCase(TestCase):
def setUp(self):
self.data = [
Expand Down