def save(self): data = self.cleaned_data result = basket.subscribe( data['email'], self.newsletters(), format=data['fmt'], country=data['country'], welcome_message='Student_Ambassadors_Welcome', source_url=data['source_url'], sync='Y') data = { 'FIRST_NAME': data['first_name'], 'LAST_NAME': data['last_name'], 'STUDENTS_CURRENT_STATUS': data['status'], 'STUDENTS_SCHOOL': data['school'], 'STUDENTS_GRAD_YEAR': data['grad_year'], 'STUDENTS_MAJOR': data['major'], 'COUNTRY_': data['country'], 'STUDENTS_CITY': data['city'], 'STUDENTS_ALLOW_SHARE': data['share_information'], } request('post', 'custom_update_student_ambassadors', token=result['token'], data=data)
def update_basket_phonebook_task(user_pk): """ Create or update profile information in the Exact Target PHONEBOOK data extension about the user. """ instance = User.objects.get(pk=user_pk).userprofile email = instance.user.email if not BASKET_ENABLED or not instance.is_vouched: return data = {} # What groups is the user in? user_group_pks = instance.groups.all().values_list('pk', flat=True) # FIXME: This will need changing for bug 936569 for group in Group.objects.exclude(steward=None): name = group.name.upper().replace(' ', '_') data[name] = 'Y' if group.id in user_group_pks else 'N' # User location if known if instance.country: data['country'] = instance.country if instance.city: data['city'] = instance.city # We need their token to do the update token = instance.basket_token if not token: msg = 'Cannot find user in Basket' try: token = instance.lookup_basket_token() except (requests.exceptions.RequestException, basket.BasketException) as exception: msg = exception.message if not token: # Either user not found or an exception occurred. # Retry either way - basket might still be in the process of setting up the user, # or else we got an exception and it might work next time. try: update_basket_phonebook_task.retry() except (MaxRetriesExceededError, basket.BasketException): _email_basket_managers('update_phonebook', email, msg) return # Remember the token # Since UserProfile.save() will trigger another update_basket_task # via a post-save signal, avoid calling save() from models import UserProfile UserProfile.objects.filter(user__email=email).update(basket_token=token) # We have a token, proceed with the update try: request('post', 'custom_update_phonebook', token=token, data=data) except (requests.exceptions.RequestException, basket.BasketException) as exception: try: update_basket_phonebook_task.retry() except (MaxRetriesExceededError, basket.BasketException): _email_basket_managers('update_phonebook', email, exception.message)
def update_basket_task(instance_id): """Update Basket Task. This task subscribes a user to Basket, if not already subscribed and then updates his data on the Phonebook DataExtension. The task retries on failure at most BASKET_TASK_MAX_RETRIES times and if it finally doesn't complete successfully, it emails the settings.BASKET_MANAGERS with details. """ from models import UserProfile instance = UserProfile.objects.get(pk=instance_id) if not BASKET_ENABLED or not instance.is_vouched: return data = {} for group in Group.objects.exclude(steward=None): name = group.name.upper().replace(' ', '_') data[name] = 'N' if instance.groups.filter(pk=group.id).exists(): data[name] = 'Y' if instance.country: data['country'] = instance.country if instance.city: data['city'] = instance.city try: if not instance.basket_token: result = basket.subscribe(instance.user.email, settings.BASKET_NEWSLETTER, trigger_welcome='N') instance.basket_token = result['token'] instance.save() request('post', 'custom_update_phonebook', token=instance.basket_token, data=data) except (requests.exceptions.RequestException, basket.BasketException), exception: try: update_basket_task.retry() except (MaxRetriesExceededError, basket.BasketException): _email_basket_managers('subscribe', instance.user.email, exception.message)
def update_basket_task(instance_id): """Update Basket Task. This task subscribes a user to Basket, if not already subscribed and then updates his data on the Phonebook DataExtension. The task retries on failure at most BASKET_TASK_MAX_RETRIES times and if it finally doesn't complete successfully, it emails the settings.BASKET_MANAGERS with details. """ from models import UserProfile instance = UserProfile.objects.get(pk=instance_id) if not BASKET_ENABLED or not instance.is_vouched: return data = {} for group in Group.objects.exclude(steward=None): name = group.name.upper().replace(' ', '_') data[name] = 'N' if instance.groups.filter(pk=group.id).exists(): data[name] = 'Y' if instance.country: data['country'] = instance.country if instance.city: data['city'] = instance.city token = instance.basket_token try: if not token: result = basket.subscribe(instance.user.email, settings.BASKET_NEWSLETTER, trigger_welcome='N') token = result['token'] (UserProfile.objects .filter(pk=instance_id).update(basket_token=token)) request('post', 'custom_update_phonebook', token=token, data=data) except (requests.exceptions.RequestException, basket.BasketException), exception: try: update_basket_task.retry() except (MaxRetriesExceededError, basket.BasketException): _email_basket_managers('subscribe', instance.user.email, exception.message)
def save(self): data = self.cleaned_data result = basket.subscribe(data['email'], self.newsletters(), format=data['fmt'], country=data['country'], welcome_message='Student_Ambassadors_Welcome', source_url=data['source_url']) data = { 'FIRST_NAME': data['first_name'], 'LAST_NAME': data['last_name'], 'STUDENTS_CURRENT_STATUS': data['status'], 'STUDENTS_SCHOOL': data['school'], 'STUDENTS_GRAD_YEAR': data['grad_year'], 'STUDENTS_MAJOR': data['major'], 'COUNTRY_': data['country'], 'STUDENTS_CITY': data['city'], 'STUDENTS_ALLOW_SHARE': data['share_information'], } request('post', 'custom_update_student_ambassadors', token=result['token'], data=data)
def save(self): data = self.cleaned_data result = basket.subscribe( data["email"], self.newsletters(), format=data["fmt"], country=data["country"], welcome_message="Student_Ambassadors_Welcome", source_url=data["source_url"], ) data = { "FIRST_NAME": data["first_name"], "LAST_NAME": data["last_name"], "STUDENTS_CURRENT_STATUS": data["status"], "STUDENTS_SCHOOL": data["school"], "STUDENTS_GRAD_YEAR": data["grad_year"], "STUDENTS_MAJOR": data["major"], "COUNTRY_": data["country"], "STUDENTS_CITY": data["city"], "STUDENTS_ALLOW_SHARE": data["share_information"], } request("post", "custom_update_student_ambassadors", token=result["token"], data=data)
def save(self): data = self.cleaned_data send_fsa_form(data) send_fsa_welcome_letter(data['email'], data['fmt']) if data.get('nl_mozilla_taiwan', False): newsletter_subscribe(data['email']) result = basket.subscribe(data['email'], self.newsletters(), format=data['fmt'], country=data['country'], welcome_message='Student_Ambassadors_Welcome', source_url=data['source_url']) data = { 'FIRST_NAME': data['first_name'], 'LAST_NAME': data['last_name'], 'STUDENTS_CURRENT_STATUS': data['current_status'], 'STUDENTS_SCHOOL': data['school'], 'STUDENTS_GRAD_YEAR': data['expected_graduation_year'], 'STUDENTS_MAJOR': data['area'], 'COUNTRY_': data['country'], 'STUDENTS_CITY': data['city'], 'STUDENTS_ALLOW_SHARE': data['share_information'], } request('post', 'custom_update_student_ambassadors', token=result['token'], data=data)