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


Python models.convert_to_int函数代码示例

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


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

示例1: retrieve_vote_smart_candidate

    def retrieve_vote_smart_candidate(
            self, vote_smart_candidate_id=None, first_name=None, last_name=None, state_code=None):
        """
        We want to return one and only one candidate
        :param vote_smart_candidate_id:
        :param first_name:
        :param last_name:
        :param state_code:
        :return:
        """
        error_result = False
        exception_does_not_exist = False
        exception_multiple_object_returned = False
        vote_smart_candidate = VoteSmartCandidate()

        try:
            if positive_value_exists(vote_smart_candidate_id):
                vote_smart_candidate = VoteSmartCandidate.objects.get(candidateId=vote_smart_candidate_id)
                vote_smart_candidate_id = convert_to_int(vote_smart_candidate.candidateId)
                status = "RETRIEVE_VOTE_SMART_CANDIDATE_FOUND_BY_ID"
            elif positive_value_exists(first_name) or positive_value_exists(last_name):
                candidate_queryset = VoteSmartCandidate.objects.all()
                if positive_value_exists(first_name):
                    first_name = first_name.replace("`", "'")  # Vote Smart doesn't like this kind of apostrophe: `
                    candidate_queryset = candidate_queryset.filter(Q(firstName__istartswith=first_name) |
                                                                   Q(nickName__istartswith=first_name) |
                                                                   Q(preferredName__istartswith=first_name))
                if positive_value_exists(last_name):
                    last_name = last_name.replace("`", "'")  # Vote Smart doesn't like this kind of apostrophe: `
                    candidate_queryset = candidate_queryset.filter(lastName__iexact=last_name)
                if positive_value_exists(state_code):
                    candidate_queryset = candidate_queryset.filter(Q(electionStateId__iexact=state_code) |
                                                                   Q(electionStateId__iexact="NA"))
                vote_smart_candidate_list = list(candidate_queryset[:1])
                if vote_smart_candidate_list:
                    vote_smart_candidate = vote_smart_candidate_list[0]
                else:
                    vote_smart_candidate = VoteSmartCandidate()
                vote_smart_candidate_id = convert_to_int(vote_smart_candidate.candidateId)
                status = "RETRIEVE_VOTE_SMART_CANDIDATE_FOUND_BY_NAME"
            else:
                status = "RETRIEVE_VOTE_SMART_CANDIDATE_SEARCH_INDEX_MISSING"
        except VoteSmartCandidate.MultipleObjectsReturned as e:
            exception_multiple_object_returned = True
            status = "RETRIEVE_VOTE_SMART_CANDIDATE_MULTIPLE_OBJECTS_RETURNED"
        except VoteSmartCandidate.DoesNotExist:
            exception_does_not_exist = True
            status = "RETRIEVE_VOTE_SMART_CANDIDATE_NOT_FOUND"

        results = {
            'success':                      True if positive_value_exists(vote_smart_candidate_id) else False,
            'status':                       status,
            'error_result':                 error_result,
            'DoesNotExist':                 exception_does_not_exist,
            'MultipleObjectsReturned':      exception_multiple_object_returned,
            'vote_smart_candidate_found':   True if positive_value_exists(vote_smart_candidate_id) else False,
            'vote_smart_candidate_id':      vote_smart_candidate_id,
            'vote_smart_candidate':         vote_smart_candidate,
        }
        return results
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:60,代码来源:models.py

示例2: organization_edit_existing_position_form_view

def organization_edit_existing_position_form_view(request, organization_id, position_id):
    """
    In edit, you can only change your stance and comments, not who or what the position is about
    :param request:
    :param organization_id:
    :param position_id:
    :return:
    """
    # If person isn't signed in, we don't want to let them visit this page yet
    if not request.user.is_authenticated():
        return redirect('/admin')

    messages_on_stage = get_messages(request)
    organization_id = convert_to_int(organization_id)
    position_id = convert_to_int(position_id)
    organization_on_stage_found = False
    try:
        organization_on_stage = Organization.objects.get(id=organization_id)
        organization_on_stage_found = True
    except Organization.MultipleObjectsReturned as e:
        handle_record_found_more_than_one_exception(e)
    except Organization.DoesNotExist as e:
        # This is fine, create new
        handle_exception_silently(e)

    if not organization_on_stage_found:
        messages.add_message(request, messages.INFO,
                             'Could not find organization when trying to edit a position.')
        return HttpResponseRedirect(reverse('organization:organization_position_list', args=([organization_id])))

    # Get the existing position
    organization_position_on_stage = PositionEntered()
    organization_position_on_stage_found = False
    position_entered_manager = PositionEnteredManager()
    results = position_entered_manager.retrieve_position_from_id(position_id)
    if results['position_found']:
        organization_position_on_stage_found = True
        organization_position_on_stage = results['position']

    if not organization_position_on_stage_found:
        messages.add_message(request, messages.INFO,
                             'Could not find organization position when trying to edit.')
        return HttpResponseRedirect(reverse('organization:organization_position_list', args=([organization_id])))

    # Note: We have access to the candidate campaign through organization_position_on_stage.candidate_campaign

    if organization_position_on_stage_found:
        template_values = {
            'is_in_edit_mode':                              True,
            'messages_on_stage':                            messages_on_stage,
            'organization':                                 organization_on_stage,
            'organization_position':                        organization_position_on_stage,
            'possible_stances_list':                        ORGANIZATION_STANCE_CHOICES,
            'stance_selected':                              organization_position_on_stage.stance,
        }

    return render(request, 'organization/organization_position_edit.html', template_values)
开发者ID:zvxr,项目名称:WeVoteBase,代码行数:57,代码来源:views.py

示例3: retrieve_vote_smart_official

    def retrieve_vote_smart_official(
            self, vote_smart_candidate_id=None, first_name=None, last_name=None, state_code=None):
        """
        We want to return one and only one official
        :param vote_smart_candidate_id:
        :param first_name:
        :param last_name:
        :param state_code:
        :return:
        """
        error_result = False
        exception_does_not_exist = False
        exception_multiple_object_returned = False
        vote_smart_official = VoteSmartOfficial()

        try:
            if positive_value_exists(vote_smart_candidate_id):
                vote_smart_official = VoteSmartOfficial.objects.get(candidateId=vote_smart_candidate_id)
                vote_smart_candidate_id = convert_to_int(vote_smart_official.candidateId)
                status = "RETRIEVE_VOTE_SMART_OFFICIAL_FOUND_BY_ID"
            elif positive_value_exists(first_name) or positive_value_exists(last_name):
                official_queryset = VoteSmartOfficial.objects.all()
                if positive_value_exists(first_name):
                    official_queryset = official_queryset.filter(firstName__istartswith=first_name)
                if positive_value_exists(last_name):
                    official_queryset = official_queryset.filter(lastName__iexact=last_name)
                if positive_value_exists(state_code):
                    official_queryset = official_queryset.filter(officeStateId__iexact=state_code)
                vote_smart_official_list = list(official_queryset[:1])
                if vote_smart_official_list:
                    vote_smart_official = vote_smart_official_list[0]
                else:
                    vote_smart_official = VoteSmartOfficial()
                vote_smart_candidate_id = convert_to_int(vote_smart_official.candidateId)
                status = "RETRIEVE_VOTE_SMART_OFFICIAL_FOUND_BY_NAME"
            else:
                status = "RETRIEVE_VOTE_SMART_OFFICIAL_SEARCH_INDEX_MISSING"
        except VoteSmartOfficial.MultipleObjectsReturned as e:
            exception_multiple_object_returned = True
            status = "RETRIEVE_VOTE_SMART_OFFICIAL_MULTIPLE_OBJECTS_RETURNED"
        except VoteSmartOfficial.DoesNotExist:
            exception_does_not_exist = True
            status = "RETRIEVE_VOTE_SMART_OFFICIAL_NOT_FOUND"

        results = {
            'success':                      True if positive_value_exists(vote_smart_candidate_id) else False,
            'status':                       status,
            'error_result':                 error_result,
            'DoesNotExist':                 exception_does_not_exist,
            'MultipleObjectsReturned':      exception_multiple_object_returned,
            'vote_smart_official_found':   True if positive_value_exists(vote_smart_candidate_id) else False,
            'vote_smart_candidate_id':      vote_smart_candidate_id,
            'vote_smart_official':         vote_smart_official,
        }
        return results
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:55,代码来源:models.py

示例4: election_summary_view

def election_summary_view(request, election_local_id):
    messages_on_stage = get_messages(request)
    election_local_id = convert_to_int(election_local_id)
    election_on_stage_found = False
    election_on_stage = Election()

    try:
        election_on_stage = Election.objects.get(id=election_local_id)
        election_on_stage_found = True
    except Election.MultipleObjectsReturned as e:
        handle_record_found_more_than_one_exception(e, logger=logger)
    except Election.DoesNotExist:
        # This is fine, create new
        pass

    if election_on_stage_found:
        template_values = {
            'messages_on_stage': messages_on_stage,
            'election': election_on_stage,
        }
    else:
        template_values = {
            'messages_on_stage': messages_on_stage,
        }
    return render(request, 'election/election_summary.html', template_values)
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:25,代码来源:views_admin.py

示例5: organization_add_new_position_form_view

def organization_add_new_position_form_view(request, organization_id):
    messages_on_stage = get_messages(request)
    organization_id = convert_to_int(organization_id)
    all_is_well = True
    organization_on_stage_found = False
    try:
        organization_on_stage = Organization.objects.get(id=organization_id)
        organization_on_stage_found = True
    except Organization.MultipleObjectsReturned as e:
        handle_record_found_more_than_one_exception(e, logger=logger)
    except Organization.DoesNotExist:
        # This is fine, create new
        pass

    if not organization_on_stage_found:
        messages.add_message(request, messages.INFO,
                             'Could not find organization when trying to create a new position.')
        return HttpResponseRedirect(reverse('organization:organization_position_list', args=([organization_id])))

    # Prepare a drop down of candidates competing in this election
    candidate_campaign_list = CandidateCampaignList()
    candidate_campaigns_for_this_election_list \
        = candidate_campaign_list.retrieve_candidate_campaigns_for_this_election_list()

    if all_is_well:
        template_values = {
            'candidate_campaigns_for_this_election_list':   candidate_campaigns_for_this_election_list,
            'messages_on_stage':                            messages_on_stage,
            'organization':                                 organization_on_stage,
            'organization_position_candidate_campaign_id':  0,
            'possible_stances_list':                        ORGANIZATION_STANCE_CHOICES,
            'stance_selected':                              SUPPORT,  # Default stance
        }
    return render(request, 'organization/organization_position_edit.html', template_values)
开发者ID:marcusbusby,项目名称:WeVoteServer,代码行数:34,代码来源:views_admin.py

示例6: retrieve_candidate_photos_for_election_view

def retrieve_candidate_photos_for_election_view(request, election_id):
    google_civic_election_id = convert_to_int(election_id)

    # We only want to process if a google_civic_election_id comes in
    if not positive_value_exists(google_civic_election_id):
        messages.add_message(request, messages.ERROR, "Google Civic Election ID required.")
        return HttpResponseRedirect(reverse("candidate:candidate_list", args=()))

    try:
        candidate_list = CandidateCampaign.objects.order_by("candidate_name")
        if positive_value_exists(google_civic_election_id):
            candidate_list = candidate_list.filter(google_civic_election_id=google_civic_election_id)
    except CandidateCampaign.DoesNotExist:
        pass

    display_messages = False
    force_retrieve = False
    # Loop through all of the candidates in this election
    for we_vote_candidate in candidate_list:
        retrieve_candidate_results = retrieve_candidate_photos(we_vote_candidate, force_retrieve)

        if retrieve_candidate_results["status"] and display_messages:
            messages.add_message(request, messages.INFO, retrieve_candidate_results["status"])

    return HttpResponseRedirect(
        reverse("candidate:candidate_list", args=())
        + "?google_civic_election_id={var}".format(var=google_civic_election_id)
    )
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:28,代码来源:views_admin.py

示例7: polling_location_edit_process_view

def polling_location_edit_process_view(request):
    """
    Process the new or edit polling_location forms
    :param request:
    :return:
    """
    polling_location_id = convert_to_int(request.POST['polling_location_id'])
    polling_location_name = request.POST['polling_location_name']

    # Check to see if this polling_location is already being used anywhere
    polling_location_on_stage_found = False
    try:
        polling_location_query = PollingLocation.objects.filter(id=polling_location_id)
        if len(polling_location_query):
            polling_location_on_stage = polling_location_query[0]
            polling_location_on_stage_found = True
    except Exception as e:
        handle_record_not_found_exception(e, logger=logger)

    try:
        if polling_location_on_stage_found:
            # Update
            polling_location_on_stage.polling_location_name = polling_location_name
            polling_location_on_stage.save()
            messages.add_message(request, messages.INFO, 'PollingLocation updated.')
        else:
            # Create new
            messages.add_message(request, messages.INFO, 'We do not support adding new polling locations.')
    except Exception as e:
        handle_record_not_saved_exception(e, logger=logger)
        messages.add_message(request, messages.ERROR, 'Could not save polling_location.')

    return HttpResponseRedirect(reverse('polling_location:polling_location_list', args=()))
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:33,代码来源:views_admin.py

示例8: measure_edit_view

def measure_edit_view(request, measure_id):
    messages_on_stage = get_messages(request)
    measure_id = convert_to_int(measure_id)
    measure_on_stage_found = False
    try:
        measure_on_stage = ContestMeasure.objects.get(id=measure_id)
        measure_on_stage_found = True
    except ContestMeasure.MultipleObjectsReturned as e:
        handle_record_found_more_than_one_exception(e, logger=logger)
        measure_on_stage = ContestMeasure()
    except ContestMeasure.DoesNotExist:
        # This is fine, create new
        measure_on_stage = ContestMeasure()
        pass

    if measure_on_stage_found:
        template_values = {
            'messages_on_stage': messages_on_stage,
            'measure': measure_on_stage,
        }
    else:
        template_values = {
            'messages_on_stage': messages_on_stage,
        }
    return render(request, 'measure/measure_edit.html', template_values)
开发者ID:thaddeusphoenix,项目名称:WeVoteServer,代码行数:25,代码来源:views_admin.py

示例9: measure_summary_view

def measure_summary_view(request, measure_id):
    messages_on_stage = get_messages(request)
    measure_id = convert_to_int(measure_id)
    measure_on_stage_found = False
    measure_on_stage = ContestMeasure()
    google_civic_election_id = request.GET.get('google_civic_election_id', 0)
    try:
        measure_on_stage = ContestMeasure.objects.get(id=measure_id)
        measure_on_stage_found = True
    except ContestMeasure.MultipleObjectsReturned as e:
        handle_record_found_more_than_one_exception(e, logger=logger)
    except ContestMeasure.DoesNotExist:
        # This is fine, create new
        pass

    election_list = Election.objects.order_by('-election_day_text')

    if measure_on_stage_found:
        template_values = {
            'messages_on_stage': messages_on_stage,
            'measure': measure_on_stage,
            'election_list': election_list,
            'google_civic_election_id': google_civic_election_id,
        }
    else:
        template_values = {
            'messages_on_stage': messages_on_stage,
        }
    return render(request, 'measure/measure_summary.html', template_values)
开发者ID:thaddeusphoenix,项目名称:WeVoteServer,代码行数:29,代码来源:views_admin.py

示例10: fetch_next_id_we_vote_last_org_integer

def fetch_next_id_we_vote_last_org_integer():
    we_vote_settings_manager = WeVoteSettingsManager()
    id_we_vote_last_org_integer = we_vote_settings_manager.fetch_setting('id_we_vote_last_org_integer')
    id_we_vote_last_org_integer = convert_to_int(id_we_vote_last_org_integer)
    id_we_vote_last_org_integer += 1
    we_vote_settings_manager.save_setting('id_we_vote_last_org_integer', id_we_vote_last_org_integer)
    return id_we_vote_last_org_integer
开发者ID:ondrae,项目名称:WeVoteBase,代码行数:7,代码来源:models.py

示例11: fetch_next_we_vote_id_last_voter_integer

def fetch_next_we_vote_id_last_voter_integer():
    we_vote_settings_manager = WeVoteSettingsManager()
    we_vote_id_last_voter_integer = we_vote_settings_manager.fetch_setting('we_vote_id_last_voter_integer')
    we_vote_id_last_voter_integer = convert_to_int(we_vote_id_last_voter_integer)
    we_vote_id_last_voter_integer += 1
    we_vote_settings_manager.save_setting('we_vote_id_last_voter_integer', we_vote_id_last_voter_integer)
    return we_vote_id_last_voter_integer
开发者ID:thaddeusphoenix,项目名称:WeVoteServer,代码行数:7,代码来源:models.py

示例12: fetch_next_id_we_vote_last_position_integer

def fetch_next_id_we_vote_last_position_integer():
    we_vote_settings_manager = WeVoteSettingsManager()
    id_we_vote_last_position_integer = we_vote_settings_manager.fetch_setting("id_we_vote_last_position_integer")
    id_we_vote_last_position_integer = convert_to_int(id_we_vote_last_position_integer)
    id_we_vote_last_position_integer += 1
    we_vote_settings_manager.save_setting("id_we_vote_last_position_integer", id_we_vote_last_position_integer)
    return id_we_vote_last_position_integer
开发者ID:zvxr,项目名称:WeVoteBase,代码行数:7,代码来源:models.py

示例13: organization_edit_view

def organization_edit_view(request, organization_id):
    # If person isn't signed in, we don't want to let them visit this page yet
    if not request.user.is_authenticated():
        return redirect('/admin')

    messages_on_stage = get_messages(request)
    organization_id = convert_to_int(organization_id)
    organization_on_stage_found = False
    try:
        organization_on_stage = Organization.objects.get(id=organization_id)
        organization_on_stage_found = True
    except Organization.MultipleObjectsReturned as e:
        handle_record_found_more_than_one_exception(e)
    except Organization.DoesNotExist as e:
        # This is fine, create new
        handle_exception_silently(e)

    if organization_on_stage_found:
        template_values = {
            'messages_on_stage': messages_on_stage,
            'organization': organization_on_stage,
        }
    else:
        template_values = {
            'messages_on_stage': messages_on_stage,
        }
    return render(request, 'organization/organization_edit.html', template_values)
开发者ID:zvxr,项目名称:WeVoteBase,代码行数:27,代码来源:views.py

示例14: election_edit_process_view

def election_edit_process_view(request):
    """
    Process the new or edit election forms
    :param request:
    :return:
    """
    election_id = convert_to_int(request.POST["election_id"])
    election_name = request.POST["election_name"]

    # Check to see if this election is already being used anywhere
    election_on_stage_found = False
    try:
        election_query = Election.objects.filter(id=election_id)
        if len(election_query):
            election_on_stage = election_query[0]
            election_on_stage_found = True
    except Exception as e:
        handle_record_not_found_exception(e, logger=logger)

    try:
        if election_on_stage_found:
            # Update
            election_on_stage.election_name = election_name
            election_on_stage.save()
            messages.add_message(request, messages.INFO, "Election updated.")
        else:
            # Create new
            election_on_stage = Election(election_name=election_name)
            election_on_stage.save()
            messages.add_message(request, messages.INFO, "New election saved.")
    except Exception as e:
        handle_record_not_saved_exception(e, logger=logger)
        messages.add_message(request, messages.ERROR, "Could not save election.")

    return HttpResponseRedirect(reverse("election:election_list", args=()))
开发者ID:marcusbusby,项目名称:WeVoteServer,代码行数:35,代码来源:views_admin.py

示例15: voter_edit_process_view

def voter_edit_process_view(request):
    """
    Process the new or edit voter forms
    :param request:
    :return:
    """
    voter_id = convert_to_int(request.POST['voter_id'])
    voter_name = request.POST['voter_name']

    # Check to see if this voter is already being used anywhere
    voter_on_stage_found = False
    try:
        voter_query = Voter.objects.filter(id=voter_id)
        if len(voter_query):
            voter_on_stage = voter_query[0]
            voter_on_stage_found = True
    except Exception as e:
        handle_record_not_found_exception(e, logger=logger)

    try:
        if voter_on_stage_found:
            # Update
            voter_on_stage.voter_name = voter_name
            voter_on_stage.save()
            messages.add_message(request, messages.INFO, 'Voter updated.')
        else:
            # Create new
            messages.add_message(request, messages.INFO, 'We do not support adding new Voters.')
    except Exception as e:
        handle_record_not_saved_exception(e, logger=logger)
        messages.add_message(request, messages.ERROR, 'Could not save voter.')

    return HttpResponseRedirect(reverse('voter:voter_list', args=()))
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:33,代码来源:views_admin.py


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