def reorder_translation_formset_by_language_id(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_id] for language_id in get_language_id_list()]
def pre_sql_setup(self): """Adds the JOINS and SELECTS for fetching multilingual data. """ super(MultilingualQuery, self).pre_sql_setup() if not self.include_translation_data: return opts = self.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_id in get_language_id_list(): table_alias = get_translation_table_alias(trans_table_name, language_id) trans_join = ('LEFT JOIN %s AS %s ON ((%s.master_id = %s.%s) AND (%s.language_id = %s))' % (qn2(translation_opts.db_table), qn2(table_alias), qn2(table_alias), qn(master_table_name), qn2(self.model._meta.pk.column), qn2(table_alias), language_id)) self.extra_join[table_alias] = trans_join
def pre_sql_setup(self): """Adds the JOINS and SELECTS for fetching multilingual data. """ super(MultilingualQuery, self).pre_sql_setup() if not self.include_translation_data: return opts = self.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_id in get_language_id_list(): table_alias = get_translation_table_alias( trans_table_name, language_id) trans_join = ( 'LEFT JOIN %s AS %s ON ((%s.master_id = %s.%s) AND (%s.language_id = %s))' % (qn2(translation_opts.db_table), qn2(table_alias), qn2(table_alias), qn(master_table_name), qn2(self.model._meta.pk.column), qn2(table_alias), language_id)) self.extra_join[table_alias] = trans_join
def reorder_translation_formset_by_language_id(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_id] for language_id in get_language_id_list()]
def __init__(self, model, connection, where=WhereNode): self.extra_join = {} extra_select = {} super(MultilingualQuery, self).__init__(model, connection, where=where) opts = self.model._meta qn = self.quote_name_unless_alias qn2 = self.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_id in get_language_id_list(): for fname in [f.attname for f in translation_opts.fields]: table_alias = get_translation_table_alias(trans_table_name, language_id) field_alias = get_translated_field_alias(fname, language_id) extra_select[field_alias] = qn2(table_alias) + '.' + qn2(fname) self.add_extra(extra_select, None,None,None,None,None)
def __init__(self, model, connection, where=WhereNode): self.extra_join = {} self.include_translation_data = True extra_select = {} super(MultilingualQuery, self).__init__(model, connection, where=where) opts = self.model._meta qn = self.quote_name_unless_alias qn2 = self.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_id in get_language_id_list(): for fname in [f.attname for f in translation_opts.fields]: table_alias = get_translation_table_alias( trans_table_name, language_id) field_alias = get_translated_field_alias( fname, language_id) 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)