Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
walterrenner committed Dec 5, 2017
2 parents cb4fb2e + ad5ab75 commit 480e25f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Contributors
* Corey Farwell (frewsxcv)
* Thomas Baguet (t0mab)
* Preston (pwag42)
* Tobin Brown (Brobin)


Your name could stand here :)
21 changes: 21 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== (ongoing) ===
-

== (2.1.4) ==
- Django 1.11 support

== (2.1.3) ==
- Settings of UserAdmin such as list_display are not overridden anymore, only the hijack button is added
- Add French translation
- Include compiled messages in package


== (2.1.2) ==
- Django 1.10 compatibility
- Drop support for Django 1.7 (might still work, but tests are allowed to fail)

== (2.1.1) ==
- Do not warn about custom user model if correctly configured

== (2.1.0) ==
- Initial release after moving the admin integration out of the django-hijack core
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Django admin integration for Django Hijack (https://github.com/arteria/django-hi

[![Build Status](https://travis-ci.org/arteria/django-hijack-admin.svg?branch=master)](https://travis-ci.org/arteria/django-hijack-admin)
[![Coverage Status](https://coveralls.io/repos/arteria/django-hijack-admin/badge.svg?branch=master&service=github)](https://coveralls.io/github/arteria/django-hijack-admin?branch=master)
[![PyPI](https://img.shields.io/pypi/v/django-hijack-admin.svg)](https://pypi.python.org/pypi/django-hijack-admin)

![Screenshot of django-hijack in action on the admin site.](docs/admin-screenshot.png)

Expand Down Expand Up @@ -50,3 +51,21 @@ class MyUserAdmin(UserAdmin, HijackUserAdminMixin):
'hijack_field', # Hijack button
)
```

## Models with ForeignKey to User
You can also add the hijack field to a model that is related to the User
model with the `HijackRelatedAdminMixin`.

```python
#admin.py
from django.contrib import Admin
from hijack_admin.admin import HijackRelatedAdminMixin

class MyCustomerAdmin(HijackRelatedAdminMixin, admin.ModelAdmin)
list_display = ('user', 'hijack_field')
```


| django-hijack-admin is free software. If you find it useful and would like to give back, please consider to make a donation using [Bitcoin](https://blockchain.info/payment_request?address=1AJkbQdcNkrHzxi91mB1kkPxh4t4BJ4hu4) or [PayPal](https://www.paypal.me/arteriagmbh). Thank you! |
| ----- |

2 changes: 1 addition & 1 deletion hijack_admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
__version__ = '2.1.3' # pragma: no cover
__version__ = '2.1.4' # pragma: no cover

default_app_config = 'hijack_admin.apps.HijackAdminConfig'
7 changes: 7 additions & 0 deletions hijack_admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ def hijack_field(self, obj):
hijack_field.short_description = _('Hijack user')


class HijackRelatedAdminMixin(HijackUserAdminMixin):

def hijack_field(self, obj):
return super(HijackRelatedAdminMixin, self).hijack_field(obj.user)


class HijackUserAdmin(HijackUserAdminMixin, UserAdmin):
list_display = UserAdmin.list_display + ('hijack_field', )


if hijack_admin_settings.HIJACK_REGISTER_ADMIN:
UserModel = get_user_model()
admin.site.unregister(UserModel)
Expand Down
5 changes: 5 additions & 0 deletions hijack_admin/tests/test_app/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from django.conf import settings
from django.db import models


class BasicModel(models.Model):
pass


class RelatedModel(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='related')
6 changes: 6 additions & 0 deletions hijack_admin/tests/test_hijack_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from hijack.tests.utils import SettingsOverride

from hijack_admin import settings as hijack_admin_settings
from hijack_admin.tests.test_app.models import RelatedModel


class HijackAdminTests(BaseHijackTests):
Expand All @@ -18,6 +19,11 @@ def test_hijack_button(self):
response = self.client.get('/admin/auth/user/')
self.assertTrue('<a href="/hijack/{}/" class="button">'.format(self.user.id) in str(response.content))

def test_hijack_button_related(self):
RelatedModel.objects.create(user=self.user)
response = self.client.get('/admin/test_app/relatedmodel/')
self.assertTrue('<a href="/hijack/{}/" class="button">'.format(self.user.id) in str(response.content))

def test_settings(self):
self.assertTrue(hasattr(hijack_admin_settings, 'HIJACK_BUTTON_TEMPLATE'))
self.assertEqual(hijack_admin_settings.HIJACK_BUTTON_TEMPLATE, 'hijack_admin/admin_button.html')
Expand Down
10 changes: 10 additions & 0 deletions hijack_admin/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
from compat import include, url

from django.contrib import admin

from hijack_admin.admin import HijackRelatedAdminMixin
from hijack_admin.tests.test_app.models import RelatedModel


@admin.register(RelatedModel)
class RelatedModelAdmin(HijackRelatedAdminMixin, admin.ModelAdmin):
list_display = ('user', 'hijack_field')


admin.autodiscover()

urlpatterns = [
Expand Down

0 comments on commit 480e25f

Please sign in to comment.