carlxaeron / django-rosetta

Automatically exported from code.google.com/p/django-rosetta
MIT License
0 stars 0 forks source link

Integration into Admin interface #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
No Problem at all, just an enhancement.

I like everything connected with my admin. Therefore I put Rosetta into the
URL conf like this:

    (r'^admin/translation/',include('rosetta.urls')),
    (r'^admin/', include('django.contrib.admin.urls')),

And I changed the Templates like this:

rosetta/language.html
    {% block breadcumbs %}<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="{% url rosetta-pick-file %}">{% trans "Rosetta" %}</a> &rsaquo; {%
trans "Language selection" %}{% endblock %}

rosetta/profile.html
    {% block breadcumbs %}
    <a href="../../">{% trans "Home" %}</a> &rsaquo;
    <a href="{% url rosetta-pick-file %}">{% trans "Rosetta" %}</a> &rsaquo;
    {{ rosetta_i18n_lang_name }} &rsaquo;
        {{ rosetta_i18n_fn }} &rsaquo;
        {% blocktrans with
rosetta_i18n_pofile.percent_translated|floatformat:2 as percent_translated
 %}Progress: {{ percent_translated }}%{% endblocktrans %}
        {% if not rosetta_i18n_write %}<span class="alert">{% trans "File
is read-only: download the file when done editing!" %}</span>{% endif %}
    {% endblock %}

Finally I overwrite the "admin/index.html" like this (add before "{%
get_admin_app_list as app_list %}"):

    <div class="module">
        <table>
            <caption>{% trans "System Translations" %} (Rosetta)</caption>
            <tr class="row2">
                <th scope="row"><a href="translation/">Rosetta</a></th>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </div>

That's it. Now Rosetta is perfectly embedded into the admin interface.

Hopefully you like these template changes. Maybe you add the
"admin/index.html" overwriting (not replacing) to the Install introduction.

Cheers from Cologne
Martin

Original issue reported on code.google.com by iusgent...@gmail.com on 12 Apr 2008 at 10:30

GoogleCodeExporter commented 8 years ago
Martin, thank you for your patch. I've considered a closer integration to the 
Django admin before, but I don't 
think that is even possible.

Original comment by mbonetti on 14 Apr 2008 at 9:01

GoogleCodeExporter commented 8 years ago
Another option to do this is by creating an empty rosetta model, after that you 
can
just overwrite the admin/rosetta/translation url and it will work without 
modifying
the admin templates.

The downside is that you'll have an empty table in the database though.

Original comment by Wolphie on 29 Apr 2008 at 3:50

GoogleCodeExporter commented 8 years ago
Alas that's the whole point: being able to enable and disable the application 
without the need to sync db's

Original comment by mbonetti on 29 Apr 2008 at 6:47

GoogleCodeExporter commented 8 years ago
That is still possible, since you aren't going to use the table in the model you
won't have to sync the database to make it work.

Original comment by Wolphie on 30 Apr 2008 at 1:15

GoogleCodeExporter commented 8 years ago
Right, here is my final decision on this point: because it is no 
straightforward way to do this, the only way this is 
gonna happen is rosetta gets officially imported into Django as e.g. 
django.contrib.admin.rosetta or if Django 
adds a better way to integrate external apps into the admin.

Original comment by mbonetti on 24 Jun 2008 at 7:35

GoogleCodeExporter commented 8 years ago
if you want show only in applications list:
admin/index.html
{% if app_list|length != 1 %}
        <div class="module">
            <table>
                <caption>{% trans "System Translations" %}</caption>
                <tr class="row2">
                    <th scope="row">
                        <a href="translation/">
                            {% trans "Translations" %}
                        </a>
                    </th>
                    <td> </td>
                    <td> </td>
                </tr>
            </table>
        </div>
    {% endif %}

Original comment by cet...@gmail.com on 16 Aug 2011 at 1:11

GoogleCodeExporter commented 8 years ago
Another options is to use the 'django-admin-tools' package, or at least its 
menu app. Then you can do:

yourproject/settings.py
ADMIN_TOOLS_MENU = 'yourapp.admin.CustomAdminMenu'

yourapp/admin.py
class CustomAdminMenu(Menu):
  """ Custom Menu for admin site. """
  def __init__(self, **kwargs):
    Menu.__init__(self, **kwargs)
    self.children += [
      items.MenuItem(_('Dashboard'), reverse('admin:index')),
      items.Bookmarks(),
      items.AppList(
        _('Applications'),
        exclude=('django.contrib.*',)
      ),
      items.AppList(
        _('Administration'),
        models=('django.contrib.*',)
      ),
      items.MenuItem(_('Translations'), reverse('rosetta-home')),
    ]

  def init_with_context(self, context):
    """Use this method if you need to access the request context."""
    return super(CustomAdminMenu, self).init_with_context(context)

Original comment by anti...@gmail.com on 2 Feb 2015 at 6:04

GoogleCodeExporter commented 8 years ago
Oops, forgot a "from admin_tools.menu import items, Menu" there

Original comment by anti...@gmail.com on 2 Feb 2015 at 6:17

GoogleCodeExporter commented 8 years ago
Or using wp_admin:

settings.py
WPADMIN = { ....       
   'left': 'consulthelp.admin.CustomLeftMenu', 
....
}

yourapp/admin.py
from wpadmin.menu import items
from wpadmin.menu.menus import BasicLeftMenu
class CustomLeftMenu(BasicLeftMenu):
  """ Custom Menu for admin site. """

  def init_with_context(self, context):
    if self.is_user_allowed(context.get('request').user):
      super(CustomLeftMenu, self).init_with_context(context)
      self.children += [
        items.MenuItem(
          title=_('Translations'),
          icon='fa-book',
          url=reverse('rosetta-home'),
          description=_('Translations'),
        ),
      ]

Original comment by anti...@gmail.com on 2 Feb 2015 at 6:29