sqlalchemy_utils.functions.get_primary_keys.values

Here are the examples of the python api sqlalchemy_utils.functions.get_primary_keys.values taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: sqlalchemy-i18n Source File: builders.py
    def assign_single_translations(self):
        mapper = sa.orm.class_mapper(self.parent_cls)
        for locale in option(self.parent_cls, 'locales'):
            key = '_translation_%s' % locale
            if mapper.has_property(key):
                continue

            conditions = self.primary_key_conditions
            conditions.append(self.translation_cls.locale == locale)
            mapper.add_property(key, sa.orm.relationship(
                self.translation_cls,
                primaryjoin=sa.and_(*conditions),
                foreign_keys=list(
                    get_primary_keys(self.parent_cls).values()
                ),
                uselist=False,
                viewonly=True
            ))

Example 2

Project: sqlalchemy-i18n Source File: builders.py
    def assign_fallback_translation(self):
        """
        Assign the current translation relationship for translatable parent
        class.
        """
        mapper = sa.orm.class_mapper(self.parent_cls)
        if not mapper.has_property('_fallback_translation'):
            conditions = self.primary_key_conditions
            conditions.append(
                self.translation_cls.locale ==
                get_fallback_locale(self.parent_cls)
            )

            mapper.add_property('_fallback_translation', sa.orm.relationship(
                self.translation_cls,
                primaryjoin=sa.and_(*conditions),
                foreign_keys=list(
                    get_primary_keys(self.parent_cls).values()
                ),
                viewonly=True,
                uselist=False
            ))

Example 3

Project: sqlalchemy-i18n Source File: builders.py
    def assign_current_translation(self):
        """
        Assign the current translation relationship for translatable parent
        class.
        """
        mapper = sa.orm.class_mapper(self.parent_cls)
        if not mapper.has_property('_current_translation'):
            conditions = self.primary_key_conditions
            conditions.append(
                self.translation_cls.locale == current_locale()
            )

            mapper.add_property('_current_translation', sa.orm.relationship(
                self.translation_cls,
                primaryjoin=sa.and_(*conditions),
                foreign_keys=list(
                    get_primary_keys(self.parent_cls).values()
                ),
                viewonly=True,
                uselist=False
            ))