def _available_translations_admin(self, include_self=True): """ Gets a HTML with all available translation URLs for current object if available. For admin use. :return str: """ try: original_translation = self.original_translation available_translations = list( self.available_translations()) languages_keys = get_languages_keys() languages = dict(get_languages()) if include_self: available_translations.append(self) output = [] # Processing all available translations. Adding edit links. if available_translations: for translation in available_translations: if PY2: url_title = unicode( languages[translation.language]) else: url_title = languages[translation.language] output.append( admin_change_url(translation._meta.app_label, translation._meta.module_name, translation.id, url_title=url_title)) languages_keys.remove(translation.language) if self.pk and self.language in languages_keys: languages_keys.remove(self.language) # For all languages that are still available (original object has no translations for) for language in languages_keys: url = admin_add_url( self._meta.app_label, self._meta.module_name, '?translation_of=%s&language=%s' % (str(original_translation.id), language)) if PY2: name = unicode(languages[language]) else: name = languages[language] output.append( u'<a href="%(url)s" style="color:#baa">%(name)s</a>' % { 'url': url, 'name': name }) return ' | '.join(output) except Exception as e: return ''
def _available_translations_admin(self, include_self=True): """ Gets a HTML with all available translation URLs for current object if available. For admin use. :return str: """ try: original_translation = self.original_translation available_translations = list(self.available_translations()) languages_keys = get_languages_keys() languages = dict(get_languages()) if include_self: available_translations.append(self) output = [] # Processing all available translations. Adding edit links. if available_translations: for translation in available_translations: if not PY3: url_title = unicode(languages[translation.language]) else: url_title = languages[translation.language] output.append( admin_change_url( translation._meta.app_label, translation._meta.module_name, translation.id, url_title = url_title ) ) languages_keys.remove(translation.language) if self.pk and self.language in languages_keys: languages_keys.remove(self.language) # For all languages that are still available (original object has no translations for) for language in languages_keys: url = admin_add_url( self._meta.app_label, self._meta.module_name, '?translation_of=%s&language=%s' % (str(original_translation.id), language) ) if not PY3: name = unicode(languages[language]) else: name = languages[language] output.append(u'<a href="%(url)s" style="color:#baa">%(name)s</a>' % {'url': url, 'name': name}) return u' | '.join(output) except Exception as e: return u''
def __init__(self, *args, **kwargs): """ Create new field. Argument ``populate`` will be sent as-is to the form field. """ defaults = { 'verbose_name': _('Language'), 'populate': None, 'max_length': 10, 'choices': get_languages(), 'default': default_language } defaults.update(kwargs) self.populate = defaults.pop('populate', None) super(SimpleLanguageField, self).__init__(*args, **defaults)