Permalink
Browse files

Merge pull request #41 from freshlimestudio/master

Small fixes for admin
  • Loading branch information...
2 parents f044eca + 00baf51 commit 4cb7c35e4f41e0a1a0a2a23b1f3883e06a00b975 @KristianOellegaard committed Apr 17, 2012
Showing with 23 additions and 10 deletions.
  1. +4 −1 nani/admin.py
  2. +19 −9 nani/tests/limit_choices_to.py
View
5 nani/admin.py
@@ -273,10 +273,13 @@ def delete_translation(self, request, object_id, language_code):
"perms_lacking": perms_needed,
"protected": protected,
"opts": opts,
- "root_path": self.admin_site.root_path,
"app_label": app_label,
}
+ # in django > 1.4 root_path is removed
+ if hasattr(self.admin_site, 'root_path'):
+ context.update({"root_path": self.admin_site.root_path})
+
return render_to_response(self.delete_confirmation_template or [
"admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()),
"admin/%s/delete_confirmation.html" % app_label,
View
28 nani/tests/limit_choices_to.py
@@ -1,20 +1,27 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
+from django.contrib.auth.models import User
from nani.test_utils.testcase import NaniTestCase
-from nani.test_utils.fixtures import (
- TwoTranslatedNormalMixin,
- SuperuserMixin,
-)
+from nani.test_utils.fixtures import TwoTranslatedNormalMixin
from testproject.app.models import LimitedChoice
-class LimitChoicesToTests(
- NaniTestCase,
- TwoTranslatedNormalMixin,
- SuperuserMixin
-):
+class LimitChoicesToTests(NaniTestCase, TwoTranslatedNormalMixin):
+ def create_fixtures(self):
+ su = User(
+ email='admin@admin.com',
+ is_staff=True,
+ is_superuser=True,
+ is_active=True,
+ username='admin',
+ )
+ su.set_password('admin')
+ su.save()
+ self.user = su
+ super(LimitChoicesToTests, self).create_fixtures()
+
def test_limit_choices_to(self):
"""
Checks if limit_choices_to works on ForeignKey and ManyToManyField.
@@ -33,6 +40,9 @@ def test_limit_choices_to(self):
# otherwise admin won't let us in
get_request.session = self.client.session
+ # in django 1.4 request.user is required
+ get_request.user = self.user
+
# Let's construct the relevant admin form...
Form = limited_choice_admin.get_form(get_request)
form = Form()

0 comments on commit 4cb7c35

Please sign in to comment.