def filter_query_by_project(q, project_safe, context):
    """Filters a query to the context's project

    Returns the updated query,  Adds filter to limit project to the
    context's project for non-admin users.  For admin users,
    the query is returned unmodified.

    :param query: query to apply filters to
    :param project_safe: boolean indicating if project restriction filter
                         should be applied
    :param context: context of the query

    """

    if project_safe and not context.is_admin:
        return q.filter_by(project=context.project_id)

    return q