Skip to content

Commit

Permalink
use AdminSite.index_template instead of overriding the default AdminSite
Browse files Browse the repository at this point in the history
  • Loading branch information
mbi committed Dec 13, 2016
1 parent cc74135 commit 67285f2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version History
Version 0.7.13 (unreleased)
---------------------------
* Search in comments, too (PR #174, thanks @torchingloom)
* Added `ROSETTA_SHOW_AT_ADMIN_PANEL` setting to display add a link to Rosetta from the admin app index page. (PR #176, thanks @scream4ik)


Version 0.7.12
Expand Down
2 changes: 1 addition & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Rosetta can be configured via the following parameters, to be defined in your pr
* ``ROSETTA_EXCLUDED_PATHS``: Exclude paths defined in this list from being searched (usually ends with "locale"). Defaults to ``()``
* ``ROSETTA_AUTO_COMPILE``: Determines whether the MO file is automatically compiled when the PO file is saved. Defaults to ``True``.
* ``ROSETTA_ENABLE_REFLANG``: Enables a selector for picking a reference language other than English. Defaults to ``False``.
* ``ROSETTA_SHOW_AT_ADMIN_PANEL``: Enable rosetta at administration panel (NOTE: rosetta need to be first at INSTALLED_APPS). Defaults to ``False``.
* ``ROSETTA_SHOW_AT_ADMIN_PANEL``: Adds a handy link to Rosetta at the bottom of the Django admin apps index. Defaults to ``False``.

Storages
--------
Expand Down
30 changes: 1 addition & 29 deletions rosetta/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from django.apps import AppConfig
from django.views.decorators.cache import never_cache
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _

from rosetta.conf import settings as rosetta_settings


Expand All @@ -11,30 +7,6 @@ class RosettaAppConfig(AppConfig):

def ready(self):
from django.contrib import admin
from django.contrib.admin import sites

class RosettaAdminSite(admin.AdminSite):
@never_cache
def index(self, request, extra_context=None):
resp = super(RosettaAdminSite, self).index(request,
extra_context)
app_dict = {
'app_url': reverse('rosetta-home'),
'models': [
{
'admin_url': reverse('rosetta-home'),
'name': _('Browse'),
'add_url': None
},
],
'has_module_perms': True,
'name': _('Translations'),
'app_label': 'rosetta'
}
resp.context_data['app_list'].append(app_dict)
return resp

if rosetta_settings.SHOW_AT_ADMIN_PANEL:
rosetta = RosettaAdminSite()
admin.site = rosetta
sites.site = rosetta
admin.site.index_template = 'rosetta/admin_index.html'
20 changes: 20 additions & 0 deletions rosetta/templates/rosetta/admin_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "admin/index.html" %}
{% load i18n %}

{% block sidebar %}
{{block.super}}
<div id="rosetta-content-main">
<div class="app-rosetta module">
<table>
<caption>
<a class="section" href="{% url 'rosetta-home' %}">Rosetta</a>
</caption>
<tbody><tr>
<th scope="row"><a href="{% url 'rosetta-home' %}">{% trans "Translations" %}</a></th>
<td colspan="2"><a href="{% url 'rosetta-home' %}" class="changelink">{% trans "Change" %}</a></td>
</tr>
</tbody></table>
</div>
</div>

{% endblock %}
9 changes: 8 additions & 1 deletion rosetta/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import shutil
import six
import django
import vcr
# import vcr
import hashlib


Expand Down Expand Up @@ -57,6 +57,7 @@ def setUp(self):
self.__require_auth = rosetta_settings.ROSETTA_REQUIRES_AUTH
self.__enable_translation = rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS
self.__auto_compile = rosetta_settings.AUTO_COMPILE
self.__admin_panel_embed = rosetta_settings.SHOW_AT_ADMIN_PANEL

shutil.copy(self.dest_file, self.dest_file + '.orig')

Expand All @@ -67,6 +68,8 @@ def tearDown(self):
rosetta_settings.ROSETTA_REQUIRES_AUTH = self.__require_auth
rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS = self.__enable_translation
rosetta_settings.AUTO_COMPILE = self.__auto_compile
rosetta_settings.SHOW_AT_ADMIN_PANEL = self.__admin_panel_embed

shutil.move(self.dest_file + '.orig', self.dest_file)

def test_1_ListLoading(self):
Expand Down Expand Up @@ -823,6 +826,10 @@ def message_hashes():
self.assertNotEqual(po_file_hash_before, po_file_hash_after)
self.assertNotEqual(mo_file_hash_before, mo_file_hash_after)

def test_41_pr_176_embed_in_admin(self):
resp = self.client.get(reverse('admin:index'))
self.assertTrue('app-rosetta module' in str(resp.content))


# Stubbed access control function
def no_access(user):
Expand Down
1 change: 1 addition & 0 deletions testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@

ROSETTA_ENABLE_REFLANG = True
ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True
ROSETTA_SHOW_AT_ADMIN_PANEL = True

0 comments on commit 67285f2

Please sign in to comment.