Exemple #1
0
    def pre_sql_setup(self):
        """
        Adds the JOINS and SELECTS for fetching multilingual data.
        """
        super(MultilingualSQLCompiler, self).pre_sql_setup()

        if not self.query.include_translation_data:
            return

        opts = self.query.model._meta
        qn = self.quote_name_unless_alias
        qn2 = self.connection.ops.quote_name

        if hasattr(opts, 'translation_model'):
            master_table_name = self.query.join(
                (None, opts.db_table, None, None))
            translation_opts = opts.translation_model._meta
            trans_table_name = translation_opts.db_table
            for language_code in get_language_code_list():
                table_alias = get_translation_table_alias(
                    trans_table_name, language_code)
                trans_join = (
                    "LEFT JOIN %s AS %s ON ((%s.master_id = %s.%s) AND (%s.language_code = '%s'))"
                    % (qn2(translation_opts.db_table), qn2(table_alias),
                       qn2(table_alias), qn(master_table_name),
                       qn2(opts.pk.column), qn2(table_alias), language_code))
                self.query.extra_join[table_alias] = trans_join
    def pre_sql_setup(self):
        """
        Adds the JOINS and SELECTS for fetching multilingual data.
        """
        super(MultilingualSQLCompiler, self).pre_sql_setup()

        if not self.query.include_translation_data:
            return

        opts = self.query.model._meta
        qn = self.quote_name_unless_alias
        qn2 = self.connection.ops.quote_name

        if hasattr(opts, 'translation_model'):
            master_table_name = opts.db_table
            translation_opts = opts.translation_model._meta
            trans_table_name = translation_opts.db_table
            for language_code in get_language_code_list():
                table_alias = get_translation_table_alias(trans_table_name,
                                                          language_code)
                trans_join = ("LEFT JOIN %s AS %s ON ((%s.master_id = %s.%s) AND (%s.language_code = '%s'))"
                           % (qn2(translation_opts.db_table),
                           qn2(table_alias),
                           qn2(table_alias),
                           qn(master_table_name),
                           qn2(opts.pk.column),
                           qn2(table_alias),
                           language_code))
                self.query.extra_join[table_alias] = trans_join
Exemple #3
0
def multilingual(request):
    """
    Returns context variables containing information about available languages.
    """
    return {
        'LANGUAGE_CODES': get_language_code_list(),
        'DEFAULT_LANGUAGE_CODE': get_default_language_code()
    }
def multilingual(request):
    """
    Returns context variables containing information about available languages.
    """
    codes = sorted(get_language_code_list())
    return {'LANGUAGE_CODES': codes,
            'LANGUAGE_CODES_AND_NAMES': [(c, LANG_DICT.get(c, c)) for c in codes], 
            'ADMIN_MEDIA_URL': '%s%s' % (settings.STATIC_URL, 'admin'),
            'DEFAULT_LANGUAGE_CODE': get_default_language_code()}
Exemple #5
0
def multilingual(request):
    """
    Returns context variables containing information about available languages.
    """
    codes = sorted(get_language_code_list())
    return {'LANGUAGE_CODES': codes,
            'LANGUAGE_CODES_AND_NAMES': [(c, LANG_DICT.get(c, c)) for c in codes], 
            'DEFAULT_LANGUAGE_CODE': get_default_language_code(),
            'ADMIN_MEDIA_URL': settings.ADMIN_MEDIA_PREFIX}
def reorder_translation_formset_by_language_code(inline_admin_form):
    """
    Shuffle the forms in the formset of multilingual model in the
    order of their language_ids.
    """
    lang_to_form = dict([(form.form.initial['language_id'], form)
                         for form in inline_admin_form])
    return [lang_to_form[language_code] for language_code in
        get_language_code_list()]
def reorder_translation_formset_by_language_code(inline_admin_form):
    """
    Shuffle the forms in the formset of multilingual model in the
    order of their language_ids.
    """
    lang_to_form = dict([(form.form.initial['language_id'], form)
                         for form in inline_admin_form])
    return [
        lang_to_form[language_code]
        for language_code in get_language_code_list()
    ]
Exemple #8
0
 def __init__(self, model, where=WhereNode):
     self.extra_join = {}
     self.include_translation_data = True
     extra_select = {}
     super(MultilingualQuery, self).__init__(model, where=where)
     opts = self.model._meta
     qn = self.get_compiler(DEFAULT_DB_ALIAS).quote_name_unless_alias
     qn2 = self.get_compiler(DEFAULT_DB_ALIAS).connection.ops.quote_name
     master_table_name = opts.db_table
     translation_opts = opts.translation_model._meta
     trans_table_name = translation_opts.db_table
     if hasattr(opts, 'translation_model'):
         master_table_name = opts.db_table
         for language_code in get_language_code_list():
             for fname in [f.attname for f in translation_opts.fields]:
                 table_alias = get_translation_table_alias(trans_table_name,
                     language_code)
                 field_alias = get_translated_field_alias(fname,
                     language_code)
                 extra_select[field_alias] = qn2(table_alias) + '.' + qn2(fname)
         self.add_extra(extra_select, None, None, None, None, None)
         self._trans_extra_select_count = len(self.extra_select)
Exemple #9
0
 def __init__(self, model, where=WhereNode):
     self.extra_join = {}
     self.include_translation_data = True
     extra_select = {}
     super(MultilingualQuery, self).__init__(model, where=where)
     opts = self.model._meta
     qn = self.get_compiler(DEFAULT_DB_ALIAS).quote_name_unless_alias
     qn2 = self.get_compiler(DEFAULT_DB_ALIAS).connection.ops.quote_name
     master_table_name = opts.db_table
     translation_opts = opts.translation_model._meta
     trans_table_name = translation_opts.db_table
     if hasattr(opts, 'translation_model'):
         master_table_name = opts.db_table
         for language_code in get_language_code_list():
             for fname in [f.attname for f in translation_opts.fields]:
                 table_alias = get_translation_table_alias(
                     trans_table_name, language_code)
                 field_alias = get_translated_field_alias(
                     fname, language_code)
                 extra_select[field_alias] = qn2(table_alias) + '.' + qn2(
                     fname)
         self.add_extra(extra_select, None, None, None, None, None)
         self._trans_extra_select_count = len(self.extra_select)
def multilingual(request):
    """
    Returns context variables containing information about available languages.
    """
    return {'LANGUAGE_CODES': get_language_code_list(),
            'DEFAULT_LANGUAGE_CODE': get_default_language_code()}