示例#1
0
def update_salesforce_user_task(queryset):
    SFResponseCodes = [
        "SUCCESS", "ERR_USERID_EXISTS", "ERR_USERID_NOT_FOUND",
        "ERR_PORTFOLIOID_NOT_FOUND", "ERR_PORTFOLIOID_EXISTS"
    ]
    django_client = init_client()
    for user in queryset:
        try:
            profile = user.profile
        except Profile.DoesNotExist:
            profile = Profile(user=user)
            profile.save()
        except Profile.MultipleObjectsReturned:
            profiles = Profile.objects.filter(user=user)
            profile = profiles[0]
        bitmask = get_subscription_bitmask(profile)
        if CampaignsSignup.objects.filter(email=user.email).exists():
            bitmask += 16
        bitmask += 8

        returncode = django_client.service.updateUser2(
            '%s' % profile.user.id,
            profile.user.username,
            profile.user.email,
            user.first_name,
            user.last_name,
            profile.dob,
            profile.telephone,
            profile.salutation,
            profile.postcode,
            bitmask,
            profile.user.is_active,
        )
        if returncode > 0:
            raise ResponseError(returncode)
示例#2
0
def update_salesforce_user_task(queryset):
    SFResponseCodes =["SUCCESS", "ERR_USERID_EXISTS", "ERR_USERID_NOT_FOUND", "ERR_PORTFOLIOID_NOT_FOUND", "ERR_PORTFOLIOID_EXISTS"]
    django_client = init_client()
    for user in queryset:
        try:
            profile = user.profile
        except Profile.DoesNotExist:
            profile = Profile(user=user)
            profile.save()
        except Profile.MultipleObjectsReturned:
            profiles = Profile.objects.filter(user=user)
            profile = profiles[0]
        bitmask = get_subscription_bitmask(profile)
        if CampaignsSignup.objects.filter(email=user.email).exists():
            bitmask += 16
        bitmask += 8

        returncode = django_client.service.updateUser2('%s' % profile.user.id,
                    profile.user.username,
                    profile.user.email,
                    user.first_name,
                    user.last_name,
                    profile.dob,
                    profile.telephone,
                    profile.salutation,
                    profile.postcode,
                    bitmask,
                    profile.user.is_active,
                )
        if returncode > 0:
            raise ResponseError(returncode)
示例#3
0
def sync_ratetracker_reminder(self, product_reminder_id):
    try:
        django_client = init_client()
        reminder = RatetrackerReminder.objects.get(pk=product_reminder_id)
        prt = django_client.factory.create('ProductPortfolio')
        prt.Balance = reminder.balance
        prt.OpeningDate = reminder.maturity_date
        prt.Id = "rr%s" % reminder.id
        prt.RateTrack = True

        # XXX get a product have to find appropriate product that is published in 1970, this can almost certainly
        # be optomised if required. Also relies on their only being 1 product that matches this way.
        product_code = 'SCxxxxx'

        # Needed now because Sue requested that all Fixed Rate Bond products are now bonds.
        # So I slice a couple letters off the account type and use contains to find the special Product for this provider.

        title_length = len(reminder.account_type.title.upper())
        products = Product.objects.filter(provider=reminder.provider).filter(
            title__contains='DJANGO %s' %
            reminder.account_type.title[:title_length - 2].upper())

        if products.exists():
            product_code = products.first().sc_code
        prt.UserId = reminder.user_id
        prt.SCCode = product_code
        if reminder.is_deleted:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_reminder.attempted')
            statsd_client += 1
            return_code = django_client.service.deleteRateTracker(
                reminder.user_id, prt)
            if return_code == 3:
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_reminder.attempted'
                )
                statsd_client += 1
                django_client.service.newRateTracker(reminder.user_id, prt)
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_reminder.attempted'
                )
                statsd_client += 1
                django_client.service.deleteRateTracker(reminder.user_id, prt)
        else:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_reminder.attempted')
            statsd_client += 1
            return_code = django_client.service.newRateTracker(
                reminder.user_id, prt)
            if return_code == 4:
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_reminder.attempted'
                )
                statsd_client += 1
                django_client.service.updateRateTracker(reminder.user_id, prt)
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        raise self.retry(exc=exc,
                         countdown=int(
                             random.uniform(2, 4)**self.request.retries))
    def handle_noargs(self, **options):
        """ 
        When logging into the salesforce api we have to append our security token to the end
        """

        dte = self._get_query_date(datetime.datetime.now())        
        django_client = init_client()

        self.alert_adjustment_sync(django_client)
示例#5
0
    def handle_noargs(self, **options):
        """ 
        When logging into the salesforce api we have to append our security token to the end
        """

        dte = self._get_query_date(datetime.datetime.now())
        django_client = init_client()

        self.alert_adjustment_sync(django_client)
示例#6
0
def sync_ratetracker_reminder(self, product_reminder_id):
    try:
        django_client = init_client()
        reminder = RatetrackerReminder.objects.get(pk=product_reminder_id)
        prt = django_client.factory.create('ProductPortfolio')
        prt.Balance = reminder.balance
        prt.OpeningDate = reminder.maturity_date
        prt.Id = "rr%s" % reminder.id
        prt.RateTrack = True

        # XXX get a product have to find appropriate product that is published in 1970, this can almost certainly
        # be optomised if required. Also relies on their only being 1 product that matches this way.
        product_code = 'SCxxxxx'

        # Needed now because Sue requested that all Fixed Rate Bond products are now bonds.
        # So I slice a couple letters off the account type and use contains to find the special Product for this provider.

        title_length = len(reminder.account_type.title.upper())
        products = Product.objects.filter(provider=reminder.provider).filter(
            title__contains='DJANGO %s' % reminder.account_type.title[:title_length - 2].upper())

        if products.exists():
            product_code = products.first().sc_code
        prt.UserId = reminder.user_id
        prt.SCCode = product_code
        if reminder.is_deleted:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_reminder.attempted'
            )
            statsd_client += 1
            return_code = django_client.service.deleteRateTracker(reminder.user_id, prt)
            if return_code == 3:
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_reminder.attempted'
                )
                statsd_client += 1
                django_client.service.newRateTracker(reminder.user_id, prt)
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_reminder.attempted'
                )
                statsd_client += 1
                django_client.service.deleteRateTracker(reminder.user_id, prt)
        else:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_reminder.attempted'
            )
            statsd_client += 1
            return_code = django_client.service.newRateTracker(reminder.user_id, prt)
            if return_code == 4:
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_reminder.attempted'
                )
                statsd_client += 1
                django_client.service.updateRateTracker(reminder.user_id, prt)
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        raise self.retry(exc=exc, countdown=int(random.uniform(2, 4) ** self.request.retries))
示例#7
0
def delete_user_profile(self, user_id):
    try:
        User = get_user_model()

        try:
            user = User.objects.get(pk=user_id)
        except User.DoesNotExist:
            # Looks like we've already done our job in another thread/task.
            return
        django_client = init_client()

        # Iterate over all Variable Rate Products and "delete" them from Salesforce.
        for rate_tracker in ProductPortfolio.objects.filter(user=user_id):
            rate_tracker.is_deleted = True
            rate_tracker.save()

        # Iterate over all Fixed Rate Products and "delete" them from Salesforce.
        for rate_tracker in RatetrackerReminder.objects.filter(user=user_id):
            rate_tracker.is_deleted = True
            rate_tracker.save()

        # "Delete" this user from salesforce (User is marked deleted)
        statsd_client = StatsDClient().get_counter_client(
            client_name='salesforce.delete_user_profile.attempted'
        )
        statsd_client += 1
        return_code = django_client.service.deleteUser(user_id)
        assert return_code in [0, '0'], return_code

        # Finally delete all records of this user from Django
        user.delete()

        statsd_client = StatsDClient().get_counter_client(
            client_name='user.profile.deleted'
        )
        statsd_client -= 1
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        raise self.retry(exc=exc, countdown=int(random.uniform(2, 4) ** self.request.retries))
示例#8
0
def delete_user_profile(self, user_id):
    try:
        User = get_user_model()

        try:
            user = User.objects.get(pk=user_id)
        except User.DoesNotExist:
            # Looks like we've already done our job in another thread/task.
            return
        django_client = init_client()

        # Iterate over all Variable Rate Products and "delete" them from Salesforce.
        for rate_tracker in ProductPortfolio.objects.filter(user=user_id):
            rate_tracker.is_deleted = True
            rate_tracker.save()

        # Iterate over all Fixed Rate Products and "delete" them from Salesforce.
        for rate_tracker in RatetrackerReminder.objects.filter(user=user_id):
            rate_tracker.is_deleted = True
            rate_tracker.save()

        # "Delete" this user from salesforce (User is marked deleted)
        statsd_client = StatsDClient().get_counter_client(
            client_name='salesforce.delete_user_profile.attempted')
        statsd_client += 1
        return_code = django_client.service.deleteUser(user_id)
        assert return_code in [0, '0'], return_code

        # Finally delete all records of this user from Django
        user.delete()

        statsd_client = StatsDClient().get_counter_client(
            client_name='user.profile.deleted')
        statsd_client -= 1
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        raise self.retry(exc=exc,
                         countdown=int(
                             random.uniform(2, 4)**self.request.retries))
示例#9
0
def sync_ratetracker_portfolio(self, product_portfolio_id):
    try:
        django_client = init_client()
        portfolio = ProductPortfolio.objects.get(pk=product_portfolio_id)
        user = portfolio.user
        # Get users rate tracker reminders
        # Ensure user has a profile, then update the bitmask by starting that task
        try:
            profile = user.profile
        except Profile.DoesNotExist:
            profile = Profile(user=user)
            profile.is_synched = False
            profile.save()
        except Profile.MultipleObjectsReturned:
            profiles = Profile.objects.filter(user=user)
            profile = profiles[0]
        prt = django_client.factory.create('ProductPortfolio')
        prt.Balance = portfolio.balance
        prt.OpeningDate = portfolio.opening_date
        prt.Id = "pp%s" % portfolio.id
        prt.RateTrack = True
        latest_product_tier = portfolio.master_product.return_product_from_balance(
            portfolio.balance)
        prt.SCCode = latest_product_tier.sc_code
        prt.UserId = portfolio.user_id
        if portfolio.is_deleted:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_portfolio.attempted')
            statsd_client += 1
            return_code = django_client.service.deleteRateTracker(
                portfolio.user_id, prt)
            if return_code == 2:
                raise ResponseError(
                    'Could not delete a product record on Salesforce, awaiting User creation'
                )
            if return_code == 3:
                statsd_client = StatsDClient().get_counter_client(
                    client_name=
                    'salesforce.sync_ratetracker_portfolio.attempted')
                statsd_client += 1
                return_code = django_client.service.newRateTracker(
                    portfolio.user_id, prt)
                if return_code == 0:
                    statsd_client = StatsDClient().get_counter_client(
                        client_name=
                        'salesforce.sync_ratetracker_portfolio.attempted')
                    statsd_client += 1
                    return_code = django_client.service.deleteRateTracker(
                        portfolio.user_id, prt)
                else:
                    raise ResponseError(
                        'Could not create a new product record for deletion on Salesforce'
                    )

        else:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_portfolio.attempted')
            statsd_client += 1
            return_code = django_client.service.newRateTracker(
                portfolio.user_id, prt)
            if return_code == 2:
                raise ResponseError(
                    'Could not create a new product record on Salesforce, awaiting User creation'
                )
            if return_code == 4:
                statsd_client = StatsDClient().get_counter_client(
                    client_name=
                    'salesforce.sync_ratetracker_portfolio.attempted')
                statsd_client += 1
                return_code = django_client.service.updateRateTracker(
                    portfolio.user_id, prt)

        if return_code == 0:
            portfolio.is_synched = True
            portfolio.save()
        else:  # Profile Doesn't Exist Yet or has been deleted.
            portfolio.is_synched = False
    #     # Process bitmask value for Salesforce
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        pass
示例#10
0
def create_user_profile(self, profile_id):
    try:
        django_client = init_client()
        profile = Profile.objects.get(pk=profile_id)
        bitmask = get_bitmask(profile.user)
        newsletter_active = False
        ratealerts_active = False

        if profile.newsletter:
            newsletter_active = profile.newsletter
        if profile.ratealerts:
            ratealerts_active = profile.ratealerts

        if bitmask >= 0:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.create_user_profile.attempted'
            )
            statsd_client += 1
            returncode = django_client.service.newUser5('%s' % profile.user.id,
                                                        profile.user.username,
                                                        profile.user.email,
                                                        profile.user.first_name,
                                                        profile.user.last_name,
                                                        profile.dob,
                                                        profile.telephone,
                                                        profile.salutation,
                                                        profile.postcode,
                                                        bitmask,
                                                        profile.source,
                                                        '',
                                                        '',
                                                        profile.user.is_active,
                                                        profile.user.date_joined,
                                                        ratealerts_active,
                                                        newsletter_active,
                                                        )
            if returncode > 0:
                if returncode == 1:
                    # userid already exists (due to this being a skeleton user so we run an updateuser command instead of erroring)
                    statsd_client = StatsDClient().get_counter_client(
                        client_name='salesforce.create_user_profile.attempted'
                    )
                    statsd_client += 1
                    returncode = django_client.service.updateUser3('%s' % profile.user.id,
                                                                   profile.user.username,
                                                                   profile.user.email,
                                                                   profile.user.first_name,
                                                                   profile.user.last_name,
                                                                   profile.dob,
                                                                   profile.telephone,
                                                                   profile.salutation,
                                                                   profile.postcode,
                                                                   bitmask,
                                                                   profile.user.is_active,
                                                                   profile.source,
                                                                   ratealerts_active,
                                                                   newsletter_active,
                                                                   )
                    # if this return code is still errorring then raise a response error
                    if returncode > 0:
                        raise ResponseError(returncode)
                else:
                    raise ResponseError(returncode)
            profile.is_synched = True
            profile.save()
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        raise self.retry(exc=exc, countdown=int(random.uniform(2, 4) ** self.request.retries))
示例#11
0
def create_user_profile(self, profile_id):
    try:
        django_client = init_client()
        profile = Profile.objects.get(pk=profile_id)
        bitmask = get_bitmask(profile.user)
        newsletter_active = False
        ratealerts_active = False

        if profile.newsletter:
            newsletter_active = profile.newsletter
        if profile.ratealerts:
            ratealerts_active = profile.ratealerts

        if bitmask >= 0:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.create_user_profile.attempted')
            statsd_client += 1
            returncode = django_client.service.newUser5(
                '%s' % profile.user.id,
                profile.user.username,
                profile.user.email,
                profile.user.first_name,
                profile.user.last_name,
                profile.dob,
                profile.telephone,
                profile.salutation,
                profile.postcode,
                bitmask,
                profile.source,
                '',
                '',
                profile.user.is_active,
                profile.user.date_joined,
                ratealerts_active,
                newsletter_active,
            )
            if returncode > 0:
                if returncode == 1:
                    # userid already exists (due to this being a skeleton user so we run an updateuser command instead of erroring)
                    statsd_client = StatsDClient().get_counter_client(
                        client_name='salesforce.create_user_profile.attempted')
                    statsd_client += 1
                    returncode = django_client.service.updateUser3(
                        '%s' % profile.user.id,
                        profile.user.username,
                        profile.user.email,
                        profile.user.first_name,
                        profile.user.last_name,
                        profile.dob,
                        profile.telephone,
                        profile.salutation,
                        profile.postcode,
                        bitmask,
                        profile.user.is_active,
                        profile.source,
                        ratealerts_active,
                        newsletter_active,
                    )
                    # if this return code is still errorring then raise a response error
                    if returncode > 0:
                        raise ResponseError(returncode)
                else:
                    raise ResponseError(returncode)
            profile.is_synched = True
            profile.save()
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        raise self.retry(exc=exc,
                         countdown=int(
                             random.uniform(2, 4)**self.request.retries))
示例#12
0
def sync_ratetracker_portfolio(self, product_portfolio_id):
    try:
        django_client = init_client()
        portfolio = ProductPortfolio.objects.get(pk=product_portfolio_id)
        user = portfolio.user
        # Get users rate tracker reminders
        # Ensure user has a profile, then update the bitmask by starting that task
        try:
            profile = user.profile
        except Profile.DoesNotExist:
            profile = Profile(user=user)
            profile.is_synched = False
            profile.save()
        except Profile.MultipleObjectsReturned:
            profiles = Profile.objects.filter(user=user)
            profile = profiles[0]
        prt = django_client.factory.create('ProductPortfolio')
        prt.Balance = portfolio.balance
        prt.OpeningDate = portfolio.opening_date
        prt.Id = "pp%s" % portfolio.id
        prt.RateTrack = True
        latest_product_tier = portfolio.master_product.return_product_from_balance(portfolio.balance)
        prt.SCCode = latest_product_tier.sc_code
        prt.UserId = portfolio.user_id
        if portfolio.is_deleted:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_portfolio.attempted'
            )
            statsd_client += 1
            return_code = django_client.service.deleteRateTracker(portfolio.user_id, prt)
            if return_code == 2:
                raise ResponseError('Could not delete a product record on Salesforce, awaiting User creation')
            if return_code == 3:
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_portfolio.attempted'
                )
                statsd_client += 1
                return_code = django_client.service.newRateTracker(portfolio.user_id, prt)
                if return_code == 0:
                    statsd_client = StatsDClient().get_counter_client(
                        client_name='salesforce.sync_ratetracker_portfolio.attempted'
                    )
                    statsd_client += 1
                    return_code = django_client.service.deleteRateTracker(portfolio.user_id, prt)
                else:
                    raise ResponseError('Could not create a new product record for deletion on Salesforce')

        else:
            statsd_client = StatsDClient().get_counter_client(
                client_name='salesforce.sync_ratetracker_portfolio.attempted'
            )
            statsd_client += 1
            return_code = django_client.service.newRateTracker(portfolio.user_id, prt)
            if return_code == 2:
                raise ResponseError('Could not create a new product record on Salesforce, awaiting User creation')
            if return_code == 4:
                statsd_client = StatsDClient().get_counter_client(
                    client_name='salesforce.sync_ratetracker_portfolio.attempted'
                )
                statsd_client += 1
                return_code = django_client.service.updateRateTracker(portfolio.user_id, prt)

        if return_code == 0:
            portfolio.is_synched = True
            portfolio.save()
        else:  # Profile Doesn't Exist Yet or has been deleted.
            portfolio.is_synched = False
    #     # Process bitmask value for Salesforce
    except (WebFault, SalesforceAuthenticationFailed) as exc:
        pass