Python flask_sqlalchemy.BaseQuery() Examples

The following are 6 code examples for showing how to use flask_sqlalchemy.BaseQuery(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module flask_sqlalchemy , or try the search function .

Example 1
Project: timesketch   Author: google   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def get_with_acl(self, model_id, user=current_user):
        """Get a database object with permission check enforced.

        Args:
            model_id: The integer ID of the model to get.
            user: User (instance of timesketch.models.user.User)

        Returns:
            A BaseQuery instance.
        """
        result_obj = self.get(model_id)
        if not result_obj:
            abort(HTTP_STATUS_CODE_NOT_FOUND)
        try:
            if result_obj.get_status.status == 'deleted':
                abort(HTTP_STATUS_CODE_NOT_FOUND)
        except AttributeError:
            pass
        if result_obj.is_public:
            return result_obj
        if not result_obj.has_permission(user=user, permission='read'):
            abort(HTTP_STATUS_CODE_FORBIDDEN)
        return result_obj 
Example 2
Project: flask-restplus-server-example   Author: frol   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_query_class(cls):
        """
        Returns extended BaseQuery class for flask_sqlalchemy model to provide get_or_403 method

        Example:
        >>> DataTransformation(db.Model):
        ...     query_class = OwnerRolePermission.get_query_class()
        """
        return lambda *args, **kwargs: PermissionExtendedQuery(cls, *args, **kwargs) 
Example 3
Project: c3bottles   Author: c3bottles   File: test_drop_point.py    License: MIT License 5 votes vote down vote up
def test_reports_are_query(self):
        assert isinstance(self.dp.reports, BaseQuery) 
Example 4
Project: c3bottles   Author: c3bottles   File: test_drop_point.py    License: MIT License 5 votes vote down vote up
def test_visits_are_query(self):
        assert isinstance(self.dp.visits, BaseQuery) 
Example 5
Project: incubator-superset   Author: apache   File: sql_lab.py    License: Apache License 2.0 5 votes vote down vote up
def apply(self, query: BaseQuery, value: Any) -> BaseQuery:
        """
        Filter queries to only those owned by current user. If
        can_access_all_queries permission is set a user can list all queries

        :returns: query
        """
        if not security_manager.can_access_all_queries():
            query = query.filter(Query.user_id == g.user.get_user_id())
        return query 
Example 6
Project: incubator-superset   Author: apache   File: filters.py    License: Apache License 2.0 5 votes vote down vote up
def apply(self, query: BaseQuery, value: Any) -> BaseQuery:
        """
        Filter queries to only those owned by current user. If
        can_access_all_queries permission is set a user can list all queries

        :returns: query
        """
        if not security_manager.can_access_all_queries():
            query = query.filter(Query.user_id == g.user.get_user_id())
        return query