Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 4 commits into from

3 participants

Rūdolfs Vikmanis Ales Kocjancic Jonas Obrist
Rūdolfs Vikmanis
  • 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
Rūdolfs Vikmanis

added __unicode__ method to BaseTranslationModel and moved get_language_name from admin.py to models.py

moving the function was necessary because you can't import nani.admin from nani.models without circular import errors, and defining the function in two modules is redundant

Ales Kocjancic

you should probably make this pull request on django-hvad, as the development of nani moved there ;)

Jonas Obrist
Owner

yes, development now happens over at https://github.com/KristianOellegaard/django-hvad so rebase your pull request for that and submit it there, thank you

Jonas Obrist ojii closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 22, 2011
  1. Rūdolfs Vikmanis
  2. Rūdolfs Vikmanis
  3. Rūdolfs Vikmanis

    Empty language tabs go to the end

    rvikmanis authored
    CSS changed:
      empty languages = color: #ccc
      available but not currently selected = font-weight: normal
Commits on Dec 23, 2011
  1. Rūdolfs Vikmanis
This page is out of date. Refresh to see the latest.
21 nani/admin.py
View
@@ -22,6 +22,7 @@
from functools import update_wrapper
from nani.forms import TranslatableModelForm
from nani.utils import get_cached_translation, get_translation
+from nani.models import get_language_name
import django
import urllib
@@ -29,8 +30,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 CleanMixin(object):
def clean(self):
@@ -190,12 +189,20 @@ 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))
+ scmp = lambda x,y: cmp((primary or y[3]!='empty'), x[3]!='empty')
+ tabs.sort(scmp)
return tabs
def _language(self, request):
@@ -271,6 +278,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,
6 nani/models.py
View
@@ -7,7 +7,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):
"""
@@ -77,6 +80,9 @@ def __init__(self, *args, **kwargs):
class Meta:
abstract = True
+
+ def __unicode__(self):
+ return get_language_name(self.language_code)
class TranslatableModelBase(ModelBase):
21 nani/templates/admin/nani/change_form.html
View
@@ -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.