Beispiel #1
0
 def handle(self, *args, **options):
     with Salesforce() as sf:
         if options['all']:
             command = "SELECT Accounts_ID__c FROM Contact "\
                           "WHERE Faculty_Verified__c = 'Confirmed' "\
                           "AND Accounts_ID__c != null"
             response = sf.query_all(command)
         elif options['user_id']:
             social_user = SocialAuthStorage.user.objects.filter(
                 user_id=options['user_id'])
             accounts_id = social_user[0].uid
             command = "SELECT Accounts_ID__c FROM Contact "\
                           "WHERE Faculty_Verified__c = 'Confirmed' "\
                           "AND Accounts_ID__c = '{}'".format(accounts_id)
             response = sf.query(command)
         else:
             raise argparse.ArgumentError()
         records = response['records']
         faculty_list = [contact['Accounts_ID__c'] for contact in records]
         for account_id in faculty_list:
             social_user = SocialAuthStorage.user.objects.filter(
                 uid=account_id)
             if social_user:
                 cms_id = social_user[0].user_id
                 user = User.objects.get(pk=cms_id)
                 faculty_group = Group.objects.get_by_natural_key('Faculty')
                 user.groups.add(faculty_group)
                 user.save()
                 faculty_group.save()
     responce = self.style.SUCCESS(
         "Successfully updated user faculty status")
     self.stdout.write(responce)
Beispiel #2
0
    def handle(self, *args, **options):
        with Salesforce() as sf:
            now = datetime.datetime.now()

            year = now.year
            if now.month < 7: # Salesforce needs the school base year, this is how they calculate it
                year = year - 1

            #first, we need to upload any records that have been updated
            adoptions_num_updated = 0

            adoptions = AdoptionOpportunityRecord.objects.filter(verified=True)
            data = []
            for adoption in adoptions:
                data_dict_item = {
                    'Id': adoption.opportunity_id,
                    'CloseDate': adoption.last_update.strftime('%Y-%m-%d'),
                    'Type': 'Renewal - Verified'
                }
                data.append(data_dict_item)
            results = sf.bulk.Opportunity.update(data)
            for result in results:
                if result['success']: # we don't need to store these anymore, they are in SF now with a new opportunity type (so we don't get them in the next step)
                    adoptions_num_updated = adoptions_num_updated + 1
                    adoptions.get(opportunity_id=result['id']).delete()


            # then we will get any new records
            command = "SELECT Id, OS_Accounts_ID__c, Book_Text__c, Contact_Email__c, School_Name__c, Yearly_Students__c, Students__c, Type, Base_Year__c, IsWon from Opportunity WHERE OS_Accounts_ID__c != null AND Type = 'Renewal' AND Base_Year__c = {} AND IsWon = True".format(year)

            response = sf.query_all(command)
            records = response['records']

            num_created = 0
            num_updated = 0
            for record in records:
                try:
                    opportunity = AdoptionOpportunityRecord.objects.get(opportunity_id=record['Id'])
                    opportunity.account_id = record['OS_Accounts_ID__c']
                    opportunity.book_name = record['Book_Text__c']
                    opportunity.email = record['Contact_Email__c']
                    opportunity.school = record['School_Name__c']
                    opportunity.yearly_students = record['Yearly_Students__c']
                    num_updated = num_updated + 1
                except AdoptionOpportunityRecord.DoesNotExist:
                    opportunity = AdoptionOpportunityRecord.objects.create(
                        opportunity_id=record['Id'],
                        account_id=record['OS_Accounts_ID__c'],
                        book_name= record['Book_Text__c'],
                        email= record['Contact_Email__c'],
                        school= record['School_Name__c'],
                        yearly_students= record['Yearly_Students__c']
                    )
                    num_created = num_created + 1


                opportunity.save()

            response = self.style.SUCCESS("Successfully updated opportunity records. {} were newly created and {} were updated. {} were synced with Salesforce".format(num_created, num_updated, adoptions_num_updated))
        self.stdout.write(response)
Beispiel #3
0
def get_adoption_status(request):
    account = request.GET.get('id', False)

    if account:
        with Salesforce() as sf:
            q = sf.query(
                "SELECT Adoption_Status__c FROM Contact WHERE Accounts_ID__c = '{}'"
                .format(account))

            return JsonResponse(q)
    def handle(self, *args, **options):
        new_resource_downloads = ResourceDownload.objects.select_related(
            'book').filter(salesforce_id__isnull=True)  # ones to create
        existing_resource_downloads = ResourceDownload.objects.exclude(
            salesforce_id__isnull=True
        )  #ones to update (this can be done in bulk)

        number_to_create = new_resource_downloads.count()
        number_to_update = existing_resource_downloads.count()
        number_created = 0
        number_updated = 0

        with Salesforce() as sf:
            data = []
            for rd in existing_resource_downloads:
                # only update the items that should change on an existing resource download record (num of times and date)
                data_dict_item = {
                    'Id': rd.salesforce_id,
                    'Number_of_times_accessed__c': rd.number_of_times_accessed,
                    'Last_accessed__c': rd.last_access.strftime('%Y-%m-%d')
                }
                data.append(data_dict_item)
                number_updated = number_updated + 1
            sf.bulk.Resource__c.update(data)

            for rd in new_resource_downloads:
                sf_resource = sf.Resource__c.create({
                    'Book__c':
                    rd.book.title,
                    'Book_Format__c':
                    rd.book_format,
                    'OS_Accounts_ID__c':
                    rd.account_id,
                    'Name':
                    rd.resource_name,
                    'Number_of_times_accessed__c':
                    rd.number_of_times_accessed,
                    'Last_accessed__c':
                    rd.last_access.strftime('%Y-%m-%d')
                })
                number_created = number_created + 1
                rd.salesforce_id = sf_resource['id']
                with transaction.atomic():
                    rd.save()

        response = self.style.SUCCESS(
            "[SF Resource Download] Created {} of {}. Updated {} of {}.".
            format(number_created, number_to_create, number_updated,
                   number_to_update))
        self.stdout.write(response)
Beispiel #5
0
def check_if_email_used(institutional_email):
    with Salesforce() as sf:
        try:
            #social_user = SocialAuthStorage.user.objects.filter(user_id=user_id)
            #accounts_id = social_user[0].uid
            command = "SELECT OS_Accounts_ID__c FROM Lead WHERE Institutional_Email__c = '{}' AND LeadSource = 'OSC Faculty' AND Status != 'Converted'".format(
                institutional_email)
            response = sf.query(command)

            try:
                record = response['records'][0]['OS_Accounts_ID__c']
                return True
            except IndexError:
                return False
        except IndexError:
            return False
Beispiel #6
0
def check_if_faculty_pending(user_id):
    with Salesforce() as sf:
        try:
            social_user = SocialAuthStorage.user.objects.filter(
                user_id=user_id)
            accounts_id = social_user[0].uid
            command = "SELECT OS_Accounts_ID__c FROM Lead WHERE OS_Accounts_ID__c = '{}' AND Status != 'Converted'".format(
                accounts_id)
            response = sf.query(command)

            try:
                record = response['records'][0]['OS_Accounts_ID__c']
                return True
            except IndexError:
                return False
        except IndexError:
            return False
    def handle(self, *args, **options):
        with Salesforce() as sf:
            command = "SELECT Id, Accounts_ID__c, Faculty_Verified__C FROM Contact"
            response = sf.query(command)

            for record in response['records']:
                salesforce_id = record['Id']
                ox_account_id = record['Accounts_ID__c']
                faculty_status = record['Faculty_Verified__c']

                if ox_account_id:
                    verification, created = Verification.objects.get_or_create(
                        salesforce_id=salesforce_id)
                    verification.ox_accounts_id = ox_account_id
                    verification.status = faculty_status

                    verification.save()

                    print("Verification created for {}".format(salesforce_id))

        print("User Status Updated!")
Beispiel #8
0
def update_faculty_status(user_id):
    faculty_group, created = Group.objects.get_or_create(name="Faculty")

    with Salesforce() as sf:
        try:
            user = User.objects.get(pk=user_id)
            social_user = SocialAuthStorage.user.objects.filter(user=user)
            accounts_id = social_user[0].uid
            command = "SELECT Accounts_ID__c FROM Contact " \
                      "WHERE Faculty_Verified__c = 'Confirmed' " \
                      "AND Accounts_ID__c = '{}'".format(accounts_id)
            response = sf.query(command)

            try:
                record = response['records'][0]['Accounts_ID__c']
                if record:
                    faculty_group.user_set.add(user)
                    user.save()
                return True
            except IndexError:
                return False
        except IndexError:
            return False
    def handle(self, *args, **options):
        with Salesforce() as sf:
            now = datetime.datetime.now()
            year = now.year
            if now.month < 7: # Salesforce needs the school base year, this is how they calculate it
                year = year - 1

            command = "SELECT Id, OS_Accounts_ID__c, Book_Text__c, Contact_Email__c, School_Name__c, Yearly_Students__c, Type, Base_Year__c, IsWon from Opportunity WHERE OS_Accounts_ID__c != null AND Type = 'Renewal' AND Base_Year__c = {} AND IsWon = True".format(year)
            # Type = 'Renewal' <-- this will need to be changed for QA testing each time (New Business is for brand new adoptions)

            response = sf.query_all(command)
            records = response['records']

            if records:
                AdoptionOpportunityRecord.objects.all().delete()

            num_created = 0
            for record in records:

                opportunity, created = AdoptionOpportunityRecord.objects.update_or_create(
                    opportunity_id=record['Id'],
                    defaults={'account_id': record['OS_Accounts_ID__c'],
                              'book_name': record['Book_Text__c'],
                              'email': record['Contact_Email__c'],
                              'school': record['School_Name__c'],
                              'yearly_students': record['Yearly_Students__c']
                              },
                )

                if created:
                    num_created = num_created + 1

                opportunity.save()

            response = self.style.SUCCESS("Successfully updated opportunity records. {} were newly created.".format(num_created))
        self.stdout.write(response)
    def handle(self, *args, **options):
        with Salesforce() as sf:
            command = "SELECT Id, Name, Description, Website FROM Account "\
                          "WHERE Number_of_Adoptions__c > 0 and Id != '001U0000011KxWa'"
            response = sf.query_all(command)
            sf_adopters = response['records']

            if sf_adopters:
                Adopter.objects.all().delete()

            for sf_adopter in sf_adopters:

                adopter, created = Adopter.objects.update_or_create(
                    sales_id=sf_adopter['Id'],
                    defaults={
                        'name': sf_adopter['Name'],
                        'description': sf_adopter['Description'],
                        'website': sf_adopter['Website'],
                    },
                )

                adopter.save()
            response = self.style.SUCCESS("Successfully updated adopters")
        self.stdout.write(response)
Beispiel #11
0
    def handle(self, *args, **options):
        with Salesforce() as sf:
            query = "SELECT Name, Id, Phone, " \
                      "Website, " \
                      "Type, " \
                      "K_I_P__c, " \
                      "Achieving_the_Dream_School__c, " \
                      "HBCU__c, " \
                      "Texas_Higher_Ed__c, " \
                      "Approximate_Enrollment__c, " \
                      "Pell_Grant_Recipients__c, " \
                      "Students_Pell_Grant__c, " \
                      "Students_Current_Year__c, " \
                      "All_Time_Students2__c, " \
                      "Savings_Current_Year__c, " \
                      "All_Time_Savings2__c, " \
                      "BillingStreet, " \
                      "BillingCity, " \
                      "BillingState, " \
                      "BillingPostalCode, " \
                      "BillingCountry, " \
                      "Address_Latitude__c, " \
                      "Address_Longitude__c," \
                      "Testimonial__c," \
                      "Testimonial_Name__c, " \
                      "Testimonial_Position__c, " \
                      "Number_of_Adoptions__c FROM Account WHERE Number_of_Adoptions__c > 0"
            response = sf.query_all(query)
            sf_schools = response['records']

            district_query = "SELECT Name, Id, Phone, " \
                      "RecordTypeId, " \
                      "Website, " \
                      "Type, " \
                      "K_I_P__c, " \
                      "Achieving_the_Dream_School__c, " \
                      "HBCU__c, " \
                      "Texas_Higher_Ed__c, " \
                      "Approximate_Enrollment__c, " \
                      "Pell_Grant_Recipients__c, " \
                      "Students_Pell_Grant__c, " \
                      "Students_Current_Year__c, " \
                      "All_Time_Students2__c, " \
                      "Savings_Current_Year__c, " \
                      "All_Time_Savings2__c, " \
                      "Adoptions_in_District__c, " \
                      "BillingStreet, " \
                      "BillingCity, " \
                      "BillingState, " \
                      "BillingPostalCode, " \
                      "BillingCountry, " \
                      "Address_Latitude__c, " \
                      "Address_Longitude__c," \
                      "Testimonial__c," \
                      "Testimonial_Name__c, " \
                      "Testimonial_Position__c, " \
                      "Number_of_Adoptions__c FROM Account WHERE RecordTypeId = '012U0000000MdzNIAS' AND K_I_P__c = True"
            district_response = sf.query_all(district_query)
            sf_districts = district_response['records']

            updated_schools = 0
            created_schools = 0
            for sf_district in sf_districts:
                school, created = School.objects.update_or_create(
                    salesforce_id=sf_district['Id'],
                    defaults={
                        'name':
                        sf_district['Name'],
                        'phone':
                        sf_district['Phone'],
                        'website':
                        sf_district['Website'],
                        'type':
                        sf_district['Type'],
                        'key_institutional_partner':
                        sf_district['K_I_P__c'],
                        'achieving_the_dream_school':
                        sf_district['Achieving_the_Dream_School__c'],
                        'hbcu':
                        sf_district['HBCU__c'],
                        'texas_higher_ed':
                        sf_district['Texas_Higher_Ed__c'],
                        'undergraduate_enrollment':
                        sf_district['Approximate_Enrollment__c'],
                        'pell_grant_recipients':
                        sf_district['Pell_Grant_Recipients__c'],
                        'percent_students_pell_grant':
                        sf_district['Students_Pell_Grant__c'],
                        'current_year_students':
                        sf_district['Students_Current_Year__c'],
                        'all_time_students':
                        sf_district['All_Time_Students2__c'],
                        'current_year_savings':
                        sf_district['Savings_Current_Year__c'],
                        'all_time_savings':
                        sf_district['All_Time_Savings2__c'],
                        'physical_country':
                        sf_district['BillingCountry'],
                        'physical_street':
                        sf_district['BillingStreet'],
                        'physical_city':
                        sf_district['BillingCity'],
                        'physical_state_province':
                        sf_district['BillingState'],
                        'physical_zip_postal_code':
                        sf_district['BillingPostalCode'],
                        'lat':
                        sf_district['Address_Latitude__c'],
                        'long':
                        sf_district['Address_Longitude__c'],
                        'testimonial':
                        sf_district['Testimonial__c'],
                        'testimonial_name':
                        sf_district['Testimonial_Name__c'],
                        'testimonial_position':
                        sf_district['Testimonial_Position__c']
                    },
                )
                school.save()
                if created:
                    created_schools = created_schools + 1
                else:
                    updated_schools = updated_schools + 1

            for sf_school in sf_schools:
                school, created = School.objects.update_or_create(
                    salesforce_id=sf_school['Id'],
                    defaults={
                        'name':
                        sf_school['Name'],
                        'phone':
                        sf_school['Phone'],
                        'website':
                        sf_school['Website'],
                        'type':
                        sf_school['Type'],
                        'key_institutional_partner':
                        sf_school['K_I_P__c'],
                        'achieving_the_dream_school':
                        sf_school['Achieving_the_Dream_School__c'],
                        'hbcu':
                        sf_school['HBCU__c'],
                        'texas_higher_ed':
                        sf_school['Texas_Higher_Ed__c'],
                        'undergraduate_enrollment':
                        sf_school['Approximate_Enrollment__c'],
                        'pell_grant_recipients':
                        sf_school['Pell_Grant_Recipients__c'],
                        'percent_students_pell_grant':
                        sf_school['Students_Pell_Grant__c'],
                        'current_year_students':
                        sf_school['Students_Current_Year__c'],
                        'all_time_students':
                        sf_school['All_Time_Students2__c'],
                        'current_year_savings':
                        sf_school['Savings_Current_Year__c'],
                        'all_time_savings':
                        sf_school['All_Time_Savings2__c'],
                        'physical_country':
                        sf_school['BillingCountry'],
                        'physical_street':
                        sf_school['BillingStreet'],
                        'physical_city':
                        sf_school['BillingCity'],
                        'physical_state_province':
                        sf_school['BillingState'],
                        'physical_zip_postal_code':
                        sf_school['BillingPostalCode'],
                        'lat':
                        sf_school['Address_Latitude__c'],
                        'long':
                        sf_school['Address_Longitude__c'],
                        'testimonial':
                        sf_school['Testimonial__c'],
                        'testimonial_name':
                        sf_school['Testimonial_Name__c'],
                        'testimonial_position':
                        sf_school['Testimonial_Position__c']
                    },
                )

                school.save()
                if created:
                    created_schools = created_schools + 1
                else:
                    updated_schools = updated_schools + 1

            response = self.style.SUCCESS(
                "Successfully updated {} schools, created {} schools.".format(
                    updated_schools, created_schools))
        self.stdout.write(response)
Beispiel #12
0
 def test_database_query(self):
     sf = SF()
     contact_info = sf.query("SELECT Id FROM Contact")
     self.assertIsNot(contact_info, None)
Beispiel #13
0
    def handle(self, *args, **options):
        with Salesforce() as sf:
            query = "SELECT Name, Phone, " \
                      "Website, " \
                      "Type, " \
                      "K_I_P__c, " \
                      "Achieving_the_Dream_School__c, " \
                      "HBCU__c, " \
                      "Texas_Higher_Ed__c, " \
                      "Approximate_Enrollment__c, " \
                      "Pell_Grant_Recipients__c, " \
                      "Students_Pell_Grant__c, " \
                      "Current_Students__c, " \
                      "All_Time_Students2__c, " \
                      "Current_Savings__c, " \
                      "All_Time_Savings2__c, " \
                      "BillingStreet, " \
                      "BillingCity, " \
                      "BillingState, " \
                      "BillingPostalCode, " \
                      "BillingCountry, " \
                      "Address_Latitude__c, " \
                      "Address_Longitude__c," \
                      "Testimonial__c," \
                      "Testimonial_Name__c, " \
                      "Testimonial_Position__c, " \
                      "Number_of_Adoptions__c FROM Account"
            response = sf.query_all(query)
            sf_schools = response['records']

            if sf_schools:
                School.objects.all().delete()

            updated_schools = 0
            for sf_school in sf_schools:
                if sf_school["Number_of_Adoptions__c"] > 0:
                    school, created = School.objects.update_or_create(
                        name=sf_school['Name'],
                        phone=sf_school['Phone'],
                        website=sf_school['Website'],
                        type=sf_school['Type'],
                        key_institutional_partner=sf_school['K_I_P__c'],
                        achieving_the_dream_school=sf_school[
                            'Achieving_the_Dream_School__c'],
                        hbcu=sf_school['HBCU__c'],
                        texas_higher_ed=sf_school['Texas_Higher_Ed__c'],
                        undergraduate_enrollment=sf_school[
                            'Approximate_Enrollment__c'],
                        pell_grant_recipients=sf_school[
                            'Pell_Grant_Recipients__c'],
                        percent_students_pell_grant=sf_school[
                            'Students_Pell_Grant__c'],
                        current_year_students=sf_school['Current_Students__c'],
                        all_time_students=sf_school['All_Time_Students2__c'],
                        current_year_savings=sf_school['Current_Savings__c'],
                        all_time_savings=sf_school['All_Time_Savings2__c'],
                        physical_country=sf_school['BillingCountry'],
                        physical_street=sf_school['BillingStreet'],
                        physical_city=sf_school['BillingCity'],
                        physical_state_province=sf_school['BillingState'],
                        physical_zip_postal_code=sf_school[
                            'BillingPostalCode'],
                        long=sf_school['Address_Latitude__c'],
                        lat=sf_school['Address_Longitude__c'],
                        testimonial=sf_school['Testimonial__c'],
                        testimonial_name=['Testimonial_Name__c'],
                        testimonial_position=['Testimonial_Position__c'])

                    school.save()
                    updated_schools = updated_schools + 1
            response = self.style.SUCCESS(
                "Successfully updated {} schools".format(updated_schools))
        self.stdout.write(response)
    def handle(self, *args, **options):
        with Salesforce() as sf:
            query = "SELECT " \
                    "Id, " \
                    "Name, " \
                    "Partner_Type__c, " \
                    "Books_Offered__c, " \
                    "Description, " \
                    "Rich_Description__c, " \
                    "short_partner_description__c, " \
                    "Website, " \
                    "Lead_Sharing__c, " \
                    "Verified_by_instructors__c, " \
                    "Integrated_with_OpenStax_content__c, " \
                    "Landing_page__c, " \
                    "Affordability_cost__c, " \
                    "Affordability_institutional__c, " \
                    "App_available__c, " \
                    "Adaptivity_adaptive_presentation__c, " \
                    "Adaptivity_affective_state__c, " \
                    "Adaptivity_breadth_and_depth__c, " \
                    "Adaptivity_customized_path__c, " \
                    "Adaptivity_instructor_control__c, " \
                    "Adaptivity_quantitative_randomization__c, " \
                    "Adaptivity_varied_level__c, " \
                    "Admin_calendar_links__c, " \
                    "Admin_online_submission__c, " \
                    "Admin_realtime_progress__c, " \
                    "Admin_shared_students__c, " \
                    "Admin_syllabus__c, " \
                    "Assignment_outside_resources__c, " \
                    "Assignment_editing__c, " \
                    "Assignment_multimedia__c, " \
                    "Assignment_multiple_quantitative__c, " \
                    "Assignment_pretest__c, " \
                    "Assignment_scientific_structures__c," \
                    "Assignment_summative_assessments__c, " \
                    "Autonomy_digital_badges__c, " \
                    "Autonomy_on_demand_extras__c, " \
                    "Autonomy_self_reflection__c, " \
                    "Collaboration_peer_feedback__c, " \
                    "Collaboration_peer_interaction__c, " \
                    "Collaboration_teacher_learner_contact__c, " \
                    "Collaboration_tutor__c, " \
                    "Content_batch_uploads__c, " \
                    "Content_resource_sharing__c, " \
                    "Content_sharing_among_courses__c, " \
                    "Customization_assessment_repository__c, " \
                    "Customization_create_learning_outcomes__c, " \
                    "Customization_reorder_content__c, " \
                    "Customization_reorder_learning_outcomes__c, " \
                    "Feedback_early_warning__c, " \
                    "Feedback_knowledge_gaps__c, " \
                    "Feedback_learner_progress_tasks__c, " \
                    "Feedback_multipart__c, " \
                    "Feedback_understanding__c, " \
                    "Formstack_URL__c, " \
                    "Grading_change_scores__c, " \
                    "Grading_class_and_student_level__c, " \
                    "Grading_group_work__c, " \
                    "Grading_learning_portfolio__c, " \
                    "Grading_rubric_based__c, " \
                    "Grading_tolerances_sig_fig__c, " \
                    "Interactivity_annotate__c, " \
                    "Interactivity_different_representations__c, " \
                    "Interactivity_gaming__c, " \
                    "Interactivity_previous_knowledge__c, " \
                    "Interactivity_simulations__c, " \
                    "Interactivity_varying_means__c, " \
                    "LMS_analytics__c, " \
                    "LMS_sends_grades__c, " \
                    "LMS_SSO__c, " \
                    "Measure_alternate_assessment__c, " \
                    "Measure_assessments_in_most__c, " \
                    "Measure_mapping__c, " \
                    "Reporting_competency__c, " \
                    "Reporting_student_workload__c, " \
                    "Scaffolding_hints__c, " \
                    "Scaffolding_learner_explanations__c, " \
                    "Scaffolding_mental_practice__c, " \
                    "Scaffolding_narrative__c, " \
                    "Scaffolding_social_intervention__c, " \
                    "Usability_design_orients_users__c, " \
                    "Usability_glossary__c, " \
                    "Usability_partial_progress__c, " \
                    "Accessibility_language_UI__c, " \
                    "Accessibility_language_content__c, " \
                    "Accessibility_VPAT__c, " \
                    "Accessibility_WCAG__c, " \
                    "Accessibility_Universal_Design__c, " \
                    "Instructional_level_K12__c, " \
                    "Online_teaching_peer_discussion__c, " \
                    "Online_teaching_lecture_streaming__c, " \
                    "Online_teaching_in_lecture__c, " \
                    "Online_teaching_asynchronous__c, " \
                    "Online_teaching_audio_video__c, " \
                    "Online_teaching_academic_integrity__c, " \
                    "Online_teaching_labs__c, " \
                    "International__c " \
                    "FROM Account WHERE RecordTypeId = '012U0000000MeAuIAK'"
            response = sf.query_all(query)
            sf_marketplace_partners = response['records']

            updated_partners = 0
            created_partners = 0
            partner_ids = []

            for partner in sf_marketplace_partners:
                partner_ids.append(partner['Id'])

                if partner['Affordability_cost__c']:
                    affordability_cost = partner[
                        'Affordability_cost__c'].replace(";", "; ")
                else:
                    affordability_cost = None

                try:
                    p = Partner.objects.get(salesforce_id=partner['Id'])
                    p.partner_name = partner['Name']
                    p.partner_type = partner['Partner_Type__c']
                    p.books = partner['Books_Offered__c']
                    p.rich_description = partner['Rich_Description__c']
                    p.partner_description = partner['Description']
                    p.short_partner_description = partner[
                        'short_partner_description__c']
                    p.partner_website = partner['Website']
                    p.lead_sharing = self.str2bool(partner['Lead_Sharing__c'])
                    p.landing_page = partner['Landing_page__c']
                    p.verified_by_instructor = self.str2bool(
                        partner['Verified_by_instructors__c'])
                    p.integrated = partner[
                        'Integrated_with_OpenStax_content__c']
                    p.affordability_cost = affordability_cost
                    p.affordability_institutional = self.str2bool(
                        partner['Affordability_Institutional__c'])
                    p.app_available = self.str2bool(
                        partner['App_available__c'])
                    p.adaptivity_adaptive_presentation = self.str2bool(
                        partner['Adaptivity_adaptive_presentation__c'])
                    p.adaptivity_affective_state = self.str2bool(
                        partner['Adaptivity_affective_state__c'])
                    p.adaptivity_breadth_and_depth = self.str2bool(
                        partner['Adaptivity_breadth_and_depth__c'])
                    p.adaptivity_customized_path = self.str2bool(
                        partner['Adaptivity_customized_path__c'])
                    p.adaptivity_instructor_control = self.str2bool(
                        partner['Adaptivity_instructor_control__c'])
                    p.adaptivity_quantitative_randomization = self.str2bool(
                        partner['Adaptivity_quantitative_randomization__c'])
                    p.adaptivity_varied_level = self.str2bool(
                        partner['Adaptivity_varied_level__c'])
                    p.admin_calendar_links = self.str2bool(
                        partner['Admin_calendar_links__c'])
                    p.admin_online_submission = self.str2bool(
                        partner['admin_online_submission__c'])
                    p.admin_realtime_progress = self.str2bool(
                        partner['Admin_realtime_progress__c'])
                    p.admin_shared_students = self.str2bool(
                        partner['Admin_shared_students__c'])
                    p.admin_syllabus = self.str2bool(
                        partner['Admin_Syllabus__c'])
                    p.assigment_outside_resources = self.str2bool(
                        partner['Assignment_outside_resources__c'])
                    p.assignment_editing = self.str2bool(
                        partner['Assignment_editing__c'])
                    p.assignment_multimedia = self.str2bool(
                        partner['Assignment_multimedia__c'])
                    p.assignment_multiple_quantitative = self.str2bool(
                        partner['Assignment_multiple_quantitative__c'])
                    p.assignment_pretest = self.str2bool(
                        partner['Assignment_pretest__c'])
                    p.assignment_scientific_structures = self.str2bool(
                        partner['Assignment_scientific_structures__c'])
                    p.assignment_summative_assessments = self.str2bool(
                        partner['Assignment_summative_assessments__c'])
                    p.autonomy_digital_badges = self.str2bool(
                        partner['Autonomy_digital_badges__c'])
                    p.autonomy_on_demand_extras = self.str2bool(
                        partner['Autonomy_on_demand_extras__c'])
                    p.autonomy_self_reflection = self.str2bool(
                        partner['Autonomy_self_reflection__c'])
                    p.collaboration_peer_feedback = self.str2bool(
                        partner['Collaboration_peer_feedback__c'])
                    p.collaboration_peer_interaction = self.str2bool(
                        partner['Collaboration_peer_interaction__c'])
                    p.collaboration_teacher_learner_contact = self.str2bool(
                        partner['Collaboration_teacher_learner_contact__c'])
                    p.collaboration_tutor = self.str2bool(
                        partner['Collaboration_tutor__c'])
                    p.content_batch_uploads = self.str2bool(
                        partner['Content_batch_uploads__c'])
                    p.content_resource_sharing = self.str2bool(
                        partner['Content_resource_sharing__c'])
                    p.content_sharing_among_courses = self.str2bool(
                        partner['Content_sharing_among_courses__c'])
                    p.customization_assessement_repository = self.str2bool(
                        partner['Customization_assessment_repository__c'])
                    p.customization_create_learning_outcomes = self.str2bool(
                        partner['Customization_create_learning_outcomes__c'])
                    p.customization_reorder_content = self.str2bool(
                        partner['Customization_reorder_content__c'])
                    p.customization_reorder_learning_outcomes = self.str2bool(
                        partner['Customization_reorder_learning_outcomes__c'])
                    p.feedback_early_warning = self.str2bool(
                        partner['Feedback_early_warning__c'])
                    p.feedback_knowledge_gaps = self.str2bool(
                        partner['Feedback_knowledge_gaps__c'])
                    p.feedback_learner_progress_tasks = self.str2bool(
                        partner['Feedback_learner_progress_tasks__c'])
                    p.feedback_multipart = self.str2bool(
                        partner['Feedback_multipart__c'])
                    p.feedback_understanding = self.str2bool(
                        partner['Feedback_understanding__c'])
                    p.formstack_url = partner['Formstack_URL__c']
                    p.grading_change_scores = self.str2bool(
                        partner['Grading_change_scores__c'])
                    p.grading_class_and_student_level = self.str2bool(
                        partner['Grading_class_and_student_level__c'])
                    p.grading_group_work = self.str2bool(
                        partner['Grading_group_work__c'])
                    p.grading_learning_portfolio = self.str2bool(
                        partner['Grading_learning_portfolio__c'])
                    p.grading_rubric_based = self.str2bool(
                        partner['Grading_rubric_based__c'])
                    p.grading_tolerances_sig_fig = self.str2bool(
                        partner['Grading_tolerances_sig_fig__c'])
                    p.interactivity_annotate = self.str2bool(
                        partner['Interactivity_annotate__c'])
                    p.interactivity_different_representations = self.str2bool(
                        partner['Interactivity_different_representations__c'])
                    p.interactivity_gaming = self.str2bool(
                        partner['Interactivity_gaming__c'])
                    p.interactivity_previous_knowledge = self.str2bool(
                        partner['Interactivity_previous_knowledge__c'])
                    p.interactivity_simulations = self.str2bool(
                        partner['Interactivity_simulations__c'])
                    p.interactivity_varying_means = self.str2bool(
                        partner['Interactivity_varying_means__c'])
                    p.LMS_analytics = self.str2bool(
                        partner['LMS_analytics__c'])
                    p.LMS_sends_grades = self.str2bool(
                        partner['LMS_sends_grades__c'])
                    p.LMS_SSO = self.str2bool(partner['LMS_SSO__c'])
                    p.measure_alternate_assessment = self.str2bool(
                        partner['Measure_alternate_assessment__c'])
                    p.measure_assessments_in_most = self.str2bool(
                        partner['Measure_assessments_in_most__c'])
                    p.measure_mapping = self.str2bool(
                        partner['Measure_mapping__c'])
                    p.reporting_competency = self.str2bool(
                        partner['Reporting_competency__c'])
                    p.reporting_student_workload = self.str2bool(
                        partner['Reporting_student_workload__c'])
                    p.scaffolding_hints = self.str2bool(
                        partner['Scaffolding_hints__c'])
                    p.scaffolding_learner_explanations = self.str2bool(
                        partner['Scaffolding_learner_explanations__c'])
                    p.scaffolding_mental_practice = self.str2bool(
                        partner['Scaffolding_mental_practice__c'])
                    p.scaffolding_narrative = self.str2bool(
                        partner['Scaffolding_narrative__c'])
                    p.scaffolding_social_intervention = self.str2bool(
                        partner['Scaffolding_social_intervention__c'])
                    p.usability_design_orients_users = self.str2bool(
                        partner['Usability_design_orients_users__c'])
                    p.usability_glossary = self.str2bool(
                        partner['Usability_glossary__c'])
                    p.usability_partial_progress = self.str2bool(
                        partner['Usability_partial_progress__c'])
                    p.accessibility_language_UI = self.str2bool(
                        partner['Accessibility_language_UI__c'])
                    p.accessibility_language_content = self.str2bool(
                        partner['Accessibility_language_content__c'])
                    p.accessibility_VPAT = self.str2bool(
                        partner['Accessibility_VPAT__c'])
                    p.accessibility_WCAG = self.str2bool(
                        partner['Accessibility_WCAG__c'])
                    p.accessibility_universal_design = self.str2bool(
                        partner['Accessibility_Universal_Design__c'])
                    p.instructional_level_k12 = self.str2bool(
                        partner['Instructional_level_K12__c'])
                    p.online_teaching_peer_discussion = self.str2bool(
                        partner['Online_teaching_peer_discussion__c'])
                    p.online_teaching_lecture_streaming = self.str2bool(
                        partner['Online_teaching_lecture_streaming__c'])
                    p.online_teaching_in_lecture = self.str2bool(
                        partner['Online_teaching_in_lecture__c'])
                    p.online_teaching_asynchronous = self.str2bool(
                        partner['Online_teaching_asynchronous__c'])
                    p.online_teaching_audio_video = self.str2bool(
                        partner['Online_teaching_audio_video__c'])
                    p.online_teaching_academic_integrity = self.str2bool(
                        partner['Online_teaching_academic_integrity__c'])
                    p.online_teaching_teaching_labs = self.str2bool(
                        partner['Online_teaching_labs__c'])
                    p.international = self.str2bool(
                        partner['International__c'])
                    p.save()
                    updated_partners = updated_partners + 1
                except Partner.DoesNotExist:
                    partner = Partner.objects.create(
                        salesforce_id=partner['Id'],
                        partner_name=partner['Name'],
                        partner_type=partner['Partner_Type__c'],
                        books=partner['Books_Offered__c'],
                        rich_description=partner['Rich_Description__c'],
                        partner_description=partner['Description'],
                        short_partner_description=partner[
                            'short_partner_description__c'],
                        partner_website=partner['Website'],
                        lead_sharing=self.str2bool(partner['Lead_Sharing__c']),
                        landing_page=partner['Landing_page__c'],
                        verified_by_instructor=self.str2bool(
                            partner['Verified_by_instructors__c']),
                        integrated=partner[
                            'Integrated_with_OpenStax_content__c'],
                        affordability_cost=partner['Affordability_cost__c'],
                        affordability_institutional=self.str2bool(
                            partner['Affordability_Institutional__c']),
                        app_available=self.str2bool(
                            partner['App_available__c']),
                        adaptivity_adaptive_presentation=self.str2bool(
                            partner['Adaptivity_adaptive_presentation__c']),
                        adaptivity_affective_state=self.str2bool(
                            partner['Adaptivity_affective_state__c']),
                        adaptivity_breadth_and_depth=self.str2bool(
                            partner['Adaptivity_breadth_and_depth__c']),
                        adaptivity_customized_path=self.str2bool(
                            partner['Adaptivity_customized_path__c']),
                        adaptivity_instructor_control=self.str2bool(
                            partner['Adaptivity_instructor_control__c']),
                        adaptivity_quantitative_randomization=self.str2bool(
                            partner['Adaptivity_quantitative_randomization__c']
                        ),
                        adaptivity_varied_level=self.str2bool(
                            partner['Adaptivity_varied_level__c']),
                        admin_calendar_links=self.str2bool(
                            partner['Admin_calendar_links__c']),
                        admin_online_submission=self.str2bool(
                            partner['admin_online_submission__c']),
                        admin_realtime_progress=self.str2bool(
                            partner['Admin_realtime_progress__c']),
                        admin_shared_students=self.str2bool(
                            partner['Admin_shared_students__c']),
                        admin_syllabus=self.str2bool(
                            partner['Admin_Syllabus__c']),
                        assigment_outside_resources=self.str2bool(
                            partner['Assignment_outside_resources__c']),
                        assignment_editing=self.str2bool(
                            partner['Assignment_editing__c']),
                        assignment_multimedia=self.str2bool(
                            partner['Assignment_multimedia__c']),
                        assignment_multiple_quantitative=self.str2bool(
                            partner['Assignment_multiple_quantitative__c']),
                        assignment_pretest=self.str2bool(
                            partner['Assignment_pretest__c']),
                        assignment_scientific_structures=self.str2bool(
                            partner['Assignment_scientific_structures__c']),
                        assignment_summative_assessments=self.str2bool(
                            partner['Assignment_summative_assessments__c']),
                        autonomy_digital_badges=self.str2bool(
                            partner['Autonomy_digital_badges__c']),
                        autonomy_on_demand_extras=self.str2bool(
                            partner['Autonomy_on_demand_extras__c']),
                        autonomy_self_reflection=self.str2bool(
                            partner['Autonomy_self_reflection__c']),
                        collaboration_peer_feedback=self.str2bool(
                            partner['Collaboration_peer_feedback__c']),
                        collaboration_peer_interaction=self.str2bool(
                            partner['Collaboration_peer_interaction__c']),
                        collaboration_teacher_learner_contact=self.str2bool(
                            partner['Collaboration_teacher_learner_contact__c']
                        ),
                        collaboration_tutor=self.str2bool(
                            partner['Collaboration_tutor__c']),
                        content_batch_uploads=self.str2bool(
                            partner['Content_batch_uploads__c']),
                        content_resource_sharing=self.str2bool(
                            partner['Content_resource_sharing__c']),
                        content_sharing_among_courses=self.str2bool(
                            partner['Content_sharing_among_courses__c']),
                        customization_assessement_repository=self.str2bool(
                            partner['Customization_assessment_repository__c']),
                        customization_create_learning_outcomes=self.str2bool(
                            partner[
                                'Customization_create_learning_outcomes__c']),
                        customization_reorder_content=self.str2bool(
                            partner['Customization_reorder_content__c']),
                        customization_reorder_learning_outcomes=self.str2bool(
                            partner[
                                'Customization_reorder_learning_outcomes__c']),
                        feedback_early_warning=self.str2bool(
                            partner['Feedback_early_warning__c']),
                        feedback_knowledge_gaps=self.str2bool(
                            partner['Feedback_knowledge_gaps__c']),
                        feedback_learner_progress_tasks=self.str2bool(
                            partner['Feedback_learner_progress_tasks__c']),
                        feedback_multipart=self.str2bool(
                            partner['Feedback_multipart__c']),
                        feedback_understanding=self.str2bool(
                            partner['Feedback_understanding__c']),
                        formstack_url=partner['Formstack_URL__c'],
                        grading_change_scores=self.str2bool(
                            partner['Grading_change_scores__c']),
                        grading_class_and_student_level=self.str2bool(
                            partner['Grading_class_and_student_level__c']),
                        grading_group_work=self.str2bool(
                            partner['Grading_group_work__c']),
                        grading_learning_portfolio=self.str2bool(
                            partner['Grading_learning_portfolio__c']),
                        grading_rubric_based=self.str2bool(
                            partner['Grading_rubric_based__c']),
                        grading_tolerances_sig_fig=self.str2bool(
                            partner['Grading_tolerances_sig_fig__c']),
                        interactivity_annotate=self.str2bool(
                            partner['Interactivity_annotate__c']),
                        interactivity_different_representations=self.str2bool(
                            partner[
                                'Interactivity_different_representations__c']),
                        interactivity_gaming=self.str2bool(
                            partner['Interactivity_gaming__c']),
                        interactivity_previous_knowledge=self.str2bool(
                            partner['Interactivity_previous_knowledge__c']),
                        interactivity_simulations=self.str2bool(
                            partner['Interactivity_simulations__c']),
                        interactivity_varying_means=self.str2bool(
                            partner['Interactivity_varying_means__c']),
                        LMS_analytics=self.str2bool(
                            partner['LMS_analytics__c']),
                        LMS_sends_grades=self.str2bool(
                            partner['LMS_sends_grades__c']),
                        LMS_SSO=self.str2bool(partner['LMS_SSO__c']),
                        measure_alternate_assessment=self.str2bool(
                            partner['Measure_alternate_assessment__c']),
                        measure_assessments_in_most=self.str2bool(
                            partner['Measure_assessments_in_most__c']),
                        measure_mapping=self.str2bool(
                            partner['Measure_mapping__c']),
                        reporting_competency=self.str2bool(
                            partner['Reporting_competency__c']),
                        reporting_student_workload=self.str2bool(
                            partner['Reporting_student_workload__c']),
                        scaffolding_hints=self.str2bool(
                            partner['Scaffolding_hints__c']),
                        scaffolding_learner_explanations=self.str2bool(
                            partner['Scaffolding_learner_explanations__c']),
                        scaffolding_mental_practice=self.str2bool(
                            partner['Scaffolding_mental_practice__c']),
                        scaffolding_narrative=self.str2bool(
                            partner['Scaffolding_narrative__c']),
                        scaffolding_social_intervention=self.str2bool(
                            partner['Scaffolding_social_intervention__c']),
                        usability_design_orients_users=self.str2bool(
                            partner['Usability_design_orients_users__c']),
                        usability_glossary=self.str2bool(
                            partner['Usability_glossary__c']),
                        usability_partial_progress=self.str2bool(
                            partner['Usability_partial_progress__c']),
                        accessibility_language_UI=self.str2bool(
                            partner['Accessibility_language_UI__c']),
                        accessibility_language_content=self.str2bool(
                            partner['Accessibility_language_content__c']),
                        accessibility_VPAT=self.str2bool(
                            partner['Accessibility_VPAT__c']),
                        accessibility_WCAG=self.str2bool(
                            partner['Accessibility_WCAG__c']),
                        accessibility_universal_design=self.str2bool(
                            partner['Accessibility_Universal_Design__c']),
                        instructional_level_k12=self.str2bool(
                            partner['Instructional_level_K12__c']),
                        online_teaching_peer_discussion=self.str2bool(
                            partner['Online_teaching_peer_discussion__c']),
                        online_teaching_lecture_streaming=self.str2bool(
                            partner['Online_teaching_lecture_streaming__c']),
                        online_teaching_in_lecture=self.str2bool(
                            partner['Online_teaching_in_lecture__c']),
                        online_teaching_asynchronous=self.str2bool(
                            partner['Online_teaching_asynchronous__c']),
                        online_teaching_audio_video=self.str2bool(
                            partner['Online_teaching_audio_video__c']),
                        online_teaching_academic_integrity=self.str2bool(
                            partner['Online_teaching_academic_integrity__c']),
                        online_teaching_teaching_labs=self.str2bool(
                            partner['Online_teaching_labs__c']),
                        international=self.str2bool(
                            partner['International__c']),
                    )
                    created_partners = created_partners + 1

            # remove partners that have been deleted from Salesforce
            stale_partners = Partner.objects.exclude(
                salesforce_id__in=partner_ids)
            stale_partners.delete()

            response = self.style.SUCCESS(
                "Successfully updated {} partners, created {} partners.".
                format(updated_partners, created_partners))
        self.stdout.write(response)
Beispiel #15
0
    def handle(self, *args, **options):
        with Salesforce() as sf:
            query = "SELECT " \
                    "Id, " \
                    "Name, " \
                    "Partner_Type__c, " \
                    "Books_Offered__c, " \
                    "Description, " \
                    "Rich_Description__c, " \
                    "short_partner_description__c, " \
                    "Website, " \
                    "Lead_Sharing__c, " \
                    "Verified_by_instructors__c, " \
                    "Integrated_with_OpenStax_content__c, " \
                    "Landing_page__c, " \
                    "Affordability_cost__c, " \
                    "Affordability_institutional__c, " \
                    "App_available__c, " \
                    "Adaptivity_adaptive_presentation__c, " \
                    "Adaptivity_affective_state__c, " \
                    "Adaptivity_breadth_and_depth__c, " \
                    "Adaptivity_customized_path__c, " \
                    "Adaptivity_instructor_control__c, " \
                    "Adaptivity_quantitative_randomization__c, " \
                    "Adaptivity_varied_level__c, " \
                    "Admin_calendar_links__c, " \
                    "Admin_online_submission__c, " \
                    "Admin_realtime_progress__c, " \
                    "Admin_shared_students__c, " \
                    "Admin_syllabus__c, " \
                    "Assignment_outside_resources__c, " \
                    "Assignment_editing__c, " \
                    "Assignment_multimedia__c, " \
                    "Assignment_multiple_quantitative__c, " \
                    "Assignment_pretest__c, " \
                    "Assignment_scientific_structures__c," \
                    "Assignment_summative_assessments__c, " \
                    "Autonomy_digital_badges__c, " \
                    "Autonomy_on_demand_extras__c, " \
                    "Autonomy_self_reflection__c, " \
                    "Collaboration_peer_feedback__c, " \
                    "Collaboration_peer_interaction__c, " \
                    "Collaboration_teacher_learner_contact__c, " \
                    "Collaboration_tutor__c, " \
                    "Content_batch_uploads__c, " \
                    "Content_resource_sharing__c, " \
                    "Content_sharing_among_courses__c, " \
                    "Customization_assessment_repository__c, " \
                    "Customization_create_learning_outcomes__c, " \
                    "Customization_reorder_content__c, " \
                    "Customization_reorder_learning_outcomes__c, " \
                    "Feedback_early_warning__c, " \
                    "Feedback_knowledge_gaps__c, " \
                    "Feedback_learner_progress_tasks__c, " \
                    "Feedback_multipart__c, " \
                    "Feedback_understanding__c, " \
                    "Formstack_URL__c, " \
                    "Grading_change_scores__c, " \
                    "Grading_class_and_student_level__c, " \
                    "Grading_group_work__c, " \
                    "Grading_learning_portfolio__c, " \
                    "Grading_rubric_based__c, " \
                    "Grading_tolerances_sig_fig__c, " \
                    "Interactivity_annotate__c, " \
                    "Interactivity_different_representations__c, " \
                    "Interactivity_gaming__c, " \
                    "Interactivity_previous_knowledge__c, " \
                    "Interactivity_simulations__c, " \
                    "Interactivity_varying_means__c, " \
                    "LMS_analytics__c, " \
                    "LMS_sends_grades__c, " \
                    "LMS_SSO__c, " \
                    "Measure_alternate_assessment__c, " \
                    "Measure_assessments_in_most__c, " \
                    "Measure_mapping__c, " \
                    "Reporting_competency__c, " \
                    "Reporting_student_workload__c, " \
                    "Scaffolding_hints__c, " \
                    "Scaffolding_learner_explanations__c, " \
                    "Scaffolding_mental_practice__c, " \
                    "Scaffolding_narrative__c, " \
                    "Scaffolding_social_intervention__c, " \
                    "Usability_design_orients_users__c, " \
                    "Usability_glossary__c, " \
                    "Usability_partial_progress__c, " \
                    "Accessibility_language_UI__c, " \
                    "Accessibility_language_content__c, " \
                    "Accessibility_VPAT__c, " \
                    "Accessibility_WCAG__c, " \
                    "Accessibility_Universal_Design__c " \
                    "FROM Account WHERE RecordTypeId = '012U0000000MeAuIAK'"
            response = sf.query_all(query)
            sf_marketplace_partners = response['records']

            updated_partners = 0
            created_partners = 0
            pprint(sf_marketplace_partners[3])
            for partner in sf_marketplace_partners:
                partner, created = Partner.objects.update_or_create(
                    salesforce_id=partner['Id'],
                    defaults={
                        'partner_name':
                        partner['Name'],
                        'partner_type':
                        partner['Partner_Type__c'],
                        'books':
                        partner['Books_Offered__c'],
                        'rich_description':
                        partner['Rich_Description__c'],
                        'partner_description':
                        partner['Description'],
                        'short_partner_description':
                        partner['short_partner_description__c'],
                        'partner_website':
                        partner['Website'],
                        'lead_sharing':
                        self.str2bool(partner['Lead_Sharing__c']),
                        'landing_page':
                        partner['Landing_page__c'],
                        'verified_by_instructor':
                        self.str2bool(partner['Verified_by_instructors__c']),
                        'integrated':
                        partner['Integrated_with_OpenStax_content__c'],
                        'affordability_cost':
                        partner['Affordability_cost__c'],
                        'affordability_institutional':
                        self.str2bool(
                            partner['Affordability_Institutional__c']),
                        'app_available':
                        self.str2bool(partner['App_available__c']),
                        'adaptivity_adaptive_presentation':
                        self.str2bool(
                            partner['Adaptivity_adaptive_presentation__c']),
                        'adaptivity_affective_state':
                        self.str2bool(
                            partner['Adaptivity_affective_state__c']),
                        'adaptivity_breadth_and_depth':
                        self.str2bool(
                            partner['Adaptivity_breadth_and_depth__c']),
                        'adaptivity_customized_path':
                        self.str2bool(
                            partner['Adaptivity_customized_path__c']),
                        'adaptivity_instructor_control':
                        self.str2bool(
                            partner['Adaptivity_instructor_control__c']),
                        'adaptivity_quantitative_randomization':
                        self.str2bool(
                            partner['Adaptivity_quantitative_randomization__c']
                        ),
                        'adaptivity_varied_level':
                        self.str2bool(partner['Adaptivity_varied_level__c']),
                        'admin_calendar_links':
                        self.str2bool(partner['Admin_calendar_links__c']),
                        'admin_online_submission':
                        self.str2bool(partner['admin_online_submission__c']),
                        'admin_realtime_progress':
                        self.str2bool(partner['Admin_realtime_progress__c']),
                        'admin_shared_students':
                        self.str2bool(partner['Admin_shared_students__c']),
                        'admin_syllabus':
                        self.str2bool(partner['Admin_Syllabus__c']),
                        'assigment_outside_resources':
                        self.str2bool(
                            partner['Assignment_outside_resources__c']),
                        'assignment_editing':
                        self.str2bool(partner['Assignment_editing__c']),
                        'assignment_multimedia':
                        self.str2bool(partner['Assignment_multimedia__c']),
                        'assignment_multiple_quantitative':
                        self.str2bool(
                            partner['Assignment_multiple_quantitative__c']),
                        'assignment_pretest':
                        self.str2bool(partner['Assignment_pretest__c']),
                        'assignment_scientific_structures':
                        self.str2bool(
                            partner['Assignment_scientific_structures__c']),
                        'assignment_summative_assessments':
                        self.str2bool(
                            partner['Assignment_summative_assessments__c']),
                        'autonomy_digital_badges':
                        self.str2bool(partner['Autonomy_digital_badges__c']),
                        'autonomy_on_demand_extras':
                        self.str2bool(partner['Autonomy_on_demand_extras__c']),
                        'autonomy_self_reflection':
                        self.str2bool(partner['Autonomy_self_reflection__c']),
                        'collaboration_peer_feedback':
                        self.str2bool(
                            partner['Collaboration_peer_feedback__c']),
                        'collaboration_peer_interaction':
                        self.str2bool(
                            partner['Collaboration_peer_interaction__c']),
                        'collaboration_teacher_learner_contact':
                        self.str2bool(
                            partner['Collaboration_teacher_learner_contact__c']
                        ),
                        'collaboration_tutor':
                        self.str2bool(partner['Collaboration_tutor__c']),
                        'content_batch_uploads':
                        self.str2bool(partner['Content_batch_uploads__c']),
                        'content_resource_sharing':
                        self.str2bool(partner['Content_resource_sharing__c']),
                        'content_sharing_among_courses':
                        self.str2bool(
                            partner['Content_sharing_among_courses__c']),
                        'customization_assessement_repository':
                        self.str2bool(
                            partner['Customization_assessment_repository__c']),
                        'customization_create_learning_outcomes':
                        self.str2bool(partner[
                            'Customization_create_learning_outcomes__c']),
                        'customization_reorder_content':
                        self.str2bool(
                            partner['Customization_reorder_content__c']),
                        'customization_reorder_learning_outcomes':
                        self.str2bool(partner[
                            'Customization_reorder_learning_outcomes__c']),
                        'feedback_early_warning':
                        self.str2bool(partner['Feedback_early_warning__c']),
                        'feedback_knowledge_gaps':
                        self.str2bool(partner['Feedback_knowledge_gaps__c']),
                        'feedback_learner_progress_tasks':
                        self.str2bool(
                            partner['Feedback_learner_progress_tasks__c']),
                        'feedback_multipart':
                        self.str2bool(partner['Feedback_multipart__c']),
                        'feedback_understanding':
                        self.str2bool(partner['Feedback_understanding__c']),
                        'formstack_url':
                        partner['Formstack_URL__c'],
                        'grading_change_scores':
                        self.str2bool(partner['Grading_change_scores__c']),
                        'grading_class_and_student_level':
                        self.str2bool(
                            partner['Grading_class_and_student_level__c']),
                        'grading_group_work':
                        self.str2bool(partner['Grading_group_work__c']),
                        'grading_learning_portfolio':
                        self.str2bool(
                            partner['Grading_learning_portfolio__c']),
                        'grading_rubric_based':
                        self.str2bool(partner['Grading_rubric_based__c']),
                        'grading_tolerances_sig_fig':
                        self.str2bool(
                            partner['Grading_tolerances_sig_fig__c']),
                        'interactivity_annotate':
                        self.str2bool(partner['Interactivity_annotate__c']),
                        'interactivity_different_representations':
                        self.str2bool(partner[
                            'Interactivity_different_representations__c']),
                        'interactivity_gaming':
                        self.str2bool(partner['Interactivity_gaming__c']),
                        'interactivity_previous_knowledge':
                        self.str2bool(
                            partner['Interactivity_previous_knowledge__c']),
                        'interactivity_simulations':
                        self.str2bool(partner['Interactivity_simulations__c']),
                        'interactivity_varying_means':
                        self.str2bool(
                            partner['Interactivity_varying_means__c']),
                        'LMS_analytics':
                        self.str2bool(partner['LMS_analytics__c']),
                        'LMS_sends_grades':
                        self.str2bool(partner['LMS_sends_grades__c']),
                        'LMS_SSO':
                        self.str2bool(partner['LMS_SSO__c']),
                        'measure_alternate_assessment':
                        self.str2bool(
                            partner['Measure_alternate_assessment__c']),
                        'measure_assessments_in_most':
                        self.str2bool(
                            partner['Measure_assessments_in_most__c']),
                        'measure_mapping':
                        self.str2bool(partner['Measure_mapping__c']),
                        'reporting_competency':
                        self.str2bool(partner['Reporting_competency__c']),
                        'reporting_student_workload':
                        self.str2bool(
                            partner['Reporting_student_workload__c']),
                        'scaffolding_hints':
                        self.str2bool(partner['Scaffolding_hints__c']),
                        'scaffolding_learner_explanations':
                        self.str2bool(
                            partner['Scaffolding_learner_explanations__c']),
                        'scaffolding_mental_practice':
                        self.str2bool(
                            partner['Scaffolding_mental_practice__c']),
                        'scaffolding_narrative':
                        self.str2bool(partner['Scaffolding_narrative__c']),
                        'scaffolding_social_intervention':
                        self.str2bool(
                            partner['Scaffolding_social_intervention__c']),
                        'usability_design_orients_users':
                        self.str2bool(
                            partner['Usability_design_orients_users__c']),
                        'usability_glossary':
                        self.str2bool(partner['Usability_glossary__c']),
                        'usability_partial_progress':
                        self.str2bool(
                            partner['Usability_partial_progress__c']),
                        'accessibility_language_UI':
                        self.str2bool(partner['Accessibility_language_UI__c']),
                        'accessibility_language_content':
                        self.str2bool(
                            partner['Accessibility_language_content__c']),
                        'accessibility_VPAT':
                        self.str2bool(partner['Accessibility_VPAT__c']),
                        'accessibility_WCAG':
                        self.str2bool(partner['Accessibility_WCAG__c']),
                        'accessibility_universal_design':
                        self.str2bool(
                            partner['Accessibility_Universal_Design__c']),
                    },
                )
                partner.save()
                if created:
                    created_partners = created_partners + 1
                else:
                    updated_partners = updated_partners + 1

            response = self.style.SUCCESS(
                "Successfully updated {} partners, created {} partners.".
                format(updated_partners, created_partners))
        self.stdout.write(response)
Beispiel #16
0
    def handle(self, *args, **options):
        with Salesforce() as sf:

            # To update the existing reviews with Partner responses and approved reviews.
            command = "Select Id, Status__c, Approved_Customer_Review__c, Pending_Customer_Review__c, Partner_Response__c, Partner_Response_Date__c, Partner__c, Contact__c, Score__c, OS_Accounts_ID__c FROM Partner_Review__c WHERE Status__c = 'Approved' OR Status__c = 'Responded'"
            response = sf.query_all(command)
            sf_reviews = response['records']

            for record in sf_reviews:
                try:
                    review = PartnerReview.objects.get(review_salesforce_id=record['Id'])
                    if review.status != 'Edited':
                        review.review = record['Approved_Customer_Review__c']
                        review.partner_response = record['Partner_Response__c']
                        review.partner_response_date = record['Partner_Response_Date__c']
                        review.status = 'Approved'
                        review.save()
                except PartnerReview.DoesNotExist:
                    print('Review does not exist for SF ID: {}'.format(record['Id']))

            # Update rejected reviews
            command = "Select Id, Status__c, Approved_Customer_Review__c, Pending_Customer_Review__c, Partner_Response__c, Partner_Response_Date__c, Partner__c, Contact__c, Score__c, OS_Accounts_ID__c FROM Partner_Review__c WHERE Status__c = 'Rejected'"
            response = sf.query_all(command)
            sf_reviews = response['records']

            for record in sf_reviews:
                try:
                    review = PartnerReview.objects.get(review_salesforce_id=record['Id'])
                    review.status = 'Rejected'
                    review.save()
                except PartnerReview.DoesNotExist:
                    print('Review does not exist for SF ID: {}'.format(record['Id']))


            # If a review does not have a Salesforce ID, it must be new. We'll upload those to SF and assign a SF ID.
            new_reviews = PartnerReview.objects.filter(review_salesforce_id__isnull=True)
            for review in new_reviews:
                data = {
                    'Status__c': 'New',
                    'Pending_Customer_Review__c': review.review,
                    'Partner__c': review.partner.salesforce_id,
                    'OS_Accounts_ID__c': review.submitted_by_account_id,
                    'Score__c': review.rating,
                }
                try:
                    response = sf.Partner_Review__c.create(data)
                    review.review_salesforce_id = response['id']
                    review.save()
                except SalesforceGeneralError:
                    print('Failed to create review in Salesforce - are you sure the partner exists?')



            # If a review is in the Edited state, it needs to be reuploaded to SF and set to 'New'
            update_reviews = PartnerReview.objects.filter(status='Edited')
            for review in update_reviews:
                data = {
                    'Status__c': 'New',
                    'Pending_Customer_Review__c': review.review,
                    'OS_Accounts_ID__c': review.submitted_by_account_id,
                    'Score__c': review.rating,
                }
                try:
                    response = sf.Partner_Review__c.update(data=data, record_id=review.review_salesforce_id)
                    review.status = 'Awaiting Approval'
                    review.save()
                except SalesforceGeneralError:
                    print('Failed to update review in Salesforce')

            # Finally, if a review was deleted by a user, let's delete it from Salesforce.
            reviews_to_delete = PartnerReview.objects.filter(status='Deleted')
            for review in reviews_to_delete:
                if review.review_salesforce_id:
                    sf.Partner_Review__c.delete(review.review_salesforce_id)
                review.delete()


            invalidate_cloudfront_caches()
            response = self.style.SUCCESS("Successfully updated partner reviews")
        self.stdout.write(response)