Example #1
0
def render_index():
    if settings.MULTI_ORG:
        # base_href ,项目的完整根路径
        # base_href = url_for('redash.index', _external=True), _external显示完整路径

        # app = Flask(__name__, template_folder='./'), 在app创建的,指定项目template的目录,也就是multi_org.html的位置
        response = render_template("multi_org.html", base_href=base_href())

        # base标签

        # 我们设置base标签,给一个基准href,那么其他的链接都是以此为基准

        # < base href = "{{base_href}}" >

    else:
        #  path =  directory + filename
        #  文件路径 =  目录 + 文件名
        # safe_join , 目录和文件名,合成文件的绝对路径
        full_path = safe_join(settings.STATIC_ASSETS_PATH, 'index.html')

        response = send_file(full_path,
                             **dict(cache_timeout=0, conditional=True))

        # response = send_file(full_path, **dict(cache_timeout=0, conditional=True)), 直接渲染文件的内容到页面里.
        # (为什么不用reader_template),(可能不受template设置的项目路径的影响)

        # response = send_file(full_path, as_attachment=True) 添加as_attachment=True的话, 将作为附件下载

    return response
Example #2
0
def render_index():
    if settings.MULTI_ORG:
        response = render_template("multi_org.html", base_href=base_href())
    else:
        full_path = safe_join(settings.STATIC_ASSETS_PATHS[-2], 'index.html')
        response = send_file(full_path, **dict(cache_timeout=0, conditional=True))

    return response
Example #3
0
def render_index():
    if settings.MULTI_ORG:
        response = render_template("multi_org.html", base_href=base_href())
    else:
        full_path = safe_join(settings.STATIC_ASSETS_PATH, 'index.html')
        response = send_file(full_path, **dict(cache_timeout=0, conditional=True))

    return response
Example #4
0
def render_index(access_token=None):
    access_token = "undefined" if access_token is None else access_token
    if settings.MULTI_ORG:
        response = render_template("multi_org.html", base_href=base_href(), access_token=access_token)
    else:
        ## TODO: maybe do it gracefully
        template_path = safe_join(settings.STATIC_ASSETS_PATH, "index.html")
        full_path = safe_join(settings.STATIC_ASSETS_PATH, "index_embed.html")
        with open(template_path, "r") as f1, open(full_path, "w") as f2:
            content = f1.read()
            template = content.replace("{{access_token}}", access_token)
            f2.write(template)
        response = send_file(full_path, **dict(cache_timeout=0, conditional=True))

    return response
Example #5
0
    def post(self, query_id):
        # Iodide does not have an access control system and it certainly does not
        # share access control settings with Redash. When the "Explore in Iodide"
        # button is pressed, the data from that query is made available to all
        # Iodide users.
        #
        # Therefore, we should only process the request if the "default" group
        # in Redash has access to the query.
        groups = get_object_or_404(Query.all_groups_for_query_ids, query_id)
        default_group = Group.query.filter(Group.name == "default").first()
        if default_group is None or default_group.id not in [
                g[0] for g in groups
        ]:
            return {
                "message":
                "Couldn't find resource. Please login and try again."
            }

        query = get_object_or_404(Query.get_by_id_and_org, query_id,
                                  self.current_org)

        with open(self.TEMPLATE_PATH, "r") as template:
            source = template.read()
            context = {
                "redash_url": base_href(),
                "query_id": query_id,
                "title": query.name,
                "api_key": query.api_key,
            }
            rendered_template = render_template_string(source, **context)
        headers = {"Authorization": "Token %s" % settings.IODIDE_AUTH_TOKEN}
        data = {
            "owner": self.current_user.email,
            "title": query.name,
            "content": rendered_template,
        }
        response = requests.post(settings.IODIDE_NOTEBOOK_API_URL,
                                 headers=headers,
                                 data=data)
        return response.json()
Example #6
0
    def post(self, query_id):
        query = get_object_or_404(Query.get_by_id_and_org, query_id, self.current_org)

        with open(self.TEMPLATE_PATH, "r") as template:
            source = template.read()
            context = {
                "redash_url": base_href(),
                "query_id": query_id,
                "title": query.name,
                "api_key": query.api_key,
            }
            rendered_template = render_template_string(source, **context)
        headers = {"Authorization": "Token %s" % settings.IODIDE_AUTH_TOKEN}
        data = {
            "owner": self.current_user.email,
            "title": query.name,
            "content": rendered_template,
        }
        response = requests.post(
            settings.IODIDE_NOTEBOOK_API_URL, headers=headers, data=data
        )
        return response.json()