当前位置: 首页>>代码示例>>Python>>正文


Python render_utils.load_graphic_config函数代码示例

本文整理汇总了Python中render_utils.load_graphic_config函数的典型用法代码示例。如果您正苦于以下问题:Python load_graphic_config函数的具体用法?Python load_graphic_config怎么用?Python load_graphic_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了load_graphic_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _templates_detail

def _templates_detail(slug):
    """
    Renders a parent.html index with child.html embedded as iframe.
    """
    from flask import request

    template_path = '%s/%s' % (app_config.TEMPLATES_PATH, slug)
    base_template_path = '%s/%s' % (app_config.TEMPLATES_PATH, '_base')

    # NOTE: Parent must load pym.js from same source as child to prevent version conflicts!
    context = make_context(asset_depth=2, root_path=template_path)
    context['slug'] = slug

    try:
        graphic_config = load_graphic_config(template_path, [base_template_path])
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (template_path, slug)

            if request.args.get('refresh'):
                oauth.get_document(graphic_config.COPY_GOOGLE_DOC_KEY, copy_path)

            context['COPY'] = copytext.Copy(filename=copy_path)
    except IOError:
        pass

    return make_response(render_template('parent.html', **context))
开发者ID:ThomasThoren,项目名称:dailygraphics,代码行数:28,代码来源:graphic_templates.py

示例2: _graphics_detail

def _graphics_detail(slug):
    """
    Renders a parent.html index with child.html embedded as iframe.
    """
    from flask import request

    graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)

    # NOTE: Parent must load pym.js from same source as child to prevent
    # version conflicts!
    context = make_context(asset_depth=2, root_path=graphic_path)
    context['slug'] = slug
    context['type'] = 'graphics'  # From previous commit
    context['var_name'] = slug.replace('-', '_')

    template = 'parent.html'

    if not os.path.exists('%s/%s/js/lib/pym.js' % (app_config.GRAPHICS_PATH, slug)):
        template = 'parent_old.html'

    try:
        graphic_config = load_graphic_config(graphic_path)
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (graphic_path, slug)

            if request.args.get('refresh'):
                oauth.get_document(graphic_config.COPY_GOOGLE_DOC_KEY, copy_path)

            context['COPY'] = copytext.Copy(filename=copy_path)
    except IOError:
        pass

    return make_response(render_template(template, **context))
开发者ID:TheLens,项目名称:dailygraphics,代码行数:35,代码来源:graphic.py

示例3: _graphics_child

def _graphics_child(slug):
    """
    Renders a child.html for embedding.
    """
    from flask import g
    alt_path = getattr(g, 'alt_path', None)
    if alt_path:
        graphic_path = alt_path
    else:
        graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)

    # Fallback for legacy projects w/o child templates
    if not os.path.exists('%s/child_template.html' % graphic_path):
        with open('%s/child.html' % graphic_path) as f:
            contents = f.read()

        return contents

    context = make_context(asset_depth=2, root_path=graphic_path)
    context['slug'] = slug
    context['var_name'] = slug.replace('-', '_')

    env = Environment(loader=FileSystemLoader(graphic_path))

    try:
        graphic_config = load_graphic_config(graphic_path)
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'JINJA_FILTER_FUNCTIONS'):
            for func in graphic_config.JINJA_FILTER_FUNCTIONS:
                env.filters[func.__name__] = func

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (graphic_path, slug)

            # Trim strings to avoid whitespace issues
            copy = copytext.Copy(filename=copy_path)
            for sheet in copy._copy:
                worksheet = copy[sheet]
                for row in worksheet:
                    stripped = []
                    for item in row._row:
                        if isinstance(item, str) or isinstance(item, unicode):
                            stripped.append(item.strip())
                        else:
                            stripped.append(item)
                    row._row = stripped

            context['COPY'] = copy
    except IOError:
        pass

    env.globals.update(render=render_with_context)
    env.filters['smarty'] = smarty_filter
    template = env.get_template('child_template.html')

    return make_response(template.render(**context))
开发者ID:nprapps,项目名称:dailygraphics,代码行数:57,代码来源:graphic.py

示例4: deploy

def deploy(slug):
    """
    Deploy the latest app to S3 and, if configured, to our servers.
    """
    require('settings', provided_by=[production, staging])

    if not slug:
        print 'You must specify a project slug, like this: "deploy:slug"'
        return

    graphic_root = '%s/%s' % (app_config.GRAPHICS_PATH, slug)
    s3_root = '%s/graphics/%s' % (app_config.PROJECT_SLUG, slug)
    graphic_assets = '%s/assets' % graphic_root
    s3_assets = '%s/assets' % s3_root

    graphic_config = load_graphic_config(graphic_root)

    use_assets = getattr(graphic_config, 'USE_ASSETS', True)
    default_max_age = getattr(graphic_config, 'DEFAULT_MAX_AGE', None) or app_config.DEFAULT_MAX_AGE
    assets_max_age = getattr(graphic_config, 'ASSETS_MAX_AGE', None) or app_config.ASSETS_MAX_AGE

    update_copy(slug)

    if use_assets:
        assets.sync(slug)

    render.render(slug)

    flat.deploy_folder(
        graphic_root,
        s3_root,
        headers={
            'Cache-Control': 'max-age=%i' % default_max_age
        },
        ignore=['%s/*' % graphic_assets]
    )

    # Deploy parent assets
    flat.deploy_folder(
        'www',
        app_config.PROJECT_SLUG,
        headers={
            'Cache-Control': 'max-age=%i' % default_max_age
        }
    )

    if use_assets:
        flat.deploy_folder(
            graphic_assets,
            s3_assets,
            headers={
                'Cache-Control': 'max-age=%i' % assets_max_age
            }
        )

    print ''
    print '%s URL: %s/graphics/%s/' % (env.settings.capitalize(), app_config.S3_BASE_URL, slug)
开发者ID:azizjiwani,项目名称:dailygraphics,代码行数:57,代码来源:__init__.py

示例5: _templates_detail

def _templates_detail(slug):
    """
    Renders a parent.html index with child.html embedded as iframe.
    """
    from flask import request

    template_path = '%s/%s' % (app_config.TEMPLATES_PATH, slug)
    base_template_path = '%s/%s' % (app_config.TEMPLATES_PATH, '_base')

    # NOTE: Parent must load pym.js from same source as child to prevent version conflicts!
    context = make_context(asset_depth=2, root_path=template_path)
    context['slug'] = slug

    try:
        graphic_config = load_graphic_config(template_path, [base_template_path])
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (template_path, slug)

            if request.args.get('refresh'):
                oauth.get_document(graphic_config.COPY_GOOGLE_DOC_KEY, copy_path)

            context['COPY'] = copytext.Copy(filename=copy_path)

        if hasattr(graphic_config, 'AIRTABLE_ENDPOINTS') and graphic_config.AIRTABLE_ENDPOINTS and request.args.get('refresh'):
            for airtable_endpoint in graphic_config.AIRTABLE_ENDPOINTS:
                copy_path = '%s/%s.json' % (template_path, airtable_endpoint['name'])

                results = []
                url = airtable_endpoint['url']

                print 'downloading %s' % airtable_endpoint['name']

                while True:
                    response = requests.get(url)
                    response.raise_for_status()

                    data = json.loads(response.text)

                    results = results + data['records']

                    if 'offset' in data:
                        offset = data['offset']
                        url = '%s&offset=%s' % (airtable_endpoint['url'], offset)
                    else:
                        break

                print '%s records found' % len(results)

                with open(copy_path, 'w+') as outfile:
                    json.dump(results, outfile)

    except IOError:
        pass

    return make_response(render_template('parent.html', **context))
开发者ID:joshuarrrr,项目名称:dailygraphics,代码行数:57,代码来源:graphic_templates.py

示例6: _graphics_child

def _graphics_child(slug):
    """
    Renders a child.html for embedding.
    """
    graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)
    print graphic_path

    # Fallback for legacy projects w/o child templates
    if not os.path.exists('%s/child_template.html' % graphic_path):
        with open('%s/child.html' % graphic_path) as f:
            contents = f.read()

        return contents

    context = make_context(asset_depth=2, root_path=graphic_path)
    context['slug'] = slug
    context['var_name'] = slug.replace('-', '_')

    env = Environment(loader=FileSystemLoader(graphic_path))

    try:
        graphic_config = load_graphic_config(graphic_path)
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'JINJA_FILTER_FUNCTIONS'):
            for func in graphic_config.JINJA_FILTER_FUNCTIONS:
                env.filters[func.__name__] = func

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (graphic_path, slug)

            context['COPY'] = copytext.Copy(filename=copy_path)

        if hasattr(graphic_config, 'AIRTABLE_ENDPOINTS') and graphic_config.AIRTABLE_ENDPOINTS:
            context['AIRTABLE_DATA'] = []

            results = []
            for airtable_endpoint in graphic_config.AIRTABLE_ENDPOINTS:
                copy_path = '%s/%s.json' % (graphic_path, airtable_endpoint['name'])

                with open(copy_path) as infile:
                    results = infile.read()

                context['AIRTABLE_DATA'].append({
                        'name': airtable_endpoint['name'],
                        'data': results
                    })
    except IOError:
        pass

    env.globals.update(render=render_with_context)
    env.filters['smarty'] = smarty_filter
    template = env.get_template('child_template.html')

    return make_response(template.render(**context))
开发者ID:joshuarrrr,项目名称:dailygraphics,代码行数:55,代码来源:graphic.py

示例7: deploy_single

def deploy_single(path):
    """
    Deploy a single project to S3 and, if configured, to our servers.
    """
    require('settings', provided_by=[production, staging])
    slug, abspath = utils.parse_path(path)
    graphic_root = '%s/%s' % (abspath, slug)
    s3_root = '%s/graphics/%s' % (app_config.PROJECT_SLUG, slug)
    graphic_assets = '%s/assets' % graphic_root
    s3_assets = '%s/assets' % s3_root
    graphic_node_modules = '%s/node_modules' % graphic_root

    graphic_config = load_graphic_config(graphic_root)

    use_assets = getattr(graphic_config, 'USE_ASSETS', True)
    default_max_age = getattr(graphic_config, 'DEFAULT_MAX_AGE', None) or app_config.DEFAULT_MAX_AGE
    assets_max_age = getattr(graphic_config, 'ASSETS_MAX_AGE', None) or app_config.ASSETS_MAX_AGE
    update_copy(path)
    if use_assets:
        error = assets.sync(path)
        if error:
            return

    render.render(path)
    flat.deploy_folder(
        graphic_root,
        s3_root,
        headers={
            'Cache-Control': 'max-age=%i' % default_max_age
        },
        ignore=['%s/*' % graphic_assets, '%s/*' % graphic_node_modules,
                # Ignore files unused on static S3 server
                '*.xls', '*.xlsx', '*.pyc', '*.py', '*.less', '*.bak',
                '%s/base_template.html' % graphic_root,
                '%s/child_template.html' % graphic_root,
                '%s/README.md' % graphic_root]
    )

    if use_assets:
        flat.deploy_folder(
            graphic_assets,
            s3_assets,
            headers={
                'Cache-Control': 'max-age=%i' % assets_max_age
            },
            ignore=['%s/private/*' % graphic_assets]
        )

    # Need to explicitly point to index.html for the AWS staging link
    file_suffix = ''
    if env.settings == 'staging':
        file_suffix = 'index.html'

    print ''
    print '%s URL: %s/graphics/%s/%s' % (env.settings.capitalize(), app_config.S3_BASE_URL, slug, file_suffix)
开发者ID:stlpublicradio,项目名称:dailygraphics,代码行数:55,代码来源:__init__.py

示例8: download_copy

def download_copy(slug):
    """
    Downloads cloud data.
    """
    graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)
    try:
        graphic_config = load_graphic_config(graphic_path)
    except (ImportError, IOError):
        print '%s/graphic_config.py does not exist.' % slug
        return

    download_google_sheet(slug, graphic_config)
    download_airtable_sheets(slug, graphic_config)
开发者ID:joshuarrrr,项目名称:dailygraphics,代码行数:13,代码来源:__init__.py

示例9: _templates_child

def _templates_child(slug):
    """
    Renders a child.html for embedding.
    """
    template_path = '%s/%s' % (app_config.TEMPLATES_PATH, slug)
    base_template_path = '%s/%s' % (app_config.TEMPLATES_PATH, '_base')

    # Fallback for legacy projects w/o child templates
    if not os.path.exists('%s/child_template.html' % template_path):
        with open('%s/child.html' % template_path) as f:
            contents = f.read()

        return contents

    context = make_context(asset_depth=2, root_path=template_path)
    context['slug'] = slug

    env = Environment(loader=FileSystemLoader([
        template_path,
        '%s/_base' % app_config.TEMPLATES_PATH])
    )

    try:
        graphic_config = load_graphic_config(
            template_path, [base_template_path])
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'JINJA_FILTER_FUNCTIONS'):
            for func in graphic_config.JINJA_FILTER_FUNCTIONS:
                env.filters[func.__name__] = func

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (template_path, slug)

            context['COPY'] = copytext.Copy(filename=copy_path)
    except IOError:
        pass

    env.globals.update(render=render_with_context)
    env.filters['smarty'] = smarty_filter
    template = env.get_template('child_template.html')

    # Save for uploading to S3.
    html = template.render(**context)
    with open('%s/child.html' % template_path, "w") as filename:
        html = html.replace('.less', '.css')
        filename.write(html)

    return make_response(template.render(**context))
开发者ID:TheLens,项目名称:dailygraphics,代码行数:49,代码来源:graphic_templates.py

示例10: _graphics_detail

def _graphics_detail(slug):
    """
    Renders a parent.html index with child.html embedded as iframe.
    """
    from flask import request, g

    alt_path = getattr(g, 'alt_path', None)
    if alt_path:
        graphic_path = alt_path
    else:
        graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)

    # NOTE: Parent must load pym.js from same source as child to prevent version conflicts!
    context = make_context(asset_depth=2, root_path=graphic_path)
    context['slug'] = slug
    context['var_name'] = slug.replace('-', '_')

    # Use local_pym for legacy graphics
    local_pym = getattr(g, 'local_pym', None)
    context['LOCAL_PYM'] = local_pym
    # warning message
    custom_location = getattr(g, 'custom_location', None)
    context['CUSTOM_LOCATION'] = custom_location

    template = 'parent.html'

    try:
        graphic_config = load_graphic_config(graphic_path)
        context.update(graphic_config.__dict__)

        if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY:
            copy_path = '%s/%s.xlsx' % (graphic_path, slug)

            if request.args.get('refresh'):
                oauth.get_document(graphic_config.COPY_GOOGLE_DOC_KEY, copy_path)

            context['COPY'] = copytext.Copy(filename=copy_path)
    except IOError:
        pass

    try:
        env = Environment(loader=FileSystemLoader(graphic_path))
        template = env.get_template('parent.html')
        return make_response(template.render(**context))
    except TemplateNotFound:
        return make_response(render_template(template, **context))
开发者ID:nprapps,项目名称:dailygraphics,代码行数:46,代码来源:graphic.py

示例11: copy_spreadsheet

def copy_spreadsheet(slug):
    """
    Copy the COPY spreadsheet
    """
    _check_credentials()

    config_path = '%s/%s/' % (app_config.GRAPHICS_PATH, slug)
    graphic_config = load_graphic_config(config_path)

    if not hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') or not graphic_config.COPY_GOOGLE_DOC_KEY:
        print 'Skipping spreadsheet creation. (COPY_GOOGLE_DOC_KEY is not defined in %s/graphic_config.py.)' % slug
        return

    metadata = {'title': '%s GRAPHIC COPY' % slug}
    try:
        if app_config.DRIVE_SPREADSHEETS_FOLDER:
            metadata['parents'] = [{
                'id': app_config.DRIVE_SPREADSHEETS_FOLDER}]
    except AttributeError:
        pass

    kwargs = {
        'credentials': get_credentials(),
        'url': SPREADSHEET_COPY_URL_TEMPLATE % graphic_config.COPY_GOOGLE_DOC_KEY,
        'method': 'POST',
        'headers': {'Content-Type': 'application/json'},
        'body': json.dumps(metadata),
    }

    resp = app_config.authomatic.access(**kwargs)

    if resp.status == 200:
        spreadsheet_key = resp.data['id']
        spreadsheet_url = SPREADSHEET_VIEW_TEMPLATE % spreadsheet_key
        print 'New spreadsheet created successfully!'
        print 'View it online at %s' % spreadsheet_url
        utils.replace_in_file('%s/graphic_config.py' % config_path , graphic_config.COPY_GOOGLE_DOC_KEY, spreadsheet_key)

        return True
    else:
        utils.replace_in_file('%s/graphic_config.py' % config_path, graphic_config.COPY_GOOGLE_DOC_KEY, '')
    print 'Error creating spreadsheet (status code %s) with message %s' % (resp.status, resp.reason)
    if resp.status == 404:
        print 'Please make sure you modify the DRIVE_SPREADSHEETS_FOLDER in app_config.py. Check the configuration section on the README.'
    return False
开发者ID:stlpublicradio,项目名称:dailygraphics,代码行数:45,代码来源:__init__.py

示例12: open_spreadsheet

def open_spreadsheet(slug):
    """
    Open the spreadsheet associated with a given slug
    """

    config_path, _ = _search_graphic_slug(slug)
    try:
        graphic_config = load_graphic_config(config_path)
    except ImportError:
        print 'graphic_config.py not found for %s on graphics or graphics-archive repos' % slug
        return

    if not hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') or not graphic_config.COPY_GOOGLE_DOC_KEY:
        print 'There seems to be no spreadsheet linked to that slug. (COPY_GOOGLE_DOC_KEY is not defined in %s/graphic_config.py.)' % slug
        return

    spreadsheet_url = SPREADSHEET_VIEW_TEMPLATE % graphic_config.COPY_GOOGLE_DOC_KEY
    webbrowser.open_new(spreadsheet_url)
开发者ID:markm92198,项目名称:dailygraphics,代码行数:18,代码来源:__init__.py

示例13: download_copy

def download_copy(slug):
    """
    Downloads a Google Doc as an .xlsx file.
    """
    graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)

    try:
        graphic_config = load_graphic_config(graphic_path)
    except IOError:
        print '%s/graphic_config.py does not exist.' % slug
        return

    if not hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') or not graphic_config.COPY_GOOGLE_DOC_KEY:
        print 'COPY_GOOGLE_DOC_KEY is not defined in %s/graphic_config.py.' % slug
        return

    copy_path = os.path.join(graphic_path, '%s.xlsx' % slug)
    get_document(graphic_config.COPY_GOOGLE_DOC_KEY, copy_path)
开发者ID:markm92198,项目名称:dailygraphics,代码行数:18,代码来源:__init__.py

示例14: deploy_to_production

def deploy_to_production(slug):
    require('settings', provided_by=[production, staging])

    graphic_root = '%s/%s' % (app_config.GRAPHICS_PATH, slug)
    graphic_assets = '%s/assets' % graphic_root
    graphic_config = load_graphic_config(graphic_root)
    default_max_age = getattr(graphic_config, 'DEFAULT_MAX_AGE', None) or app_config.DEFAULT_MAX_AGE

    flat.deploy_folder(
        graphic_root,
        slug,
        headers={
            'Cache-Control': 'max-age=%i' % default_max_age
        },
        ignore=['%s/*' % graphic_assets]
    )

    write_meta_json(slug, 'deploy')
开发者ID:abcnews,项目名称:dailygraphics,代码行数:18,代码来源:__init__.py

示例15: decorated_function

    def decorated_function(*args, **kwargs):
        from flask import request

        if request.path.startswith('/graphics/'):
            slug = request.path.split('/')[-2]
            graphic_path = '%s/%s' % (app_config.GRAPHICS_PATH, slug)

            try:
                graphic_config = load_graphic_config(graphic_path)
            except IOError:
                return f(*args, **kwargs)

            credentials = get_credentials()

            if hasattr(graphic_config, 'COPY_GOOGLE_DOC_KEY') and graphic_config.COPY_GOOGLE_DOC_KEY and (not credentials or not credentials.valid):
                return redirect(url_for('_oauth.oauth_alert'))

        return f(*args, **kwargs)
开发者ID:blakebutcher,项目名称:dailygraphics,代码行数:18,代码来源:oauth.py


注:本文中的render_utils.load_graphic_config函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。