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


Python CandidateCampaignManager.fetch_google_civic_candidate_name_from_we_vote_id方法代码示例

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


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

示例1: quick_info_import_from_sample_file

# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_google_civic_candidate_name_from_we_vote_id [as 别名]
def quick_info_import_from_sample_file(request=None):  # , load_from_uri=False  # TODO to be converted
    """
    Get the json data, and either create new entries or update existing
    :return:
    """
    # if load_from_uri:
    #     # Request json file from We Vote servers
    #     messages.add_message(request, messages.INFO, "Loading quick_info from We Vote Master servers")
    #     request = requests.get(QUICK_INFO_URL, params={
    #         "key": WE_VOTE_API_KEY,  # This comes from an environment variable
    #     })
    #     structured_json = json.loads(request.text)
    # else:
    # Load saved json from local file
    with open("quick_info/import_data/quick_info_sample.json") as json_data:
        structured_json = json.load(json_data)

    quick_info_saved = 0
    quick_info_updated = 0
    quick_info_not_processed = 0
    for one_quick_info in structured_json:
        # Make sure we have the minimum required variables
        if not positive_value_exists(one_quick_info["we_vote_id"]) \
                or not positive_value_exists(one_quick_info["organization_we_vote_id"])\
                or not positive_value_exists(one_quick_info["candidate_campaign_we_vote_id"]):
            quick_info_not_processed += 1
            continue

        # Check to see if this quick_info is already being used anywhere
        quick_info_found = False
        try:
            if len(one_quick_info["we_vote_id"]) > 0:
                quick_info_query = QuickInfo.objects.filter(we_vote_id=one_quick_info["we_vote_id"])
                if len(quick_info_query):
                    quick_info = quick_info_query[0]
                    quick_info_found = True
        except QuickInfo.DoesNotExist as e:
            handle_record_not_found_exception(e, logger=logger)
            pass
        except Exception as e:
            handle_record_not_found_exception(e, logger=logger)

        # We need to look up the local organization_id based on the newly saved we_vote_id
        organization_manager = OrganizationManager()
        organization_id = organization_manager.fetch_organization_id(one_quick_info["organization_we_vote_id"])

        # We need to look up the local candidate_campaign_id
        candidate_campaign_manager = CandidateCampaignManager()
        candidate_campaign_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(
            one_quick_info["candidate_campaign_we_vote_id"])

        # Find the google_civic_candidate_name so we have a backup way to link quick_info if the we_vote_id is lost
        google_civic_candidate_name = one_quick_info["google_civic_candidate_name"] if \
            "google_civic_candidate_name" in one_quick_info else ''
        if not positive_value_exists(google_civic_candidate_name):
            google_civic_candidate_name = candidate_campaign_manager.fetch_google_civic_candidate_name_from_we_vote_id(
                one_quick_info["candidate_campaign_we_vote_id"])

        # TODO We need to look up contest_measure_id
        contest_measure_id = 0

        try:
            if quick_info_found:
                # Update
                quick_info.we_vote_id = one_quick_info["we_vote_id"]
                quick_info.organization_id = organization_id
                quick_info.organization_we_vote_id = one_quick_info["organization_we_vote_id"]
                quick_info.candidate_campaign_id = candidate_campaign_id
                quick_info.candidate_campaign_we_vote_id = one_quick_info["candidate_campaign_we_vote_id"]
                quick_info.google_civic_candidate_name = google_civic_candidate_name
                quick_info.contest_measure_id = contest_measure_id
                quick_info.date_entered = one_quick_info["date_entered"]
                quick_info.google_civic_election_id = one_quick_info["google_civic_election_id"]
                quick_info.stance = one_quick_info["stance"]
                quick_info.more_info_url = one_quick_info["more_info_url"]
                quick_info.statement_text = one_quick_info["statement_text"]
                quick_info.statement_html = one_quick_info["statement_html"]
                quick_info.save()
                quick_info_updated += 1
                # messages.add_message(request, messages.INFO, u"QuickInfo updated: {we_vote_id}".format(
                #     we_vote_id=one_quick_info["we_vote_id"]))
            else:
                # Create new
                quick_info = QuickInfo(
                    we_vote_id=one_quick_info["we_vote_id"],
                    organization_id=organization_id,
                    organization_we_vote_id=one_quick_info["organization_we_vote_id"],
                    candidate_campaign_id=candidate_campaign_id,
                    candidate_campaign_we_vote_id=one_quick_info["candidate_campaign_we_vote_id"],
                    google_civic_candidate_name=google_civic_candidate_name,
                    contest_measure_id=contest_measure_id,
                    date_entered=one_quick_info["date_entered"],
                    google_civic_election_id=one_quick_info["google_civic_election_id"],
                    stance=one_quick_info["stance"],
                    more_info_url=one_quick_info["more_info_url"],
                    statement_text=one_quick_info["statement_text"],
                    statement_html=one_quick_info["statement_html"],
                )
                quick_info.save()
                quick_info_saved += 1
#.........这里部分代码省略.........
开发者ID:josephevans,项目名称:WeVoteServer,代码行数:103,代码来源:controllers.py

示例2: positions_import_from_sample_file

# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_google_civic_candidate_name_from_we_vote_id [as 别名]
def positions_import_from_sample_file(request=None, load_from_uri=False):
    """
    Get the json data, and either create new entries or update existing
    :return:
    """
    # if load_from_uri:
    #     # Request json file from We Vote servers
    #     messages.add_message(request, messages.INFO, "Loading positions from We Vote Master servers")
    #     request = requests.get(POSITIONS_URL, params={
    #         "key": WE_VOTE_API_KEY,  # This comes from an environment variable
    #     })
    #     structured_json = json.loads(request.text)
    # else:
    # Load saved json from local file
    with open("position/import_data/positions_sample.json") as json_data:
        structured_json = json.load(json_data)

    positions_saved = 0
    positions_updated = 0
    positions_not_processed = 0
    for one_position in structured_json:
        # Make sure we have the minimum required variables
        if not positive_value_exists(one_position["we_vote_id"]) \
                or not positive_value_exists(one_position["organization_we_vote_id"])\
                or not positive_value_exists(one_position["candidate_campaign_we_vote_id"]):
            positions_not_processed += 1
            continue

        # Check to see if this position is already being used anywhere
        position_on_stage_found = False
        try:
            if len(one_position["we_vote_id"]) > 0:
                position_query = PositionEntered.objects.filter(we_vote_id=one_position["we_vote_id"])
                if len(position_query):
                    position_on_stage = position_query[0]
                    position_on_stage_found = True
        except PositionEntered.DoesNotExist as e:
            handle_record_not_found_exception(e, logger=logger)
            pass
        except Exception as e:
            handle_record_not_found_exception(e, logger=logger)

        # We need to look up the local organization_id based on the newly saved we_vote_id
        organization_manager = OrganizationManager()
        organization_id = organization_manager.fetch_organization_id(one_position["organization_we_vote_id"])

        # We need to look up the local candidate_campaign_id
        candidate_campaign_manager = CandidateCampaignManager()
        candidate_campaign_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(
            one_position["candidate_campaign_we_vote_id"])

        # Find the google_civic_candidate_name so we have a backup way to link position if the we_vote_id is lost
        google_civic_candidate_name = one_position["google_civic_candidate_name"] if \
            "google_civic_candidate_name" in one_position else ''
        if not positive_value_exists(google_civic_candidate_name):
            google_civic_candidate_name = candidate_campaign_manager.fetch_google_civic_candidate_name_from_we_vote_id(
                one_position["candidate_campaign_we_vote_id"])

        # TODO We need to look up measure_campaign_id
        measure_campaign_id = 0

        try:
            if position_on_stage_found:
                # Update
                position_on_stage.we_vote_id = one_position["we_vote_id"]
                position_on_stage.organization_id = organization_id
                position_on_stage.organization_we_vote_id = one_position["organization_we_vote_id"]
                position_on_stage.candidate_campaign_id = candidate_campaign_id
                position_on_stage.candidate_campaign_we_vote_id = one_position["candidate_campaign_we_vote_id"]
                position_on_stage.google_civic_candidate_name = google_civic_candidate_name
                position_on_stage.measure_campaign_id = measure_campaign_id
                position_on_stage.date_entered = one_position["date_entered"]
                position_on_stage.google_civic_election_id = one_position["google_civic_election_id"]
                position_on_stage.stance = one_position["stance"]
                position_on_stage.more_info_url = one_position["more_info_url"]
                position_on_stage.statement_text = one_position["statement_text"]
                position_on_stage.statement_html = one_position["statement_html"]
                position_on_stage.save()
                positions_updated += 1
                # messages.add_message(request, messages.INFO, u"Position updated: {we_vote_id}".format(
                #     we_vote_id=one_position["we_vote_id"]))
            else:
                # Create new
                position_on_stage = PositionEntered(
                    we_vote_id=one_position["we_vote_id"],
                    organization_id=organization_id,
                    organization_we_vote_id=one_position["organization_we_vote_id"],
                    candidate_campaign_id=candidate_campaign_id,
                    candidate_campaign_we_vote_id=one_position["candidate_campaign_we_vote_id"],
                    google_civic_candidate_name=google_civic_candidate_name,
                    measure_campaign_id=measure_campaign_id,
                    date_entered=one_position["date_entered"],
                    google_civic_election_id=one_position["google_civic_election_id"],
                    stance=one_position["stance"],
                    more_info_url=one_position["more_info_url"],
                    statement_text=one_position["statement_text"],
                    statement_html=one_position["statement_html"],
                )
                position_on_stage.save()
                positions_saved += 1
#.........这里部分代码省略.........
开发者ID:thaddeusphoenix,项目名称:WeVoteServer,代码行数:103,代码来源:controllers.py


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