示例#1
0
            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 ''
示例#2
0
    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&amp;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''
示例#3
0
    def translation_admin(self, *args, **kwargs):
        """
        Gets a HTML with URL to the original translation of available. For admin use.

        :return str:
        """
        if self.translation_of:
            if not PY3:
                url_title = unicode(self.translation_of)
            else:
                url_title = self.translation_of

            return admin_change_url(self._meta.app_label,
                                    self._meta.module_name,
                                    self.translation_of.id,
                                    url_title=url_title)
        return ''
示例#4
0
    def translation_admin(self, *args, **kwargs):
        """
        Gets a HTML with URL to the original translation of available. For admin use.

        :return str:
        """
        if self.translation_of:
            if not PY3:
                url_title = unicode(self.translation_of)
            else:
                url_title = self.translation_of

            return admin_change_url(
                self._meta.app_label,
                self._meta.module_name,
                self.translation_of.id,
                url_title = url_title
                )
        return ''