use AdminSite.index_template instead of overriding the default AdminSite

This commit is contained in:
Marco Bonetti 2016-12-13 11:26:01 +01:00
parent cc74135ff2
commit 67285f2174
6 changed files with 32 additions and 31 deletions

View file

@ -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

View file

@ -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
--------

View file

@ -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
@ -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'

View file

@ -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 %}

View file

@ -12,7 +12,7 @@ import os
import shutil
import six
import django
import vcr
# import vcr
import hashlib
@ -57,6 +57,7 @@ class RosettaTestCase(TestCase):
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')
@ -67,6 +68,8 @@ class RosettaTestCase(TestCase):
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):
@ -823,6 +826,10 @@ class RosettaTestCase(TestCase):
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):

View file

@ -113,3 +113,4 @@ SECRET_KEY = 'empty'
ROSETTA_ENABLE_REFLANG = True
ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True
ROSETTA_SHOW_AT_ADMIN_PANEL = True