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


Python render_utils.make_context函数代码示例

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


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

示例1: delegates

def delegates(party):
    """
    Render the results card
    """

    context = make_context()

    ap_party = utils.PARTY_MAPPING[party]['AP']

    candidates = models.CandidateDelegates.select().where(
        models.CandidateDelegates.party == ap_party,
        models.CandidateDelegates.level == 'nation',
        models.CandidateDelegates.last << DELEGATE_WHITELIST[party],
        models.CandidateDelegates.delegates_count > 0
    ).order_by(
        -models.CandidateDelegates.delegates_count,
        models.CandidateDelegates.last
    )

    context['last_updated'] = utils.get_delegates_updated_time()

    context['candidates'] = candidates
    context['needed'] = list(candidates)[0].party_need
    context['party'] = ap_party

    context['party_class'] = utils.PARTY_MAPPING[party]['class']
    context['party_long'] = utils.PARTY_MAPPING[party]['adverb']

    context['slug'] = 'delegates-%s' % party
    context['template'] = 'delegates'
    context['route'] = '/delegates/%s/' % party

    context['refresh_rate'] = app_config.LOAD_DELEGATES_INTERVAL

    return render_template('cards/delegates.html', **context)
开发者ID:katlonsdorf,项目名称:elections16,代码行数:35,代码来源:__init__.py

示例2: index

def index():
    """
    Example view demonstrating rendering a simple HTML page.
    """
    context = make_context()

    return make_response(render_template('index.html', **context))
开发者ID:dailycal-projects,项目名称:public-trust,代码行数:7,代码来源:app.py

示例3: _graphics_child

def _graphics_child(slug):
    """
    Renders a child.html for embedding.
    """
    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()
    context['slug'] = slug
    context['COPY'] = copytext.Copy(filename='data/%s.xlsx' % slug)
    
    try:
        graphic_config = imp.load_source('graphic_config', '%s/graphic_config.py' % graphic_path)
        context.update(graphic_config.__dict__)
    except IOError:
        pass

    with open('%s/child_template.html' % graphic_path) as f:
        template = f.read().decode('utf-8')

    return render_template_string(template, **context)
开发者ID:EJHale,项目名称:dailygraphics,代码行数:27,代码来源:app.py

示例4: index

def index():
    """
    Render the admin index.
    """
    context = make_context()

    return render_template('index.html', **context)
开发者ID:nprapps,项目名称:musicgame,代码行数:7,代码来源:public_app.py

示例5: _word

def _word(slug):
    context = make_context()

    data = {}

    for file in glob('data/text/counts/*.json'):
        with open(file) as f:
            transcript_data = json.load(f)

            date = file.split('/')[3].split('.')[0]
            data[date] = {}

            reporter_words = transcript_data['reporters']['words']
            reporter_count = transcript_data['reporters']['count']
            secretary_words = transcript_data['secretary']['words']
            secretary_count = transcript_data['secretary']['count']

            data[date]['reporter_count'] = reporter_count
            data[date]['secretary_count'] = secretary_count

            for word in reporter_words:
                for k, v in word.iteritems():
                    if k == slug:
                        data[date]['reporter'] = v
                        break

            for word in secretary_words:
                for k, v in word.iteritems():
                    if k == slug:
                        data[date]['secretary'] = v
                        break

    context['data'] = data

    return make_response(render_template('word.html', **context))
开发者ID:nprapps,项目名称:wh-press-briefings,代码行数:35,代码来源:app.py

示例6: rematches

def rematches():
    """
    List of elections with candidates who have faced off before
    """
    context = make_context()

    return render_template('slides/rematches.html', **context)
开发者ID:nprapps,项目名称:elections14,代码行数:7,代码来源:slides.py

示例7: methodology

def methodology():
    """
    Methodology explainer page.
    """
    context = make_context()

    return render_template('methodology.html', **context)
开发者ID:strogo,项目名称:stl-lobbying,代码行数:7,代码来源:app.py

示例8: index

def index():
    """
    Example view rendering a simple page.
    """
    context = make_context(asset_depth=1)

    return render_template("index.html", **context)
开发者ID:vfulco,项目名称:pixelcite,代码行数:7,代码来源:public_app.py

示例9: index

def index():
    """
    Example view demonstrating rendering a simple HTML page.
    """
    context = make_context()

    # Nav needs to be a list of lists.
    # The inner list should only have four objects max.
    # Because of reasons.
    context['nav'] = []
    contents = list(context['COPY']['content'])
    not_yet_four = []

    for idx, row in enumerate(contents):
        row = dict(zip(row.__dict__['_columns'], row.__dict__['_row']))
        row_title = row.get('data_panel', None)

        if row_title:
            if row_title not in ['_', 'introduction', 'data_panel', 'about']:
                not_yet_four.append(row)

                if len(not_yet_four) == 4:
                    context['nav'].append(not_yet_four)
                    not_yet_four = []

        if (idx + 1) == len(contents):
            if len(not_yet_four) > 0:
                context['nav'].append(not_yet_four)

    return render_template('index.html', **context)
开发者ID:HobokenMartha,项目名称:borders-map,代码行数:30,代码来源:app.py

示例10: _story

def _story(slug):
    context = make_context()

    context['story'] = list(context['COPY'][slug])
    context['slug'] = slug

    return render_template('story.html', **context)
开发者ID:TylerFisher,项目名称:mag,代码行数:7,代码来源:app.py

示例11: _stack

def _stack():
    """
    Administer a stack of slides.
    """
    context = make_context(asset_depth=1)

    sequence = SlideSequence.select()
    sequence_dicts = sequence.dicts()

    time = 0

    for slide in sequence:
        time += slide.slide.time_on_screen

    for slide_dict in sequence_dicts:
        for slide in sequence:
            if slide.slide.slug == slide_dict['slide']:
                slide_dict['name'] = slide.slide.name
                slide_dict['time_on_screen'] = slide.slide.time_on_screen

                if slide_dict['slide'].startswith('tumblr'):
                    slide_dict['news_item'] = True

    context.update({
        'sequence': sequence_dicts,
        'slides': Slide.select().dicts(),
        'graphics': Slide.select().where(fn.Lower(fn.Substr(Slide.slug, 1, 6)) != 'tumblr').order_by(Slide.slug).dicts(),
        'news':  Slide.select().where(fn.Lower(fn.Substr(Slide.slug, 1, 6)) == 'tumblr').order_by(Slide.slug.desc()).dicts(),
        'time': time,
    })

    return render_template('admin/stack.html', **context)
开发者ID:nprapps,项目名称:elections14,代码行数:32,代码来源:admin_app.py

示例12: _episode_detail

def _episode_detail(episode_code):
    context = make_context()
    context['episode'] = Episode.get(Episode.code == episode_code)
    context['jokes'] = {}
    context['joke_count'] = 0

    for joke in EpisodeJoke.select().where(EpisodeJoke.episode == context['episode']):
        group = joke.joke.primary_character

        if group not in app_config.PRIMARY_CHARACTER_LIST:
            group = 'Miscellaneous'

        if group not in context['jokes']:
            context['jokes'][group] = []

        context['jokes'][group].append(joke)
        context['joke_count'] += 1

    context['seasons'] = _all_seasons()

    context['group_order'] = [g for g in app_config.PRIMARY_CHARACTER_LIST if g in context['jokes']]

    try:
        context['next'] = Episode.get(number=context['episode'].number + 1)
    except Episode.DoesNotExist:
        context['next'] = None
    try:
        context['prev'] = Episode.get(number=context['episode'].number - 1)
    except Episode.DoesNotExist:
        context['prev'] = None

    return render_template('episode_detail.html', **context)
开发者ID:nprapps,项目名称:arrested-development,代码行数:32,代码来源:app.py

示例13: index

def index():
    """
    Example view rendering a simple page.
    """
    context = make_context(asset_depth=1)

    return make_response(render_template('index.html', **context))
开发者ID:katlonsdorf,项目名称:elections16,代码行数:7,代码来源:__init__.py

示例14: preview

def preview(path):
    context = make_context()
    path_parts = path.split('/')
    slug = path_parts[0]
    args = path_parts[1:]
    context['content'] = app.view_functions[slug](*args)
    return make_response(render_template('index.html', **context))
开发者ID:katlonsdorf,项目名称:elections16,代码行数:7,代码来源:__init__.py

示例15: obama_reps

def obama_reps():
    """
    Ongoing list of Incumbent Republicans In Districts Barack Obama Won In 2012
    """
    from models import Race

    races = Race.select().where(Race.obama_gop == True).order_by(Race.state_postal, Race.seat_number)
    timestamp = get_last_updated(races)

    context = make_context(timestamp=timestamp)

    won = [race for race in races if race.is_called() and not race.is_runoff() and not race.party_changed()]
    lost = [race for race in races if race.is_called() and not race.is_runoff() and race.party_changed()]
    not_called = [race for race in races if not race.is_called() or race.is_runoff()]

    context['races_won'] = columnize_card(won)
    context['races_lost'] = columnize_card(lost)
    context['races_not_called'] = columnize_card(not_called)

    context['races_won_count'] = len(won)
    context['races_lost_count'] = len(lost)
    context['races_not_called_count'] = len(not_called)
    context['races_count'] = races.count()

    return render_template('slides/obama-reps.html', **context)
开发者ID:nprapps,项目名称:elections14,代码行数:25,代码来源:slides.py


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