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


Python State.update方法代码示例

本文整理汇总了Python中models.State.update方法的典型用法代码示例。如果您正苦于以下问题:Python State.update方法的具体用法?Python State.update怎么用?Python State.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.State的用法示例。


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

示例1: wipe_status

# 需要导入模块: from models import State [as 别名]
# 或者: from models.State import update [as 别名]
def wipe_status():
    """
    Blanks the status fields for congress and presidential races.
    """

    rq = Race.update(
        precincts_reporting=0,
        ap_called=False,
        ap_called_time=None,
        npr_called=False,
        npr_called_time=None
    )
    rq.execute()

    cq = Candidate.update(
        vote_count=0,
        ap_winner=False,
        npr_winner=False
    )
    cq.execute()

    sq = State.update(
        ap_call='u',
        ap_called_at=None,
        npr_call='u',
        npr_called_at=None,
        precincts_reporting=0,
        rep_vote_count=0,
        dem_vote_count=0
    )
    sq.execute()
    write_www_files()
开发者ID:imclab,项目名称:electris,代码行数:34,代码来源:fabfile.py

示例2: update_polls

# 需要导入模块: from models import State [as 别名]
# 或者: from models.State import update [as 别名]
def update_polls():
    pollster = Pollster()

    for state in State.select().where(State.electoral_votes > 1):
        charts = pollster.charts(topic='2012-president', state=state.id)

        if charts:
            chart = charts[0]
        else:
            print 'NO DATA FOR %s' % state.id.upper()
            continue

        obama = 0
        romney = 0

        if chart.estimates:
            for estimate in chart.estimates:
                if estimate['choice'] == "Obama":
                    obama = estimate['value']
                elif estimate['choice'] == "Romney":
                    romney = estimate['value']
        else:
            print 'NO ESTIMATES FOR %s' % state.id.upper()
            continue

        prediction = "t"

        if abs(obama - romney) > 15:
            if obama > romney:
                prediction = "sd"
            else:
                prediction = "sr"
        elif abs(obama - romney) > 7.5:
            if obama > romney:
                prediction = "ld"
            else:
                prediction = "lr"

        uq = State.update(prediction=prediction).where(State.id == state)
        uq.execute()
开发者ID:imclab,项目名称:electris,代码行数:42,代码来源:input.py

示例3: president

# 需要导入模块: from models import State [as 别名]
# 或者: from models.State import update [as 别名]
def president(featured=None):
    """
    Read/update list of presidential state winners.
    """

    is_featured = False
    if featured == 'featured':
        is_featured = True

    if request.method == 'GET':

        states = State.select().order_by(State.name.asc())

        if is_featured == True:
            states = states.where(State.prediction == 't').order_by(State.name.asc())

        context = {
            'states': states,
            'settings': settings
        }

        return render_template('president.html', **context)

    if request.method == 'POST':
        # First, try and get the state.
        race_slug = request.form.get('race_slug', None)
        race_slug = race_slug.strip()

        # Next, try to get the AP call.
        accept_ap_call = request.form.get('accept_ap_call', None)

        if accept_ap_call != None:
            # Figure out which direction we're going and send an appropriate message.
            if accept_ap_call.lower() == 'true':
                accept_ap_call = True
            else:
                accept_ap_call = False

        # Accumulate changes so we only execute a single update
        update_dict = {}

        # If all the pieces are here, do something.
        if race_slug != None and accept_ap_call != None:

            # Run some SQL to change the status of this set of candidate's accept_ap_call column.
            sq = State.update(accept_ap_call=accept_ap_call).where(State.id == race_slug)
            sq.execute()

            # Clear the NPR winner status of candidates who we accept AP calls for.
            if accept_ap_call == True:
                update_dict['npr_call'] = 'n',
                update_dict['npr_called_at'] = None

        # Try and get the winner.
        party = request.form.get('party', None)

        # Try and get a clear_all.
        clear_all = request.form.get('clear_all', None)

        if race_slug != None and clear_all != None:
            # If we're passing clear_all as true ...
            if clear_all == 'true':
                update_dict['npr_call'] = 'n',
                update_dict['npr_called_at'] = None

        # If all of the pieces are here, do something.
        if race_slug != None and party != None:
            update_dict['npr_call'] = party,
            update_dict['npr_called_at'] = datetime.datetime.utcnow()

        if update_dict:
            uq = State.update(**update_dict).where(State.id == race_slug)
            uq.execute()

        if settings.DEBUG:
            o.write_electris_json()
            o.write_president_json()
            o.write_bop_json()

        # TODO
        # Return a 200. This is probably bad.
        # Need to figure out what should go here.
        return "Success."
开发者ID:imclab,项目名称:electris,代码行数:85,代码来源:cms.py


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