Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

1 language on object creation, empty tabs at end, can't remove default translation, CSS changed #9

Closed
wants to merge 6 commits into from

3 participants

@rvikmanis
  • Does not display additional language tabs on object creation, only default language
  • Empty language tabs go to the end
  • Can't remove default translation
  • CSS changed:
    • empty languages = color: #ccc
    • available but not currently selected = font-weight: normal
  • added __unicode__ method to BaseTranslationModel
@KristianOellegaard

Hi!

Thanks a lot for your pull request. As this is a project we use in many other projects and since it seems to be a cosmetic change, I'll have a look when i return to work in january.

Hope you had a great christmas and have a happy new year.

Kristian

nani/admin.py
((10 lines not shown))
status = 'available'
else:
status = 'empty'
- tabs.append((url, name, key, status))
+ if key == settings.LANGUAGE_CODE:
+ primary = True
+ else:
+ primary = False
+ tabs.append((url, name, key, status, primary, current))
+ scmp = lambda x,y: cmp((primary or y[3]!='empty'), x[3]!='empty')
@ojii Collaborator
ojii added a note

NOT a fan of this. cmp is deprecated in Python to my knowledge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 23, 2011
  1. @rvikmanis
  2. @rvikmanis
  3. @rvikmanis

    Empty language tabs go to the end

    rvikmanis authored
    CSS changed:
      empty languages = color: #ccc
      available but not currently selected = font-weight: normal
  4. @rvikmanis
  5. @rvikmanis

    removed duplicate imports

    rvikmanis authored
Commits on Feb 19, 2012
  1. @rvikmanis
This page is out of date. Refresh to see the latest.
View
22 nani/admin.py
@@ -19,6 +19,7 @@
from django.utils.translation import ugettext_lazy as _, get_language
from functools import update_wrapper
from nani.forms import TranslatableModelForm, translatable_inlineformset_factory, translatable_modelform_factory
+from nani.models import get_language_name
import django
import urllib
from nani.utils import get_cached_translation, get_translation
@@ -28,8 +29,6 @@
NEW_GET_DELETE_OBJECTS = LooseVersion(django.get_version()) >= LooseVersion('1.3')
-def get_language_name(language_code):
- return dict(settings.LANGUAGES).get(language_code, language_code)
class InlineModelForm(TranslatableModelForm):
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
@@ -107,12 +106,21 @@ def get_language_tabs(self, request, available_languages):
request.get_host(), request.path,
urllib.urlencode(get))
if language == key:
- status = 'current'
- elif key in available_languages:
+ current = True
+ else:
+ current = False
+ if key in available_languages:
status = 'available'
else:
status = 'empty'
- tabs.append((url, name, key, status))
+ if key == settings.LANGUAGE_CODE:
+ primary = True
+ else:
+ primary = False
+ tabs.append((url, name, key, status, primary, current))
+ cmp = lambda x,y: (x>y) - (x<y)
+ scmp = lambda x,y: cmp((primary or y[3]!='empty'), x[3]!='empty')
+ tabs.sort(scmp)
return tabs
def _language(self, request):
@@ -188,6 +196,10 @@ def render_change_form(self, request, context, add=False, change=False,
context['allow_deletion'] = len(available_languages) > 1
context['language_tabs'] = self.get_language_tabs(request, available_languages)
context['base_template'] = self.get_change_form_base_template()
+
+ if add:
+ context['language_tabs'] = context['language_tabs'][:1]
+
return super(TranslatableAdmin, self).render_change_form(request,
context,
add, change,
View
6 nani/models.py
@@ -8,7 +8,10 @@
from nani.manager import TranslationManager, TranslationsModelManager
from nani.utils import SmartGetFieldByName
from types import MethodType
+from django.conf import settings
+def get_language_name(language_code):
+ return dict(settings.LANGUAGES).get(language_code, language_code)
def create_translations_model(model, related_name, meta, **fields):
"""
@@ -80,6 +83,9 @@ def __init__(self, *args, **kwargs):
class Meta:
abstract = True
+
+ def __unicode__(self):
+ return get_language_name(self.language_code)
class TranslatableModelBase(ModelBase):
View
21 nani/templates/admin/nani/change_form.html
@@ -12,15 +12,20 @@
position: relative;
left: 0px;
top: 1px;
- font-weight: bold;
+ font-weight: normal;
}
.nani-language-tabs span.current {
border-bottom: 1px solid #fff;
+ font-weight: bold;
+}
+.nani-language-tabs span a {
}
.nani-language-tabs span.empty {
- opacity: 0.7;
font-weight: normal;
}
+.nani-language-tabs span.empty a {
+ color: #ccc;
+}
.nani-language-tabs a.deletelink {
right: -17px;
bottom: 4px;
@@ -32,12 +37,12 @@
{% block object-tools %}
{{ block.super }}
<div class="nani-language-tabs">
- {% for url,name,code,status in language_tabs %}
- {% if status == 'current' %}
- <span class="current">{{ name }}{% if current_is_translated and allow_deletion %}<a class="deletelink" href="./delete-translation/{{ code }}/" title="{% trans 'Delete Translation' %}">&nbsp;</a>{% endif %}</span>
- {% else %}
- <span class="{{ status }}"><a href="{{ url }}">{{ name }}</a> {% if status == 'available' and allow_deletion %}<a class="deletelink" href="./delete-translation/{{ code }}/" title="{% trans 'Delete Translation' %}">&nbsp;</a>{% endif %}</span>
- {% endif %}
+ {% for url,name,code,status,primary,current in language_tabs %}
+ {% if current %}
+ <span class="current" {% if not current_is_translated %}style="color: #ccc;"{% endif %}>{{ name }}{% if not primary and current_is_translated and allow_deletion %}<a class="deletelink" href="./delete-translation/{{ code }}/" title="{% trans 'Delete Translation' %}">&nbsp;</a>{% endif %}</span>
+ {% else %}
+ <span class="{{ status }}"><a href="{{ url }}">{{ name }}</a> {% if not primary and status == 'available' and allow_deletion %}<a class="deletelink" href="./delete-translation/{{ code }}/" title="{% trans 'Delete Translation' %}">&nbsp;</a>{% endif %}</span>
+ {% endif %}
{% endfor %}
</div>
{% endblock %}
Something went wrong with that request. Please try again.