def create_addon_purchase(sender, instance, **kw): """ When the contribution table is updated with the data from PayPal, update the addon purchase table. Will figure out if we need to add to or delete from the AddonPurchase table. """ if kw.get("raw") or instance.type not in [amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]: # Whitelist the types we care about. Forget about the rest. return log.debug( "Processing addon purchase type: %s, addon %s, user %s" % (unicode(amo.CONTRIB_TYPES[instance.type]), instance.addon.pk, instance.user.pk) ) if instance.type == amo.CONTRIB_PURCHASE: log.debug("Creating addon purchase: addon %s, user %s" % (instance.addon.pk, instance.user.pk)) data = {"addon": instance.addon, "user": instance.user} purchase, created = AddonPurchase.objects.safer_get_or_create(**data) purchase.update(type=amo.CONTRIB_PURCHASE) from mkt.webapps.models import Installed # Circular import. Installed.objects.safer_get_or_create(user=instance.user, addon=instance.addon) elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]: purchases = AddonPurchase.objects.filter(addon=instance.addon, user=instance.user) for p in purchases: log.debug("Changing addon purchase: %s, addon %s, user %s" % (p.pk, instance.addon.pk, instance.user.pk)) p.update(type=instance.type) cache.delete(memoize_key("users:purchase-ids", instance.user.pk))
def create_addon_purchase(sender, instance, **kw): """ When the contribution table is updated with the data from PayPal, update the addon purchase table. Will figure out if we need to add to or delete from the AddonPurchase table. """ if (kw.get('raw') or instance.type not in [ amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK ]): # Whitelist the types we care about. Forget about the rest. return log.debug('Processing addon purchase type: %s, addon %s, user %s' % (unicode(amo.CONTRIB_TYPES[instance.type]), instance.addon.pk, instance.user.pk)) if instance.type == amo.CONTRIB_PURCHASE: log.debug('Creating addon purchase: addon %s, user %s' % (instance.addon.pk, instance.user.pk)) data = {'addon': instance.addon, 'user': instance.user} purchase, created = AddonPurchase.objects.safer_get_or_create(**data) purchase.update(type=amo.CONTRIB_PURCHASE) from mkt.webapps.models import Installed # Circular import # Ensure that devs have the correct installed object found # or created. # is_dev = instance.addon.has_author( instance.user, (amo.AUTHOR_ROLE_OWNER, amo.AUTHOR_ROLE_DEV)) install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev else apps.INSTALL_TYPE_USER) Installed.objects.safer_get_or_create(user=instance.user, addon=instance.addon, install_type=install_type) elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]: purchases = AddonPurchase.objects.filter(addon=instance.addon, user=instance.user) for p in purchases: log.debug('Changing addon purchase: %s, addon %s, user %s' % (p.pk, instance.addon.pk, instance.user.pk)) p.update(type=instance.type) cache.delete(memoize_key('users:purchase-ids', instance.user.pk))
def create_addon_purchase(sender, instance, **kw): """ When the contribution table is updated with the data from PayPal, update the addon purchase table. Will figure out if we need to add to or delete from the AddonPurchase table. """ if (kw.get('raw') or instance.type not in [amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]): # Whitelist the types we care about. Forget about the rest. return log.debug('Processing addon purchase type: %s, addon %s, user %s' % (unicode(amo.CONTRIB_TYPES[instance.type]), instance.addon.pk, instance.user.pk)) if instance.type == amo.CONTRIB_PURCHASE: log.debug('Creating addon purchase: addon %s, user %s' % (instance.addon.pk, instance.user.pk)) data = {'addon': instance.addon, 'user': instance.user} purchase, created = AddonPurchase.objects.safer_get_or_create(**data) purchase.update(type=amo.CONTRIB_PURCHASE) from mkt.webapps.models import Installed # Circular import # Ensure that devs have the correct installed object found # or created. # is_dev = instance.addon.has_author(instance.user, (amo.AUTHOR_ROLE_OWNER, amo.AUTHOR_ROLE_DEV)) install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev else apps.INSTALL_TYPE_USER) Installed.objects.safer_get_or_create(user=instance.user, addon=instance.addon, install_type=install_type) elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]: purchases = AddonPurchase.objects.filter(addon=instance.addon, user=instance.user) for p in purchases: log.debug('Changing addon purchase: %s, addon %s, user %s' % (p.pk, instance.addon.pk, instance.user.pk)) p.update(type=instance.type) cache.delete(memoize_key('users:purchase-ids', instance.user.pk))