diff --git a/apps/files/models.py b/apps/files/models.py index f65695e5f8..0734c4cccf 100644 --- a/apps/files/models.py +++ b/apps/files/models.py @@ -72,9 +72,12 @@ class File(amo.models.OnChangeMixin, amo.models.ModelBase): # file, used for default to compatible. binary_components = models.BooleanField(default=False, db_index=True) - # Whether a webapp uses flash or not + # Whether a webapp uses flash or not. uses_flash = models.BooleanField(default=False, db_index=True) + # Whether the app is packaged or not (aka hosted). + is_packaged = models.BooleanField(default=False, db_index=True) + class Meta(amo.models.ModelBase.Meta): db_table = 'files' diff --git a/migrations/451-files-is-packaged.sql b/migrations/451-files-is-packaged.sql new file mode 100644 index 0000000000..e1b58d3413 --- /dev/null +++ b/migrations/451-files-is-packaged.sql @@ -0,0 +1,2 @@ +ALTER TABLE `files` ADD COLUMN `is_packaged` bool NOT NULL DEFAULT 0; +CREATE INDEX `files_is_packaged` ON `files` (`is_packaged`); diff --git a/mkt/webapps/models.py b/mkt/webapps/models.py index 5611c601fe..19cbe01225 100644 --- a/mkt/webapps/models.py +++ b/mkt/webapps/models.py @@ -380,6 +380,13 @@ class Webapp(Addon): """ return self.get_latest_file().uses_flash + @amo.cached_property + def has_packaged_files(self): + """ + Whether this app has any versions that are a packaged app. + """ + return self.versions.filter(files__is_packaged=True).exists() + # Pull all translated_fields from Addon over to Webapp. Webapp._meta.translated_fields = Addon._meta.translated_fields diff --git a/mkt/webapps/tests/test_models.py b/mkt/webapps/tests/test_models.py index a44780cbef..de96e15e92 100644 --- a/mkt/webapps/tests/test_models.py +++ b/mkt/webapps/tests/test_models.py @@ -12,7 +12,7 @@ import waffle from addons.models import (Addon, AddonCategory, AddonDeviceType, AddonPremium, BlacklistedSlug, Category, Preview) import amo -from amo.tests import TestCase, WebappTestCase +from amo.tests import app_factory, TestCase, WebappTestCase from constants.applications import DEVICE_TYPES from market.models import Price from files.models import File @@ -250,6 +250,12 @@ class TestWebapp(TestCase): eq_(sorted(Webapp.objects.get(id=w2.id).get_regions()), sorted(w2_regions)) + def test_has_packaged_files(self): + app1 = app_factory() + eq_(app1.has_packaged_files, False) + app2 = app_factory(file_kw=dict(is_packaged=True)) + eq_(app2.has_packaged_files, True) + class TestWebappVersion(amo.tests.TestCase): fixtures = ['base/platforms'] @@ -375,7 +381,8 @@ class TestTransformer(amo.tests.TestCase): assert transformer.called def test_device_types(self): - AddonDeviceType.objects.create(addon_id=337141, device_type=self.device) + AddonDeviceType.objects.create(addon_id=337141, + device_type=self.device) webapps = list(Webapp.objects.filter(id=337141)) with self.assertNumQueries(0):