put installed in a transaction (bug 706554)
This commit is contained in:
Родитель
85ad80a531
Коммит
7f81288318
|
@ -1110,16 +1110,6 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
|
||||||
|
|
||||||
return self.installed.filter(user=user).exists()
|
return self.installed.filter(user=user).exists()
|
||||||
|
|
||||||
def get_or_create_install(self, user):
|
|
||||||
"""
|
|
||||||
Gets or creates the install receipt.
|
|
||||||
Ignoring get_or_create until #13906 is fixed.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
return self.installed.get(user=user)
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
return self.installed.create(user=user)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(dbsignals.post_save, sender=Addon,
|
@receiver(dbsignals.post_save, sender=Addon,
|
||||||
dispatch_uid='addons.update.name.table')
|
dispatch_uid='addons.update.name.table')
|
||||||
|
|
|
@ -40,7 +40,7 @@ from sharing.views import share as share_redirect
|
||||||
from stats.models import Contribution
|
from stats.models import Contribution
|
||||||
from translations.query import order_by_translation
|
from translations.query import order_by_translation
|
||||||
from versions.models import Version
|
from versions.models import Version
|
||||||
from webapps.models import Webapp
|
from webapps.models import Installed, Webapp
|
||||||
from .models import Addon, Persona, FrozenAddon
|
from .models import Addon, Persona, FrozenAddon
|
||||||
from .decorators import (addon_view_factory, can_be_purchased, has_purchased,
|
from .decorators import (addon_view_factory, can_be_purchased, has_purchased,
|
||||||
has_not_purchased)
|
has_not_purchased)
|
||||||
|
@ -596,7 +596,8 @@ def purchase_thanks(request, addon):
|
||||||
'download': download}
|
'download': download}
|
||||||
|
|
||||||
if addon.is_webapp():
|
if addon.is_webapp():
|
||||||
installed = addon.get_or_create_install(user=request.amo_user)
|
installed, c = Installed.objects.safe_get_or_create(addon=addon,
|
||||||
|
user=request.amo_user)
|
||||||
data['receipt'] = installed.receipt
|
data['receipt'] = installed.receipt
|
||||||
|
|
||||||
return jingo.render(request, 'addons/paypal_thanks.html', data)
|
return jingo.render(request, 'addons/paypal_thanks.html', data)
|
||||||
|
|
|
@ -130,7 +130,9 @@ def create_addon_purchase(sender, instance, **kw):
|
||||||
data = {'addon': instance.addon, 'user': instance.user}
|
data = {'addon': instance.addon, 'user': instance.user}
|
||||||
purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
|
purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
|
||||||
purchase.update(type=amo.CONTRIB_PURCHASE)
|
purchase.update(type=amo.CONTRIB_PURCHASE)
|
||||||
instance.addon.get_or_create_install(user=instance.user)
|
from 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]:
|
elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]:
|
||||||
purchases = AddonPurchase.objects.filter(addon=instance.addon,
|
purchases = AddonPurchase.objects.filter(addon=instance.addon,
|
||||||
|
|
|
@ -167,7 +167,8 @@ class TestReceipt(amo.tests.TestCase):
|
||||||
def create_install(self, user, webapp):
|
def create_install(self, user, webapp):
|
||||||
webapp.update(type=amo.ADDON_WEBAPP,
|
webapp.update(type=amo.ADDON_WEBAPP,
|
||||||
manifest_url='http://somesite.com/')
|
manifest_url='http://somesite.com/')
|
||||||
return webapp.get_or_create_install(user)
|
return Installed.objects.safer_get_or_create(user=user,
|
||||||
|
addon=webapp)[0]
|
||||||
|
|
||||||
def test_get_or_create(self):
|
def test_get_or_create(self):
|
||||||
install = self.create_install(self.user, self.webapp)
|
install = self.create_install(self.user, self.webapp)
|
||||||
|
|
|
@ -10,6 +10,7 @@ from amo.helpers import loc
|
||||||
from amo.utils import paginate
|
from amo.utils import paginate
|
||||||
from addons.decorators import addon_view
|
from addons.decorators import addon_view
|
||||||
import addons.views
|
import addons.views
|
||||||
|
from webapps.models import Installed
|
||||||
import search.views
|
import search.views
|
||||||
|
|
||||||
from addons.models import Category
|
from addons.models import Category
|
||||||
|
@ -108,6 +109,7 @@ def share(request, app_slug):
|
||||||
@post_required
|
@post_required
|
||||||
def record(request, addon):
|
def record(request, addon):
|
||||||
if addon.is_webapp():
|
if addon.is_webapp():
|
||||||
installed = addon.get_or_create_install(user=request.amo_user)
|
installed, c = Installed.objects.safer_get_or_create(addon=addon,
|
||||||
|
user=request.amo_user)
|
||||||
return {'addon': addon.pk,
|
return {'addon': addon.pk,
|
||||||
'receipt': installed.receipt if installed else ''}
|
'receipt': installed.receipt if installed else ''}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче