def handle_modeladmin(self, modeladmin): extensions.prefetch_modeladmin_get_queryset( modeladmin, 'translation_of__translations', 'translations') def available_translations_admin(self, page): translations = dict((p.language, p.id) for p in page.available_translations()) links = [] for key, title in django_settings.LANGUAGES: if key == page.language: continue if key in translations: links.append(u'<a href="%s/" title="%s">%s</a>' % ( translations[key], _('Edit translation'), key.upper())) else: links.append(u'<a style="color:#baa" href="add/?translation_of=%s&language=%s" title="%s">%s</a>' % ( page.id, key, _('Create translation'), key.upper())) return u' | '.join(links) available_translations_admin.allow_tags = True available_translations_admin.short_description = _('translations') modeladmin.__class__.available_translations_admin = available_translations_admin if hasattr(modeladmin, 'add_extension_options'): modeladmin.add_extension_options('language', 'translation_of') modeladmin.list_display.extend(['language', 'available_translations_admin']) modeladmin.list_filter.extend(['language']) modeladmin.raw_id_fields.append('translation_of')
def handle_modeladmin(self, modeladmin): extensions.prefetch_modeladmin_get_queryset( modeladmin, 'translation_of__translations', 'translations') def available_translations_admin(self, page): # Do not use available_translations() because we don't care # whether pages are active or not here. translations = [page] translations.extend(page.translations.all()) if page.translation_of: translations.append(page.translation_of) translations.extend(page.translation_of.translations.all()) translations = { p.language: p.id for p in translations } links = [] for key, title in django_settings.LANGUAGES: if key == page.language: continue if key in translations: links.append('<a href="%s/" title="%s">%s</a>' % ( translations[key], _('Edit translation'), key.upper())) else: links.append( '<a style="color:#baa" href="add/?translation_of=' '%s&language=%s" title="%s">%s</a>' % ( page.id, key, _('Create translation'), key.upper() ) ) return ' | '.join(links) available_translations_admin.allow_tags = True available_translations_admin.short_description = _('translations') modeladmin.__class__.available_translations_admin =\ available_translations_admin if hasattr(modeladmin, 'add_extension_options'): modeladmin.add_extension_options('language', 'translation_of') modeladmin.extend_list( 'list_display', ['language', 'available_translations_admin'], ) modeladmin.extend_list('list_filter', ['language']) modeladmin.extend_list('raw_id_fields', ['translation_of'])
def handle_modeladmin(self, modeladmin): extensions.prefetch_modeladmin_get_queryset( modeladmin, 'translation_of__translations', 'translations') def available_translations_admin(self, page): # Do not use available_translations() because we don't care # whether pages are active or not here. translations = [page] translations.extend(page.translations.all()) if page.translation_of: translations.append(page.translation_of) translations.extend(page.translation_of.translations.all()) translations = { p.language: p.id for p in translations } links = [] for key, title in django_settings.LANGUAGES: if key == page.language: continue if key in translations: links.append('<a href="%s/" title="%s">%s</a>' % ( translations[key], _('Edit translation'), key.upper())) else: links.append( '<a style="color:#baa" href="add/?translation_of=' '%s&language=%s" title="%s">%s</a>' % ( page.id, key, _('Create translation'), key.upper() ) ) return mark_safe(' | '.join(links)) available_translations_admin.short_description = _('translations') modeladmin.__class__.available_translations_admin =\ available_translations_admin if hasattr(modeladmin, 'add_extension_options'): modeladmin.add_extension_options('language', 'translation_of') modeladmin.extend_list( 'list_display', ['language', 'available_translations_admin'], ) modeladmin.extend_list('list_filter', ['language']) modeladmin.extend_list('raw_id_fields', ['translation_of'])
def handle_modeladmin(self, modeladmin): extensions.prefetch_modeladmin_get_queryset( modeladmin, "translation_of__translations", "translations" ) def available_translations_admin(self, page): # Do not use available_translations() because we don't care # whether pages are active or not here. translations = [page] translations.extend(page.translations.all()) if page.translation_of: translations.append(page.translation_of) translations.extend(page.translation_of.translations.all()) translations = {p.language: p.id for p in translations} links = [] for key, title in django_settings.LANGUAGES: if key == page.language: continue if key in translations: links.append( '<a href="%s/" title="%s">%s</a>' % (translations[key], _("Edit translation"), key.upper()) ) else: links.append( '<a style="color:#baa" href="add/?translation_of=' '%s&language=%s" title="%s">%s</a>' % (page.id, key, _("Create translation"), key.upper()) ) return mark_safe(" | ".join(links)) available_translations_admin.short_description = _("translations") modeladmin.__class__.available_translations_admin = available_translations_admin if hasattr(modeladmin, "add_extension_options"): modeladmin.add_extension_options("language", "translation_of") modeladmin.extend_list( "list_display", ["language", "available_translations_admin"] ) modeladmin.extend_list("list_filter", ["language"]) modeladmin.extend_list("raw_id_fields", ["translation_of"])
def handle_modeladmin(self, modeladmin): extensions.prefetch_modeladmin_get_queryset( modeladmin, 'translation_of__translations', 'translations') def available_translations_admin(self, page): translations = dict( (p.language, p.id) for p in page.available_translations()) links = [] for key, title in django_settings.LANGUAGES: if key == page.language: continue if key in translations: links.append('<a href="%s/" title="%s">%s</a>' % (translations[key], _('Edit translation'), key.upper())) else: links.append( '<a style="color:#baa" href="add/?translation_of=' '%s&language=%s" title="%s">%s</a>' % (page.id, key, _('Create translation'), key.upper())) return ' | '.join(links) available_translations_admin.allow_tags = True available_translations_admin.short_description = _('translations') modeladmin.__class__.available_translations_admin =\ available_translations_admin if hasattr(modeladmin, 'add_extension_options'): modeladmin.add_extension_options('language', 'translation_of') modeladmin.extend_list( 'list_display', ['language', 'available_translations_admin'], ) modeladmin.extend_list('list_filter', ['language']) modeladmin.extend_list('raw_id_fields', ['translation_of'])