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

Handle reverse move and models.permalink removal #331

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.contrib import admin
from django.contrib.admin import helpers
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, render
from django.utils.text import capfirst
from django.utils.html import mark_safe
Expand All @@ -18,6 +17,10 @@
from django.contrib.admin.utils import unquote
except ImportError: # Django < 1.7
from django.contrib.admin.util import unquote
try:
from django.urls import reverse
except ImportError: # Django < 1.10
from django.core.urlresolvers import reverse
try:
from django.utils.version import get_complete_version
except ImportError:
Expand Down
10 changes: 6 additions & 4 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from django.apps import apps
except ImportError: # Django < 1.7
from django.db.models import get_app
try:
from django.urls import reverse
except ImportError: # Django < 1.10
from django.core.urlresolvers import reverse
try:
from south.modelsinspector import add_introspection_rules
except ImportError: # south not present
Expand Down Expand Up @@ -204,14 +208,12 @@ def get_extra_fields(self, model, fields):

user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')

@models.permalink
def revert_url(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any tests in the test suite that are testing this function? Couldn't find any. Want to add one and include it with the PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rossmechanic I added a simple test of the reverse_url() output; there was an existing test that called it, but this looks like the first one to sanity check the output.

"""URL for this change in the default admin site."""
opts = model._meta
app_label, model_name = opts.app_label, opts.model_name
return ('%s:%s_%s_simple_history' %
(admin.site.name, app_label, model_name),
[getattr(self, opts.pk.attname), self.history_id])
viewname = '%s:%s_%s_simple_history' % (admin.site.name, app_label, model_name)
return reverse(viewname, args=[getattr(self, opts.pk.attname), self.history_id])

def get_instance(self):
return model(**{
Expand Down
5 changes: 4 additions & 1 deletion simple_history/tests/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.contrib.messages.storage.fallback import FallbackStorage
from django.test.utils import override_settings
from django.test.client import RequestFactory
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils.encoding import force_text
Expand All @@ -19,6 +18,10 @@
from django.contrib.admin.utils import quote
except ImportError: # Django < 1.7
from django.contrib.admin.util import quote
try:
from django.urls import reverse
except ImportError: # Django < 1.10
from django.core.urlresolvers import reverse

User = get_user_model()
today = datetime(2021, 1, 1, 10, 0)
Expand Down
8 changes: 8 additions & 0 deletions simple_history/tests/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ def test_model_with_excluded_fields(self):
self.assertIn('question', all_fields_names)
self.assertNotIn('pub_date', all_fields_names)

def test_revert_url(self):
p = Poll(question="what's up?", pub_date=today)
p.save()
record = p.history.all()[0]
revert_url = record.revert_url()
expected_url = '/admin/tests/poll/{}/history/{}/'.format(p.id, record.id)
self.assertEqual(revert_url, expected_url)


class CreateHistoryModelTests(unittest.TestCase):

Expand Down