create addon premium table
This commit is contained in:
Родитель
3354a0a0d8
Коммит
536da2356b
|
@ -27,6 +27,7 @@ from amo.utils import (send_mail, urlparams, sorted_groupby, JSONEncoder,
|
|||
from amo.urlresolvers import get_outgoing_url, reverse
|
||||
from addons.utils import ReverseNameLookup, FeaturedManager, CreaturedManager
|
||||
from files.models import File
|
||||
from market.models import AddonPremium
|
||||
from reviews.models import Review
|
||||
from stats.models import AddonShareCountTotal
|
||||
from translations.fields import (TranslatedField, PurifiedField,
|
||||
|
@ -649,6 +650,11 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
|
|||
category = categories[cats[addon.id]] if addon.id in cats else None
|
||||
addon._first_category[amo.FIREFOX.id] = category
|
||||
|
||||
# Attach premium addons.
|
||||
qs = AddonPremium.objects.filter(addon__in=addons)
|
||||
for addon_p in qs:
|
||||
addon_dict[addon_p.addon_id].premium = addon_p
|
||||
|
||||
@property
|
||||
def show_beta(self):
|
||||
return self.status == amo.STATUS_PUBLIC and self.current_beta_version
|
||||
|
|
|
@ -28,6 +28,7 @@ from applications.models import Application, AppVersion
|
|||
from devhub.models import ActivityLog
|
||||
from files.models import File, Platform
|
||||
from files.tests.test_models import TestLanguagePack, UploadTest
|
||||
from market.models import Price, AddonPremium
|
||||
from reviews.models import Review
|
||||
from translations.models import TranslationSequence, Translation
|
||||
from users.models import UserProfile
|
||||
|
@ -1585,7 +1586,7 @@ class TestLanguagePack(TestLanguagePack):
|
|||
class TestMarketplace(amo.tests.ESTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.addon = Addon(type=amo.ADDON_EXTENSION)
|
||||
self.addon = Addon.objects.create(type=amo.ADDON_EXTENSION)
|
||||
|
||||
def test_is_premium(self):
|
||||
assert not self.addon.is_premium()
|
||||
|
@ -1621,6 +1622,16 @@ class TestMarketplace(amo.tests.ESTestCase):
|
|||
status=status)
|
||||
assert self.addon.can_be_purchased()
|
||||
|
||||
def test_transformer(self):
|
||||
other = Addon.objects.create(type=amo.ADDON_EXTENSION)
|
||||
price = Price.objects.create(price='1.00')
|
||||
|
||||
self.addon.update(type=amo.ADDON_PREMIUM)
|
||||
AddonPremium.objects.create(addon=self.addon, price=price)
|
||||
|
||||
assert hasattr(Addon.objects.get(pk=self.addon.pk), 'premium')
|
||||
assert not hasattr(Addon.objects.get(pk=other.pk), 'premium')
|
||||
|
||||
|
||||
class TestAddonUpsell(amo.tests.TestCase):
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ from django.dispatch import receiver
|
|||
|
||||
from translations.fields import TranslatedField
|
||||
|
||||
from addons.models import Addon
|
||||
import amo
|
||||
import amo.models
|
||||
from stats.models import Contribution
|
||||
|
@ -53,7 +52,7 @@ class PriceCurrency(amo.models.ModelBase):
|
|||
|
||||
|
||||
class AddonPurchase(amo.models.ModelBase):
|
||||
addon = models.ForeignKey(Addon)
|
||||
addon = models.ForeignKey('addons.Addon')
|
||||
user = models.ForeignKey(UserProfile)
|
||||
|
||||
class Meta:
|
||||
|
@ -93,3 +92,16 @@ def create_addon_purchase(sender, instance, **kw):
|
|||
log.debug('Deleting addon purchase: %s, addon %s, user %s'
|
||||
% (p.pk, instance.addon.pk, instance.user.pk))
|
||||
p.delete()
|
||||
|
||||
|
||||
class AddonPremium(amo.models.ModelBase):
|
||||
"""Additions to the Addon model that only apply to Premium add-ons."""
|
||||
addon = models.OneToOneField('addons.Addon')
|
||||
price = models.ForeignKey(Price)
|
||||
paypal_permissions_token = models.CharField(max_length=255, blank=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'addons_premium'
|
||||
|
||||
def __unicode__(self):
|
||||
return u'Premium %s: %s' % (self.addon, self.price)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
CREATE TABLE addons_premium (
|
||||
id int(11) unsigned AUTO_INCREMENT NOT NULL PRIMARY KEY,
|
||||
created datetime NOT NULL,
|
||||
modified datetime NOT NULL,
|
||||
addon_id int(11) unsigned NOT NULL UNIQUE,
|
||||
price_id int(11) NOT NULL,
|
||||
paypal_permissions_token varchar(255) NOT NULL
|
||||
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
|
||||
ALTER TABLE addons_premium ADD CONSTRAINT addon_id_refs_id_addons_premium FOREIGN KEY (addon_id) REFERENCES addons (id);
|
||||
ALTER TABLE addons_premium ADD CONSTRAINT price_id_refs_id_addons_premium FOREIGN KEY (price_id) REFERENCES prices (id);
|
Загрузка…
Ссылка в новой задаче