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


Python models.OrganizationManager类代码示例

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


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

示例1: toggle_voter_following_organization

    def toggle_voter_following_organization(self, voter_id, organization_id, following_status):
        # Does a follow_organization entry exist from this voter already exist?
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.retrieve_follow_organization(0, voter_id, organization_id)

        follow_organization_on_stage_found = False
        follow_organization_on_stage_id = 0
        follow_organization_on_stage = FollowOrganization()
        if results['follow_organization_found']:
            follow_organization_on_stage = results['follow_organization']

            # Update this follow_organization entry with new values - we do not delete because we might be able to use
            try:
                follow_organization_on_stage.following_status = following_status
                # We don't need to update here because set set auto_now=True in the field
                # follow_organization_on_stage.date_last_changed =
                follow_organization_on_stage.save()
                follow_organization_on_stage_id = follow_organization_on_stage.id
                follow_organization_on_stage_found = True
                status = 'UPDATE ' + following_status
            except Exception as e:
                status = 'FAILED_TO_UPDATE ' + following_status
                handle_record_not_saved_exception(e, logger=logger, exception_message_optional=status)
        elif results['MultipleObjectsReturned']:
            logger.warn("follow_organization: delete all but one and take it over?")
            status = 'TOGGLE_FOLLOWING MultipleObjectsReturned ' + following_status
        elif results['DoesNotExist']:
            try:
                # Create new follow_organization entry
                # First make sure that organization_id is for a valid organization
                organization_manager = OrganizationManager()
                results = organization_manager.retrieve_organization(organization_id)
                if results['organization_found']:
                    follow_organization_on_stage = FollowOrganization(
                        voter_id=voter_id,
                        organization_id=organization_id,
                        following_status=following_status,
                        # We don't need to update here because set set auto_now=True in the field
                        # date_last_changed =
                    )
                    follow_organization_on_stage.save()
                    follow_organization_on_stage_id = follow_organization_on_stage.id
                    follow_organization_on_stage_found = True
                    status = 'CREATE ' + following_status
                else:
                    status = 'ORGANIZATION_NOT_FOUND_ON_CREATE ' + following_status
            except Exception as e:
                status = 'FAILED_TO_UPDATE ' + following_status
                handle_record_not_saved_exception(e, logger=logger, exception_message_optional=status)
        else:
            status = results['status']

        results = {
            'success':                      True if follow_organization_on_stage_found else False,
            'status':                       status,
            'follow_organization_found':    follow_organization_on_stage_found,
            'follow_organization_id':       follow_organization_on_stage_id,
            'follow_organization':          follow_organization_on_stage,
        }
        return results
开发者ID:thaddeusphoenix,项目名称:WeVoteServer,代码行数:60,代码来源:models.py

示例2: scrape_and_save_social_media_from_all_organizations

def scrape_and_save_social_media_from_all_organizations(state_code=''):
    facebook_pages_found = 0
    twitter_handles_found = 0
    force_retrieve = False
    temp_count = 0

    organization_manager = OrganizationManager()
    organization_list_query = Organization.objects.order_by('organization_name')
    if positive_value_exists(state_code):
        organization_list_query = organization_list_query.filter(state_served_code=state_code)

    organization_list = organization_list_query
    for organization in organization_list:
        twitter_handle = False
        facebook_page = False
        if not organization.organization_website:
            continue
        if (not positive_value_exists(organization.organization_twitter_handle)) or force_retrieve:
            scrape_results = scrape_social_media_from_one_site(organization.organization_website)

            # Only include a change if we have a new value (do not try to save blank value)
            if scrape_results['twitter_handle_found'] and positive_value_exists(scrape_results['twitter_handle']):
                twitter_handle = scrape_results['twitter_handle']
                twitter_handles_found += 1

            if scrape_results['facebook_page_found'] and positive_value_exists(scrape_results['facebook_page']):
                facebook_page = scrape_results['facebook_page']
                facebook_pages_found += 1

            save_results = organization_manager.update_organization_social_media(organization, twitter_handle,
                                                                                 facebook_page)

        if save_results['success']:
            organization = save_results['organization']

        # ######################################
        # If we have a Twitter handle for this org, refresh the data
        if organization.organization_twitter_handle:
            results = retrieve_twitter_user_info(organization.organization_twitter_handle)

            if results['success']:
                save_results = organization_manager.update_organization_twitter_details(
                    organization, results['twitter_json'])

                if save_results['success']:
                    results = update_social_media_statistics_in_other_tables(organization)
        # ######################################
        # temp_count += 1
        # if temp_count > 10:
        #     break

    status = "ORGANIZATION_SOCIAL_MEDIA_RETRIEVED"
    results = {
        'success':                  True,
        'status':                   status,
        'twitter_handles_found':    twitter_handles_found,
        'facebook_pages_found':     facebook_pages_found,
    }
    return results
开发者ID:eternal44,项目名称:WeVoteServer,代码行数:59,代码来源:controllers.py

示例3: scrape_website_for_social_media_view

def scrape_website_for_social_media_view(request, organization_id, force_retrieve=False):
    authority_required = {'admin'}  # admin, verified_volunteer
    if not voter_has_authority(request, authority_required):
        return redirect_to_sign_in_page(request, authority_required)

    facebook_page = False
    twitter_handle = False

    organization_manager = OrganizationManager()
    results = organization_manager.retrieve_organization(organization_id)

    if not results['organization_found']:
        messages.add_message(request, messages.INFO, results['status'])
        return HttpResponseRedirect(reverse('organization:organization_edit', args=(organization_id,)))

    organization = results['organization']

    if not organization.organization_website:
        messages.add_message(request, messages.ERROR, "No organizational website found.")
        return HttpResponseRedirect(reverse('organization:organization_position_list', args=(organization_id,)))

    if (not positive_value_exists(organization.organization_twitter_handle)) or \
            (not positive_value_exists(organization.organization_facebook)) or force_retrieve:
        scrape_results = scrape_social_media_from_one_site(organization.organization_website)

        if scrape_results['twitter_handle_found']:
            twitter_handle = scrape_results['twitter_handle']
            messages.add_message(request, messages.INFO, "Twitter handle found: " + twitter_handle)
        else:
            messages.add_message(request, messages.INFO, "No Twitter handle found: " + scrape_results['status'])

        if scrape_results['facebook_page_found']:
            facebook_page = scrape_results['facebook_page']
            messages.add_message(request, messages.INFO, "Facebook page found: " + facebook_page)

    save_results = organization_manager.update_organization_social_media(organization, twitter_handle,
                                                                         facebook_page)
    if save_results['success']:
        organization = save_results['organization']
    else:
        organization.organization_twitter_handle = twitter_handle  # Store it temporarily

    # ######################################
    if organization.organization_twitter_handle:
        results = retrieve_twitter_user_info(organization.organization_twitter_handle)

        if results['success']:
            save_results = organization_manager.update_organization_twitter_details(
                organization, results['twitter_json'])

            if save_results['success']:
                organization = save_results['organization']
                results = update_social_media_statistics_in_other_tables(organization)
    # ######################################

    return HttpResponseRedirect(reverse('organization:organization_position_list', args=(organization_id,)))
开发者ID:nf071590,项目名称:WeVoteServer,代码行数:56,代码来源:views_admin.py

示例4: voter_guide_display_name

 def voter_guide_display_name(self):
     if self.display_name:
         return self.display_name
     elif self.voter_guide_owner_type == ORGANIZATION:
         organization_manager = OrganizationManager()
         organization_id = 0
         organization_we_vote_id = self.organization_we_vote_id
         results = organization_manager.retrieve_organization(organization_id, organization_we_vote_id)
         if results["organization_found"]:
             organization = results["organization"]
             organization_name = organization.organization_name
             return organization_name
     return ""
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:13,代码来源:models.py

示例5: voter_guide_image_url

 def voter_guide_image_url(self):
     if self.image_url:
         return self.image_url
     elif self.voter_guide_owner_type == ORGANIZATION:
         organization_manager = OrganizationManager()
         organization_id = 0
         organization_we_vote_id = self.organization_we_vote_id
         results = organization_manager.retrieve_organization(organization_id, organization_we_vote_id)
         if results["organization_found"]:
             organization = results["organization"]
             organization_photo_url = organization.organization_photo_url()
             return organization_photo_url
     return ""
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:13,代码来源:models.py

示例6: toggle_voter_following_organization

    def toggle_voter_following_organization(self, voter_id, organization_id, following_status):
        # Does a follow_organization entry exist from this voter already exist?
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.retrieve_follow_organization(0, voter_id, organization_id)

        follow_organization_on_stage_found = False
        follow_organization_on_stage_id = 0
        follow_organization_on_stage = FollowOrganization()
        if results['follow_organization_found']:
            follow_organization_on_stage = results['follow_organization']

            # Update this follow_organization entry with new values - we do not delete because we might be able to use
            try:
                follow_organization_on_stage.following_status = following_status
                # We don't need to update here because set set auto_now=True in the field
                # follow_organization_on_stage.date_last_changed =
                follow_organization_on_stage.save()
                follow_organization_on_stage_id = follow_organization_on_stage.id
                follow_organization_on_stage_found = True
            except Exception as e:
                handle_record_not_saved_exception(e)

        elif results['MultipleObjectsReturned']:
            print "follow_organization: delete all but one and take it over?"
        elif results['DoesNotExist']:
            try:
                # Create new follow_organization entry
                # First make sure that organization_id is for a valid organization
                organization_manager = OrganizationManager()
                results = organization_manager.retrieve_organization(organization_id)
                if results['organization_found']:
                    follow_organization_on_stage = FollowOrganization(
                        voter_id=voter_id,
                        organization_id=organization_id,
                        following_status=following_status,
                        # We don't need to update here because set set auto_now=True in the field
                        # date_last_changed =
                    )
                    follow_organization_on_stage.save()
                    follow_organization_on_stage_id = follow_organization_on_stage.id
                    follow_organization_on_stage_found = True
            except Exception as e:
                handle_record_not_saved_exception(e)

        results = {
            'success':                      True if follow_organization_on_stage_found else False,
            'follow_organization_found':    follow_organization_on_stage_found,
            'follow_organization_id':       follow_organization_on_stage_id,
            'follow_organization':          follow_organization_on_stage,
        }
        return results
开发者ID:zvxr,项目名称:WeVoteBase,代码行数:51,代码来源:models.py

示例7: organization_edit_view

def organization_edit_view(request, organization_id):
    authority_required = {'verified_volunteer'}  # admin, verified_volunteer
    if not voter_has_authority(request, authority_required):
        return redirect_to_sign_in_page(request, authority_required)

    # A positive value in google_civic_election_id means we want to create a voter guide for this org for this election
    google_civic_election_id = request.GET.get('google_civic_election_id', 0)

    messages_on_stage = get_messages(request)
    organization_id = convert_to_int(organization_id)
    organization_on_stage_found = False
    organization_manager = OrganizationManager()
    organization_on_stage = Organization()
    state_served_code = ''
    results = organization_manager.retrieve_organization(organization_id)
    if results['organization_found']:
        organization_on_stage = results['organization']
        state_served_code = organization_on_stage.state_served_code
        organization_on_stage_found = True

    election_manager = ElectionManager()
    upcoming_election_list = []
    results = election_manager.retrieve_upcoming_elections()
    if results['success']:
        upcoming_election_list = results['election_list']

    state_list = STATE_CODE_MAP
    sorted_state_list = sorted(state_list.items())

    if organization_on_stage_found:
        template_values = {
            'messages_on_stage':        messages_on_stage,
            'organization':             organization_on_stage,
            'upcoming_election_list':   upcoming_election_list,
            'google_civic_election_id': google_civic_election_id,
            'state_list':               sorted_state_list,
            'state_served_code':        state_served_code,
        }
    else:
        template_values = {
            'messages_on_stage': messages_on_stage,
            'upcoming_election_list':   upcoming_election_list,
            'google_civic_election_id': google_civic_election_id,
            'state_list':               sorted_state_list,
        }
    return render(request, 'organization/organization_edit.html', template_values)
开发者ID:trinile,项目名称:WeVoteServer,代码行数:46,代码来源:views_admin.py

示例8: refresh_twitter_details_view

def refresh_twitter_details_view(request, organization_id):
    authority_required = {'verified_volunteer'}  # admin, verified_volunteer
    if not voter_has_authority(request, authority_required):
        return redirect_to_sign_in_page(request, authority_required)

    organization_manager = OrganizationManager()
    results = organization_manager.retrieve_organization(organization_id)

    if not results['organization_found']:
        messages.add_message(request, messages.INFO, results['status'])
        return HttpResponseRedirect(reverse('organization:organization_edit', args=(organization_id,)))

    organization = results['organization']

    results = refresh_twitter_details(organization)

    return HttpResponseRedirect(reverse('organization:organization_position_list', args=(organization_id,)))
开发者ID:nf071590,项目名称:WeVoteServer,代码行数:17,代码来源:views_admin.py

示例9: import_organization_logo_from_wikipedia_view

def import_organization_logo_from_wikipedia_view(request, organization_id):
    organization_manager = OrganizationManager()
    results = organization_manager.retrieve_organization(organization_id)

    if not results['organization_found']:
        messages.add_message(request, messages.INFO, results['status'])
        return HttpResponseRedirect(reverse('organization:organization_edit', args=(organization_id,)))

    organization = results['organization']

    results = retrieve_organization_logo_from_wikipedia(organization)

    if not results['success']:
        messages.add_message(request, messages.INFO, results['status'])
    else:
        messages.add_message(request, messages.INFO, "Wikipedia information retrieved.")

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

示例10: import_organization_logo_from_wikipedia_view

def import_organization_logo_from_wikipedia_view(request, organization_id):
    authority_required = {'admin'}  # admin, verified_volunteer
    if not voter_has_authority(request, authority_required):
        return redirect_to_sign_in_page(request, authority_required)

    logo_found = False

    organization_manager = OrganizationManager()
    results = organization_manager.retrieve_organization(organization_id)

    if not results['organization_found']:
        messages.add_message(request, messages.INFO, results['status'])
        return HttpResponseRedirect(reverse('organization:organization_edit', args=(organization_id,)))

    organization = results['organization']

    # When looking up logos one at a time, we want to force a retrieve
    force_retrieve = True
    organization_results = retrieve_wikipedia_page_from_wikipedia(organization, force_retrieve)

    if organization_results['wikipedia_page_found']:
        wikipedia_page = organization_results['wikipedia_page']

        logo_results = retrieve_organization_logo_from_wikipedia_page(organization, wikipedia_page, force_retrieve)
        if logo_results['logo_found']:
            logo_found = True

        if positive_value_exists(force_retrieve):
            if 'image_options' in logo_results:
                for one_image in logo_results['image_options']:
                    link_to_image = "<a href='{one_image}' target='_blank'>{one_image}</a>".format(one_image=one_image)
                    messages.add_message(request, messages.INFO, link_to_image)

        if not logo_results['success']:
            messages.add_message(request, messages.ERROR, logo_results['status'])
    else:
        messages.add_message(request, messages.ERROR, "Wikipedia page not found. " + organization_results['status'])

    if logo_found:
        messages.add_message(request, messages.INFO, "Wikipedia logo retrieved.")
    else:
        messages.add_message(request, messages.ERROR, "Wikipedia logo not retrieved.")

    return HttpResponseRedirect(reverse('organization:organization_position_list', args=(organization_id,)))
开发者ID:eternal44,项目名称:WeVoteServer,代码行数:44,代码来源:views_admin.py

示例11: retrieve_twitter_data_for_all_organizations

def retrieve_twitter_data_for_all_organizations(state_code='', google_civic_election_id=0, first_retrieve_only=False):
    number_of_twitter_accounts_queried = 0
    number_of_organizations_updated = 0

    organization_manager = OrganizationManager()
    organization_list_query = Organization.objects.order_by('organization_name')
    if positive_value_exists(state_code):
        organization_list_query = organization_list_query.filter(state_served_code=state_code)

    # TODO DALE limit this to organizations that have a voter guide in a particular election

    organization_list = organization_list_query
    for organization in organization_list:
        # ######################################
        # If we have a Twitter handle for this org, refresh the data
        if organization.organization_twitter_handle:
            retrieved_twitter_data = False
            if first_retrieve_only:
                if not positive_value_exists(organization.twitter_followers_count):
                    results = retrieve_twitter_user_info(organization.organization_twitter_handle)
                    retrieved_twitter_data = results['success']
                    number_of_twitter_accounts_queried += 1
            else:
                results = retrieve_twitter_user_info(organization.organization_twitter_handle)
                retrieved_twitter_data = results['success']
                number_of_twitter_accounts_queried += 1

            if retrieved_twitter_data:
                number_of_organizations_updated += 1
                save_results = organization_manager.update_organization_twitter_details(
                    organization, results['twitter_json'])

                if save_results['success']:
                    results = update_social_media_statistics_in_other_tables(organization)

    status = "ALL_ORGANIZATION_TWITTER_DATA_RETRIEVED"
    results = {
        'success':                              True,
        'status':                               status,
        'number_of_twitter_accounts_queried':   number_of_twitter_accounts_queried,
        'number_of_organizations_updated':      number_of_organizations_updated,
    }
    return results
开发者ID:josephevans,项目名称:WeVoteServer,代码行数:43,代码来源:controllers.py

示例12: scrape_and_save_social_media_from_all_organizations

def scrape_and_save_social_media_from_all_organizations(state_code='', force_retrieve=False):
    facebook_pages_found = 0
    twitter_handles_found = 0

    organization_manager = OrganizationManager()
    organization_list_query = Organization.objects.order_by('organization_name')
    if positive_value_exists(state_code):
        organization_list_query = organization_list_query.filter(state_served_code=state_code)

    organization_list = organization_list_query
    for organization in organization_list:
        twitter_handle = False
        facebook_page = False
        if not organization.organization_website:
            continue
        if (not positive_value_exists(organization.organization_twitter_handle)) or force_retrieve:
            scrape_results = scrape_social_media_from_one_site(organization.organization_website)

            # Only include a change if we have a new value (do not try to save blank value)
            if scrape_results['twitter_handle_found'] and positive_value_exists(scrape_results['twitter_handle']):
                twitter_handle = scrape_results['twitter_handle']
                twitter_handles_found += 1

            if scrape_results['facebook_page_found'] and positive_value_exists(scrape_results['facebook_page']):
                facebook_page = scrape_results['facebook_page']
                facebook_pages_found += 1

            save_results = organization_manager.update_organization_social_media(organization, twitter_handle,
                                                                                 facebook_page)

        # ######################################
        # We refresh the Twitter information in another function

    status = "ORGANIZATION_SOCIAL_MEDIA_SCRAPED"
    results = {
        'success':                  True,
        'status':                   status,
        'twitter_handles_found':    twitter_handles_found,
        'facebook_pages_found':     facebook_pages_found,
    }
    return results
开发者ID:josephevans,项目名称:WeVoteServer,代码行数:41,代码来源:controllers.py

示例13: organization_retrieve

def organization_retrieve(organization_id, we_vote_id):
    organization_id = convert_to_int(organization_id)

    we_vote_id = we_vote_id.strip()
    if not positive_value_exists(organization_id) and not positive_value_exists(we_vote_id):
        json_data = {
            'status': "ORGANIZATION_RETRIEVE_BOTH_IDS_MISSING",
            'success': False,
            'organization_id': organization_id,
            'we_vote_id': we_vote_id,
        }
        return HttpResponse(json.dumps(json_data), content_type='application/json')

    organization_manager = OrganizationManager()
    results = organization_manager.retrieve_organization(organization_id, we_vote_id)

    if results['organization_found']:
        organization = results['organization']
        json_data = {
            'organization_id': organization.id,
            'we_vote_id': organization.we_vote_id,
            'organization_name':
                organization.organization_name if positive_value_exists(organization.organization_name) else '',
            'organization_website': organization.organization_website if positive_value_exists(
                organization.organization_website) else '',
            'organization_twitter':
                organization.twitter_handle if positive_value_exists(organization.twitter_handle) else '',
            'success': True,
            'status': results['status'],
        }
        return HttpResponse(json.dumps(json_data), content_type='application/json')
    else:
        json_data = {
            'status': results['status'],
            'success': False,
            'organization_id': organization_id,
            'we_vote_id': we_vote_id,
        }
        return HttpResponse(json.dumps(json_data), content_type='application/json')
开发者ID:thaddeusphoenix,项目名称:WeVoteServer,代码行数:39,代码来源:controllers.py

示例14: refresh_twitter_details

def refresh_twitter_details(organization):
    organization_manager = OrganizationManager()
    status = "ENTERING_REFRESH_TWITTER_DETAILS"

    if not organization:
        status = "ORGANIZATION_TWITTER_DETAILS_NOT_RETRIEVED-ORG_MISSING"
        results = {
            'success':                  False,
            'status':                   status,
        }
        return results

    if organization.organization_twitter_handle:
        status = "ORGANIZATION_TWITTER_DETAILS-REACHING_OUT_TO_TWITTER"
        results = retrieve_twitter_user_info(organization.organization_twitter_handle)

        if results['success']:
            status = "ORGANIZATION_TWITTER_DETAILS_RETRIEVED_FROM_TWITTER"
            save_results = organization_manager.update_organization_twitter_details(
                organization, results['twitter_json'])

            if save_results['success']:
                results = update_social_media_statistics_in_other_tables(organization)
                status = "ORGANIZATION_TWITTER_DETAILS_RETRIEVED_FROM_TWITTER_AND_SAVED"
    else:
        status = "ORGANIZATION_TWITTER_DETAILS-CLEARING_DETAILS"
        save_results = organization_manager.clear_organization_twitter_details(organization)

        if save_results['success']:
            results = update_social_media_statistics_in_other_tables(organization)
            status = "ORGANIZATION_TWITTER_DETAILS_CLEARED_FROM_DB"

    results = {
        'success':                  True,
        'status':                   status,
    }
    return results
开发者ID:nf071590,项目名称:WeVoteServer,代码行数:37,代码来源:controllers.py

示例15: update_or_create_we_vote_organization

    def update_or_create_we_vote_organization(self, vote_smart_special_interest_group_id):
        # See if we can find an existing We Vote organization with vote_smart_special_interest_group_id
        if not positive_value_exists(vote_smart_special_interest_group_id):
            results = {
                'success':              False,
                'status':               "SPECIAL_INTEREST_GROUP_ID_MISSING",
                'organization_found':   False,
                'organization':         Organization(),
            }
            return results

        # Retrieve Special Interest Group
        try:
            vote_smart_organization = VoteSmartSpecialInterestGroup.objects.get(
                sigId=vote_smart_special_interest_group_id)
            vote_smart_organization_found = True
        except VoteSmartSpecialInterestGroup.MultipleObjectsReturned as e:
            vote_smart_organization_found = False
        except VoteSmartSpecialInterestGroup.DoesNotExist as e:
            # An organization matching this Vote Smart ID wasn't found
            vote_smart_organization_found = False

        if not vote_smart_organization_found:
            results = {
                'success':              False,
                'status':               "SPECIAL_INTEREST_GROUP_MISSING",
                'organization_found':   False,
                'organization':         Organization(),
            }
            return results

        we_vote_organization_manager = OrganizationManager()
        organization_id = 0
        organization_we_vote_id = None
        we_vote_organization_found = False
        results = we_vote_organization_manager.retrieve_organization(organization_id, organization_we_vote_id,
                                                                     vote_smart_special_interest_group_id)

        if results['organization_found']:
            success = True
            status = "NOT UPDATING RIGHT NOW"
            we_vote_organization_found = True
            we_vote_organization = results['organization']
            # Update existing organization entry
        else:
            # Create new organization, or find existing org via other fields
            try:
                defaults_from_vote_smart = {
                    'organization_name': vote_smart_organization.name,
                    'organization_address': vote_smart_organization.address,
                    'organization_city': vote_smart_organization.city,
                    'organization_state': vote_smart_organization.state,
                    'organization_zip': vote_smart_organization.zip,
                    'organization_phone1': vote_smart_organization.phone1,
                    'organization_phone2': vote_smart_organization.phone2,
                    'organization_fax': vote_smart_organization.fax,
                    'organization_email': vote_smart_organization.email,
                    'organization_website': vote_smart_organization.url,
                    'organization_contact_name': vote_smart_organization.contactName,
                    'organization_description': vote_smart_organization.description,
                    'state_served_code': vote_smart_organization.stateId,
                    'vote_smart_id': vote_smart_organization.sigId,
                }
                we_vote_organization, created = Organization.objects.update_or_create(
                    organization_name=vote_smart_organization.name,
                    # organization_website=vote_smart_organization.url,
                    # organization_email=vote_smart_organization.email,
                    defaults=defaults_from_vote_smart,
                )
                success = True
                status = "UPDATE_OR_CREATE_ORGANIZATION_FROM_VOTE_SMART"
                we_vote_organization_found = True
            except Organization.MultipleObjectsReturned as e:
                success = False
                status = "UPDATE_OR_CREATE_ORGANIZATION_FROM_VOTE_SMART_MULTIPLE_FOUND"
                we_vote_organization = Organization()
            except Exception as error_instance:
                error_message = error_instance.args
                status = "UPDATE_OR_CREATE_ORGANIZATION_FROM_VOTE_SMART_FAILED: " \
                         "{error_message}".format(error_message=error_message)
                success = False
                we_vote_organization = Organization()

        results = {
            'success':              success,
            'status':               status,
            'organization_found':   we_vote_organization_found,
            'organization':         we_vote_organization,
        }
        return results
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:90,代码来源:models.py


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