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

Django 1.8 support #35

Merged
merged 4 commits into from
Apr 11, 2015
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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ python:
- "2.7"
- "3.4"

env:
- DJANGO=1.7
- DJANGO=1.8

install:
- "pip install ."
- pip install -q Django==$DJANGO --use-mirrors
- "pip install django-tools coveralls"

script:
Expand Down
22 changes: 15 additions & 7 deletions reversion_compare/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def get_many_to_something(self, ids, related_model, is_reverse=False):

deleted = []
if is_reverse:
true_missing_objects = []
for o in missing_objects:
for ver in reversion.get_for_object(o):
# An object can only be missing if it actually existed prior to this version
# Otherwise its a new item
if ver.revision.date_created < version.revision.date_created:
true_missing_objects.append(o)
missing_objects = true_missing_objects
deleted = [d for d in reversion.get_deleted(related_model) if d.revision == old_revision]
return versions, missing_objects, missing_ids, deleted

Expand Down Expand Up @@ -498,7 +506,7 @@ def get_urls(self):
urls = super(BaseCompareVersionAdmin, self).get_urls()
admin_site = self.admin_site
opts = self.model._meta
info = opts.app_label, opts.module_name,
info = opts.app_label, opts.model_name,
reversion_urls = patterns("",
url("^([^/]+)/history/compare/$", admin_site.admin_view(self.compare_view),
name='%s_%s_compare' % info),
Expand All @@ -513,7 +521,7 @@ def _get_action_list(self, request, object_id, extra_context=None):
{
"version": version,
"revision": version.revision,
"url": reverse("%s:%s_%s_revision" % (self.admin_site.name, opts.app_label, opts.module_name),
"url": reverse("%s:%s_%s_revision" % (self.admin_site.name, opts.app_label, opts.model_name),
args=(quote(version.object_id), version.id)),
}
for version
Expand Down Expand Up @@ -626,7 +634,7 @@ def compare(self, obj, version1, version2):
)
if isinstance(f, models.ForeignKey) and f not in fields:
self.reverse_fields.append(f.rel)

#print(self.reverse_fields)
fields += self.reverse_fields

has_unfollowed_fields = False
Expand Down Expand Up @@ -705,18 +713,18 @@ def compare_view(self, request, object_id, extra_context=None):
context = {
"opts": opts,
"app_label": opts.app_label,
"module_name": capfirst(opts.verbose_name),
"model_name": capfirst(opts.verbose_name),
"title": _("Compare %(name)s") % {"name": version1.object_repr},
"obj": obj,
"compare_data": compare_data,
"has_unfollowed_fields": has_unfollowed_fields,
"version1": version1,
"version2": version2,
"changelist_url": reverse("%s:%s_%s_changelist" % (self.admin_site.name, opts.app_label, opts.module_name)),
"change_url": reverse("%s:%s_%s_change" % (self.admin_site.name, opts.app_label, opts.module_name),
"changelist_url": reverse("%s:%s_%s_changelist" % (self.admin_site.name, opts.app_label, opts.model_name)),
"change_url": reverse("%s:%s_%s_change" % (self.admin_site.name, opts.app_label, opts.model_name),
args=(quote(obj.pk),)),
"original": obj,
"history_url": reverse("%s:%s_%s_history" % (self.admin_site.name, opts.app_label, opts.module_name),
"history_url": reverse("%s:%s_%s_history" % (self.admin_site.name, opts.app_label, opts.model_name),
args=(quote(obj.pk),)),
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_text_diff(self):
queryset = custom_revision_manager.get_for_object(self.item)
version_ids = queryset.values_list("pk", flat=True)
self.assertEqual(len(version_ids), 2)
url_name = 'admin:%s_%s_compare' % (CustomModel._meta.app_label, CustomModel._meta.module_name)
url_name = 'admin:%s_%s_compare' % (CustomModel._meta.app_label, CustomModel._meta.model_name)
diff_url = reverse(url_name, args=(self.item.pk, ))
data = {"version_id2": version_ids[0], "version_id1": version_ids[1]}
response = self.client.get(diff_url, data=data)
Expand All @@ -83,7 +83,7 @@ def test_version_selection(self):
queryset = custom_revision_manager.get_for_object(self.item)
version_ids = queryset.values_list("pk", flat=True)
self.assertEqual(len(version_ids), 3)
url_name = 'admin:%s_%s_history' % (CustomModel._meta.app_label, CustomModel._meta.module_name)
url_name = 'admin:%s_%s_history' % (CustomModel._meta.app_label, CustomModel._meta.model_name)
history_url = reverse(url_name, args=(self.item.pk, ))
response = self.client.get(history_url)
self.assertContainsHtml(response,
Expand Down
1 change: 0 additions & 1 deletion tests/test_factory_car_reverse_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def test_diff1(self):
self.assertContainsHtml(response,
'''
<p class="highlight">
<del>- motor-car four from factory one supplier(s): </del><sup class="follow">*</sup><br />
<del>- motor-car three from factory one supplier(s):</del> &rarr; Deleted<br />
<ins>+ motor-car four from factory one supplier(s): </ins><br />
motor-car one from factory one supplier(s): <br />
Expand Down