diff --git a/apps/addons/buttons.py b/apps/addons/buttons.py index 21507ce3410..56541ed1a57 100644 --- a/apps/addons/buttons.py +++ b/apps/addons/buttons.py @@ -174,7 +174,7 @@ def links(self): return rv def file_details(self, file): - platform = file.platform_id + platform = file.platform if self.latest and ( self.addon.status == file.status == amo.STATUS_PUBLIC): url = file.latest_xpi_url() diff --git a/apps/addons/fixtures/addons/eula+contrib-addon.json b/apps/addons/fixtures/addons/eula+contrib-addon.json index 99895ddfc54..dfba0ac46e3 100644 --- a/apps/addons/fixtures/addons/eula+contrib-addon.json +++ b/apps/addons/fixtures/addons/eula+contrib-addon.json @@ -84,14 +84,6 @@ "_current_version": 68776 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 68776, "model": "versions.version", diff --git a/apps/addons/fixtures/addons/invalid_latest_version.json b/apps/addons/fixtures/addons/invalid_latest_version.json index 19eef5621a9..7f6d6d63c6f 100644 --- a/apps/addons/fixtures/addons/invalid_latest_version.json +++ b/apps/addons/fixtures/addons/invalid_latest_version.json @@ -58,14 +58,6 @@ "the_reason": null } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 98217, "model": "versions.version", @@ -78,22 +70,6 @@ "addon": 3895 } }, - { - "pk": 2, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 5, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:56", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 78829, "model": "versions.version", diff --git a/apps/addons/fixtures/addons/test_manager.json b/apps/addons/fixtures/addons/test_manager.json index f05172c7884..81683c2db40 100644 --- a/apps/addons/fixtures/addons/test_manager.json +++ b/apps/addons/fixtures/addons/test_manager.json @@ -215,14 +215,6 @@ "addon": 1 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 11993, "model": "files.file", diff --git a/apps/addons/tests/test_buttons.py b/apps/addons/tests/test_buttons.py index a9c823d6b9d..a5e186a407f 100644 --- a/apps/addons/tests/test_buttons.py +++ b/apps/addons/tests/test_buttons.py @@ -44,10 +44,10 @@ def setUp(self): v.version = 'v1' self.addon.current_version = v - self.file = self.get_file(amo.PLATFORM_ALL) + self.file = self.get_file(amo.PLATFORM_ALL.id) v.all_files = [self.file] - self.platforms = amo.PLATFORM_MAC, amo.PLATFORM_LINUX + self.platforms = amo.PLATFORM_MAC.id, amo.PLATFORM_LINUX.id self.platform_files = map(self.get_file, self.platforms) self.request = Mock() @@ -79,7 +79,7 @@ def render(self, **kwargs): def get_file(self, platform): file = Mock() - file.platform_id = platform.id + file.platform = platform file.latest_xpi_url.return_value = 'xpi.latest' file.get_url_path.return_value = 'xpi.url' file.eula_url.return_value = 'eula.url' @@ -278,7 +278,7 @@ def test_after_no_show_contrib(self): eq_(b.attrs(), {}) def test_file_details(self): - file = self.get_file(amo.PLATFORM_ALL) + file = self.get_file(amo.PLATFORM_ALL.id) self.addon.meet_the_dev_url.return_value = 'meet.dev' b = self.get_button() @@ -289,7 +289,7 @@ def test_file_details(self): eq_(os, None) # Platformer. - file = self.get_file(amo.PLATFORM_MAC) + file = self.get_file(amo.PLATFORM_MAC.id) _, _, os = b.file_details(file) eq_(os, amo.PLATFORM_MAC) @@ -306,7 +306,7 @@ def test_file_details(self): '/en-US/firefox/addon/2/contribute/roadblock/?version=v1') def test_file_details_unreviewed(self): - file = self.get_file(amo.PLATFORM_ALL) + file = self.get_file(amo.PLATFORM_ALL.id) file.status = amo.STATUS_UNREVIEWED b = self.get_button() @@ -333,7 +333,7 @@ def test_links(self): links = self.get_button().links() eq_(len(links), len(self.platforms)) - eq_([x.os for x in links], list(self.platforms)) + eq_([x.os.id for x in links], list(self.platforms)) def test_link_with_invalid_file(self): self.version.all_files = self.platform_files @@ -342,7 +342,7 @@ def test_link_with_invalid_file(self): expected_platforms = self.platforms[1:] eq_(len(links), len(expected_platforms)) - eq_([x.os for x in links], list(expected_platforms)) + eq_([x.os.id for x in links], list(expected_platforms)) def test_no_version(self): self.addon.current_version = None @@ -434,8 +434,9 @@ def test_multi_platform(self): eq_(doc('.button').length, 2) for platform in self.platforms: - os = doc('.button.%s .os' % platform.shortname).attr('data-os') - eq_(platform.name, os) + os = doc('.button.%s .os' % + amo.PLATFORMS[platform].shortname).attr('data-os') + eq_(amo.PLATFORMS[platform].name, os) def test_compatible_apps(self): compat = Mock() @@ -538,7 +539,7 @@ def setUp(self): def get_backup_file(self): file = Mock() - file.platform_id = amo.PLATFORM_ALL.id + file.platform = amo.PLATFORM_ALL.id file.latest_xpi_url.return_value = 'xpi.backup' file.get_url_path.return_value = 'xpi.backup.url' file.status = amo.STATUS_PUBLIC diff --git a/apps/addons/tests/test_cron.py b/apps/addons/tests/test_cron.py index f7493e620f0..dd64f61c531 100644 --- a/apps/addons/tests/test_cron.py +++ b/apps/addons/tests/test_cron.py @@ -1,18 +1,15 @@ import os import datetime -from nose.exc import SkipTest from nose.tools import eq_ import mock -from django.conf import settings - import amo import amo.tests from addons import cron from addons.models import Addon, AppSupport from django.core.management.base import CommandError -from files.models import File, Platform +from files.models import File from lib.es.utils import flag_reindexing_amo, unflag_reindexing_amo from stats.models import UpdateCount from versions.models import Version @@ -119,7 +116,7 @@ class TestHideDisabledFiles(amo.tests.TestCase): msg = 'Moving disabled file: %s => %s' def setUp(self): - p = Platform.objects.create(id=amo.PLATFORM_ALL.id) + p = amo.PLATFORM_ALL.id self.addon = Addon.objects.create(type=amo.ADDON_EXTENSION) self.version = Version.objects.create(addon=self.addon) self.f1 = File.objects.create(version=self.version, platform=p, diff --git a/apps/addons/tests/test_forms.py b/apps/addons/tests/test_forms.py index 112f2baa6d8..cbd8f550a4c 100644 --- a/apps/addons/tests/test_forms.py +++ b/apps/addons/tests/test_forms.py @@ -86,7 +86,7 @@ def test_slug_isdigit(self): class TestTagsForm(amo.tests.TestCase): - fixtures = ['base/addon_3615', 'base/platforms', 'base/users'] + fixtures = ['base/addon_3615', 'base/users'] def setUp(self): self.addon = Addon.objects.get(pk=3615) diff --git a/apps/addons/tests/test_models.py b/apps/addons/tests/test_models.py index 30dcc203f58..77dfe3fdedd 100644 --- a/apps/addons/tests/test_models.py +++ b/apps/addons/tests/test_models.py @@ -31,7 +31,7 @@ from constants.applications import DEVICE_TYPES from devhub.models import ActivityLog, AddonLog, RssKey, SubmitStep from editors.models import EscalationQueue -from files.models import File, Platform +from files.models import File from files.tests.test_models import UploadTest from reviews.models import Review, ReviewFlag from translations.models import Translation, TranslationSequence @@ -300,7 +300,6 @@ class TestAddonModels(amo.tests.TestCase): 'base/appversion', 'base/collections', 'base/featured', - 'base/platforms', 'base/users', 'base/addon_5299_gcal', 'base/addon_3615', @@ -1504,7 +1503,6 @@ def test_review_delete(self): class TestUpdateStatus(amo.tests.TestCase): - fixtures = ['base/platforms', ] def test_no_file_ends_with_NULL(self): addon = Addon.objects.create(type=amo.ADDON_EXTENSION) @@ -1624,8 +1622,7 @@ def test_featured_random(self): class TestBackupVersion(amo.tests.TestCase): - fixtures = ['addons/update', 'base/apps', 'base/appversion', - 'base/platforms'] + fixtures = ['addons/update', 'base/apps', 'base/appversion'] def setUp(self): self.version_1_2_0 = 105387 @@ -1823,7 +1820,6 @@ def test_scores(self): class TestAddonDependencies(amo.tests.TestCase): fixtures = ['base/apps', 'base/appversion', - 'base/platforms', 'base/users', 'base/addon_5299_gcal', 'base/addon_3615', @@ -1863,7 +1859,6 @@ def test_listed_two_versions(self): class TestFlushURLs(amo.tests.TestCase): fixtures = ['base/apps', 'base/appversion', - 'base/platforms', 'base/users', 'base/addon_5579', 'base/previews', @@ -1915,7 +1910,7 @@ def setUp(self): super(TestAddonFromUpload, self).setUp() u = UserProfile.objects.get(pk=999) set_user(u) - self.platform = Platform.objects.create(id=amo.PLATFORM_MAC.id) + self.platform = amo.PLATFORM_MAC.id for version in ('3.0', '3.6.*'): AppVersion.objects.create(application_id=1, version=version) self.addCleanup(translation.deactivate) @@ -1948,17 +1943,16 @@ def test_xpi_version(self): [self.platform]) v = addon.versions.get() eq_(v.version, '0.1') - eq_(v.files.get().platform_id, self.platform.id) + eq_(v.files.get().platform, self.platform) eq_(v.files.get().status, amo.STATUS_UNREVIEWED) def test_xpi_for_multiple_platforms(self): - platforms = [Platform.objects.get(pk=amo.PLATFORM_LINUX.id), - Platform.objects.get(pk=amo.PLATFORM_MAC.id)] + platforms = [amo.PLATFORM_LINUX.id, amo.PLATFORM_MAC.id] addon = Addon.from_upload(self.get_upload('extension.xpi'), platforms) v = addon.versions.get() - eq_(sorted([f.platform.id for f in v.all_files]), - sorted([p.id for p in platforms])) + eq_(sorted([f.platform for f in v.all_files]), + sorted(platforms)) def test_search_attributes(self): addon = Addon.from_upload(self.get_upload('search.xml'), @@ -1977,7 +1971,7 @@ def test_search_version(self): [self.platform]) v = addon.versions.get() eq_(v.version, datetime.now().strftime('%Y%m%d')) - eq_(v.files.get().platform_id, amo.PLATFORM_ALL.id) + eq_(v.files.get().platform, amo.PLATFORM_ALL.id) eq_(v.files.get().status, amo.STATUS_UNREVIEWED) def test_no_homepage(self): @@ -2226,8 +2220,8 @@ def setUp(self): super(TestLanguagePack, self).setUp() self.addon = amo.tests.addon_factory(type=amo.ADDON_LPAPP, status=amo.STATUS_PUBLIC) - self.platform_all = Platform.objects.get(id=amo.PLATFORM_ALL.id) - self.platform_mob = Platform.objects.create(id=amo.PLATFORM_ANDROID.id) + self.platform_all = amo.PLATFORM_ALL.id + self.platform_mob = amo.PLATFORM_ANDROID.id self.version = self.addon.current_version def test_extract(self): diff --git a/apps/addons/tests/test_update.py b/apps/addons/tests/test_update.py index 77620975e21..6e5243dd604 100644 --- a/apps/addons/tests/test_update.py +++ b/apps/addons/tests/test_update.py @@ -26,10 +26,7 @@ def get(self, data): class TestDataValidate(VersionCheckMixin, amo.tests.TestCase): - fixtures = ['base/addon_3615', - 'base/platforms', - 'base/apps', - 'base/appversion'] + fixtures = ['base/addon_3615', 'base/apps', 'base/appversion'] def setUp(self): super(TestDataValidate, self).setUp() @@ -97,10 +94,7 @@ def test_no_version(self): class TestLookup(VersionCheckMixin, amo.tests.TestCase): - fixtures = ['addons/update', - 'base/apps', - 'base/appversion', - 'base/platforms'] + fixtures = ['addons/update', 'base/apps', 'base/appversion'] def setUp(self): super(TestLookup, self).setUp() @@ -297,7 +291,7 @@ def test_platform_does_not_exist(self): """If client passes a platform, find that specific platform.""" version = Version.objects.get(pk=115509) for file in version.files.all(): - file.platform_id = amo.PLATFORM_LINUX.id + file.platform = amo.PLATFORM_LINUX.id file.save() version, file = self.get('1.2', self.version_int, @@ -308,7 +302,7 @@ def test_platform_exists(self): """If client passes a platform, find that specific platform.""" version = Version.objects.get(pk=115509) for file in version.files.all(): - file.platform_id = amo.PLATFORM_LINUX.id + file.platform = amo.PLATFORM_LINUX.id file.save() version, file = self.get('1.2', self.version_int, @@ -319,11 +313,11 @@ def test_file_for_platform(self): """If client passes a platform, make sure we get the right file.""" version = Version.objects.get(pk=self.version_1_2_2) file_one = version.files.all()[0] - file_one.platform_id = amo.PLATFORM_LINUX.id + file_one.platform = amo.PLATFORM_LINUX.id file_one.save() file_two = File(version=version, filename='foo', hash='bar', - platform_id=amo.PLATFORM_WIN.id, + platform=amo.PLATFORM_WIN.id, status=amo.STATUS_PUBLIC) file_two.save() version, file = self.get('1.2', self.version_int, @@ -384,7 +378,7 @@ class TestDefaultToCompat(VersionCheckMixin, amo.tests.TestCase): """ Test default to compatible with all the various combinations of input. """ - fixtures = ['base/platforms', 'addons/default-to-compat'] + fixtures = ['addons/default-to-compat'] def setUp(self): super(TestDefaultToCompat, self).setUp() @@ -570,9 +564,7 @@ def test_min_max_version(self): class TestResponse(VersionCheckMixin, amo.tests.TestCase): - fixtures = ['base/addon_3615', - 'base/platforms', - 'base/seamonkey'] + fixtures = ['base/addon_3615', 'base/seamonkey'] def setUp(self): super(TestResponse, self).setUp() @@ -596,7 +588,7 @@ def test_bad_guid(self): def test_no_platform(self): file = File.objects.get(pk=67442) - file.platform_id = self.win.id + file.platform = self.win.id file.save() data = self.good_data.copy() @@ -611,12 +603,12 @@ def test_no_platform(self): def test_different_platform(self): file = File.objects.get(pk=67442) - file.platform_id = self.win.id + file.platform = self.win.id file.save() file_pk = file.pk file.id = None - file.platform_id = self.mac.id + file.platform = self.mac.id file.save() mac_file_pk = file.pk diff --git a/apps/amo/fixtures/base/addon_10423_youtubesearch.json b/apps/amo/fixtures/base/addon_10423_youtubesearch.json index 7a384f3462e..e46d0c005b1 100644 --- a/apps/amo/fixtures/base/addon_10423_youtubesearch.json +++ b/apps/amo/fixtures/base/addon_10423_youtubesearch.json @@ -71,14 +71,6 @@ "localized_string_clean": null } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 10423, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/addon_3615.json b/apps/amo/fixtures/base/addon_3615.json index 87e65e24ad2..a72878554a3 100644 --- a/apps/amo/fixtures/base/addon_3615.json +++ b/apps/amo/fixtures/base/addon_3615.json @@ -148,22 +148,6 @@ "id": 650353 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 2, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 3615, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/addon_4594_a9.json b/apps/amo/fixtures/base/addon_4594_a9.json index 164d4c69140..3e1cb2e73be 100644 --- a/apps/amo/fixtures/base/addon_4594_a9.json +++ b/apps/amo/fixtures/base/addon_4594_a9.json @@ -23,14 +23,6 @@ "localized_string_clean": null } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 4594, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/addon_4664_twitterbar.json b/apps/amo/fixtures/base/addon_4664_twitterbar.json index 6714e1059d5..2e6f352c44b 100644 --- a/apps/amo/fixtures/base/addon_4664_twitterbar.json +++ b/apps/amo/fixtures/base/addon_4664_twitterbar.json @@ -82,14 +82,6 @@ "localized_string_clean": "* Now with better and more relevant trending news in the Twitter sidebar." } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 4664, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/addon_5299_gcal.json b/apps/amo/fixtures/base/addon_5299_gcal.json index bc180cac182..3e4a5d452b0 100644 --- a/apps/amo/fixtures/base/addon_5299_gcal.json +++ b/apps/amo/fixtures/base/addon_5299_gcal.json @@ -22,14 +22,6 @@ "id": 58814 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 5299, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/addon_59.json b/apps/amo/fixtures/base/addon_59.json index 06a4ff8748b..a0642324742 100644 --- a/apps/amo/fixtures/base/addon_59.json +++ b/apps/amo/fixtures/base/addon_59.json @@ -76,14 +76,6 @@ "addon": 59 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 56975, "model": "files.file", diff --git a/apps/amo/fixtures/base/addon_592.json b/apps/amo/fixtures/base/addon_592.json index 61c32574b4b..11e72c3925f 100644 --- a/apps/amo/fixtures/base/addon_592.json +++ b/apps/amo/fixtures/base/addon_592.json @@ -21,14 +21,6 @@ "id": 3400 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 592, "model": "addons.addon", diff --git a/apps/amo/fixtures/base/addontag.json b/apps/amo/fixtures/base/addontag.json index 679801a005e..83183098cec 100644 --- a/apps/amo/fixtures/base/addontag.json +++ b/apps/amo/fixtures/base/addontag.json @@ -138,14 +138,6 @@ "addon": 8680 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 71943, "model": "files.file", diff --git a/apps/amo/fixtures/base/apps.json b/apps/amo/fixtures/base/apps.json index 35ee6b08b39..7a13086d395 100644 --- a/apps/amo/fixtures/base/apps.json +++ b/apps/amo/fixtures/base/apps.json @@ -52,21 +52,5 @@ "modified": "2006-08-21 23:53:19", "created": "2006-08-21 23:53:19" } - }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 2, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } } ] diff --git a/apps/amo/fixtures/base/featured.json b/apps/amo/fixtures/base/featured.json index bdd8e8bdabd..7ee56285fa3 100644 --- a/apps/amo/fixtures/base/featured.json +++ b/apps/amo/fixtures/base/featured.json @@ -477,14 +477,6 @@ "the_reason": null } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 15679, "model": "versions.version", diff --git a/apps/amo/fixtures/base/platforms.json b/apps/amo/fixtures/base/platforms.json deleted file mode 100644 index cb866dda404..00000000000 --- a/apps/amo/fixtures/base/platforms.json +++ /dev/null @@ -1,74 +0,0 @@ -[ - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 2, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 3, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 4, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 5, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:56", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 6, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:56", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 7, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:56", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 8, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:56", - "created": "2007-03-05 13:09:27" - } - }, - { - "pk": 9, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:56", - "created": "2007-03-05 13:09:27" - } - } -] diff --git a/apps/amo/fixtures/base/seamonkey.json b/apps/amo/fixtures/base/seamonkey.json index 8af0a25cb6d..63f57513d7b 100644 --- a/apps/amo/fixtures/base/seamonkey.json +++ b/apps/amo/fixtures/base/seamonkey.json @@ -89,14 +89,6 @@ "addon": 6076 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 49431, "model": "versions.version", diff --git a/apps/amo/tests/__init__.py b/apps/amo/tests/__init__.py index d45a0c26cfa..ab0cfdabf07 100644 --- a/apps/amo/tests/__init__.py +++ b/apps/amo/tests/__init__.py @@ -46,7 +46,7 @@ from amo.urlresolvers import get_url_prefix, Prefixer, reverse, set_url_prefix from applications.models import Application, AppVersion from bandwagon.models import Collection -from files.models import File, Platform +from files.models import File from lib.es.signals import process, reset from translations.hold import clean_translations from translations.models import Translation @@ -655,10 +655,9 @@ def collection_factory(**kw): def file_factory(**kw): v = kw['version'] - p, _ = Platform.objects.get_or_create(id=amo.PLATFORM_ALL.id) status = kw.pop('status', amo.STATUS_PUBLIC) f = File.objects.create(filename='%s-%s' % (v.addon_id, v.id), - platform=p, status=status, **kw) + platform=amo.PLATFORM_ALL.id, status=status, **kw) return f diff --git a/apps/api/templates/api/includes/addon.xml b/apps/api/templates/api/includes/addon.xml index 7e425a24c22..5b3b50222b7 100644 --- a/apps/api/templates/api/includes/addon.xml +++ b/apps/api/templates/api/includes/addon.xml @@ -90,7 +90,7 @@ {%- if version -%} {%- for file in version.all_files -%} {{ file.get_url_path('api') }} {% endfor -%} {%- endif -%} diff --git a/apps/api/tests/test_oauth.py b/apps/api/tests/test_oauth.py index 674f800388a..c05e033bc5e 100644 --- a/apps/api/tests/test_oauth.py +++ b/apps/api/tests/test_oauth.py @@ -182,8 +182,7 @@ def get_access_token(consumer, token, authorize=True, verifier=None): class BaseOAuth(TestCase): - fixtures = ['base/users', 'base/apps', 'base/appversion', 'base/platforms', - 'base/licenses'] + fixtures = ['base/users', 'base/apps', 'base/appversion', 'base/licenses'] def setUp(self): self.editor = UserProfile.objects.get(email='editor@mozilla.com') @@ -569,7 +568,7 @@ def test_create_version(self): v = a.versions.get(version='0.2') eq_(v.version, '0.2') # validate any new version data - eq_(v.files.get().amo_platform.shortname, 'windows') + eq_(amo.PLATFORMS[v.files.get().platform].shortname, 'windows') def test_create_version_bad_license(self): data = self.create_addon() diff --git a/apps/api/tests/test_views.py b/apps/api/tests/test_views.py index 057d9cb64ec..62fed014b42 100644 --- a/apps/api/tests/test_views.py +++ b/apps/api/tests/test_views.py @@ -24,7 +24,7 @@ from api.views import addon_filter from applications.models import Application, AppVersion from bandwagon.models import Collection, CollectionAddon, FeaturedCollection -from files.models import File, Platform +from files.models import File from files.tests.test_models import UploadTest from tags.models import AddonTag, Tag @@ -732,9 +732,8 @@ def test_app_filter(self): eq_(addons, [self.addon2]) def test_platform_filter(self): - platform, _ = Platform.objects.get_or_create(pk=amo.PLATFORM_WIN.id) file = self.addon1.current_version.files.all()[0] - file.update(platform=platform) + file.update(platform=amo.PLATFORM_WIN.id) # Transformers don't know 'bout my files. self.addons[0] = Addon.objects.get(pk=self.addons[0].pk) addons = addon_filter( @@ -927,7 +926,7 @@ def test_addon_compatibility_not_hosted(self): class SearchTest(ESTestCase): - fixtures = ('base/apps', 'base/platforms', 'base/appversion', + fixtures = ('base/apps', 'base/appversion', 'base/addon_6113', 'base/addon_40', 'base/addon_3615', 'base/addon_6704_grapple', 'base/addon_4664_twitterbar', 'base/addon_10423_youtubesearch', 'base/featured') @@ -1120,13 +1119,13 @@ def test_compat_mode_normal_and_binary_components_multi_file(self): addon = Addon.objects.get(pk=3615) file1 = addon.current_version.files.all()[0] - file1.update(platform=Platform(id=amo.PLATFORM_LINUX.id)) + file1.update(platform=amo.PLATFORM_LINUX.id) # Make a 2nd file just like the 1st, but with a different platform that # uses binary_components. file2 = file1 file2.id = None - file2.platform = Platform(id=amo.PLATFORM_WIN.id) + file2.platform = amo.PLATFORM_WIN.id file2.binary_components = True file2.save() @@ -1273,7 +1272,7 @@ class DRFSearchTest(DRFMixin, SearchTest): class LanguagePacks(UploadTest): - fixtures = ['addons/listed', 'base/apps', 'base/platforms'] + fixtures = ['addons/listed', 'base/apps'] def setUp(self): self.url = reverse('api.language', args=['1.5']) @@ -1311,7 +1310,7 @@ def test_search_no_localepicker(self): def setup_localepicker(self, platform): self.addon.update(type=amo.ADDON_LPAPP, status=amo.STATUS_PUBLIC) version = self.addon.versions.all()[0] - File.objects.create(version=version, platform_id=platform, + File.objects.create(version=version, platform=platform, status=amo.STATUS_PUBLIC) def test_search_wrong_platform(self): diff --git a/apps/browse/fixtures/browse/test_views.json b/apps/browse/fixtures/browse/test_views.json index b8874a053ff..48255f5a4a3 100644 --- a/apps/browse/fixtures/browse/test_views.json +++ b/apps/browse/fixtures/browse/test_views.json @@ -608,14 +608,6 @@ "min": 267 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 42473, "model": "files.file", diff --git a/apps/browse/tests.py b/apps/browse/tests.py index bcc0d0fb261..accd202ad40 100644 --- a/apps/browse/tests.py +++ b/apps/browse/tests.py @@ -335,8 +335,7 @@ def test_null_target_locale(self): class TestThemes(amo.tests.TestCase): - fixtures = ('base/category', 'base/platforms', 'base/addon_6704_grapple', - 'base/addon_3615') + fixtures = ('base/category', 'base/addon_6704_grapple', 'base/addon_3615') def setUp(self): super(TestThemes, self).setUp() diff --git a/apps/constants/platforms.py b/apps/constants/platforms.py index 59fe6819394..050cb921263 100644 --- a/apps/constants/platforms.py +++ b/apps/constants/platforms.py @@ -97,6 +97,13 @@ class PLATFORM_MAEMO: SUPPORTED_PLATFORMS = DESKTOP_PLATFORMS.copy() SUPPORTED_PLATFORMS.update(MOBILE_PLATFORMS) +DESKTOP_PLATFORMS_CHOICES = ( + (p.id, p.name) for p in DESKTOP_PLATFORMS.values() +) +MOBILE_PLATFORMS_CHOICES = ((p.id, p.name) for p in MOBILE_PLATFORMS.values()) +SUPPORTED_PLATFORMS_CHOICES = ( + (p.id, p.name) for p in SUPPORTED_PLATFORMS.values() +) PLATFORM_DICT = { 'all': PLATFORM_ALL, diff --git a/apps/devhub/fixtures/devhub/addon-compat-results.json b/apps/devhub/fixtures/devhub/addon-compat-results.json index f81f817f30e..a7d1c0fa827 100644 --- a/apps/devhub/fixtures/devhub/addon-compat-results.json +++ b/apps/devhub/fixtures/devhub/addon-compat-results.json @@ -134,14 +134,6 @@ "hotness": 0.0 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2010-01-02 12:34:56", - "created": "2010-01-02 12:34:56" - } - }, { "pk": 457235, "model": "versions.version", diff --git a/apps/devhub/fixtures/devhub/addon-file-100456.json b/apps/devhub/fixtures/devhub/addon-file-100456.json index 38ac120b373..bb0f7f9ef23 100644 --- a/apps/devhub/fixtures/devhub/addon-file-100456.json +++ b/apps/devhub/fixtures/devhub/addon-file-100456.json @@ -156,14 +156,6 @@ "user": 55021 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 118898, "model": "versions.version", diff --git a/apps/devhub/fixtures/devhub/addon-validation-1.json b/apps/devhub/fixtures/devhub/addon-validation-1.json index 072b872ba1a..3264e6d9d27 100644 --- a/apps/devhub/fixtures/devhub/addon-validation-1.json +++ b/apps/devhub/fixtures/devhub/addon-validation-1.json @@ -157,14 +157,6 @@ "user": 55021 } }, - { - "pk": 1, - "model": "files.platform", - "fields": { - "modified": "2008-04-07 08:16:55", - "created": "2007-03-05 13:09:27" - } - }, { "pk": 118898, "model": "versions.version", diff --git a/apps/devhub/forms.py b/apps/devhub/forms.py index 8645e3657f9..edd4fc8fdb6 100644 --- a/apps/devhub/forms.py +++ b/apps/devhub/forms.py @@ -28,7 +28,7 @@ from amo.utils import raise_required, slugify from applications.models import Application, AppVersion -from files.models import File, FileUpload, Platform +from files.models import File, FileUpload from files.utils import parse_addon, VERSION_RE from translations.widgets import TranslationTextarea, TranslationTextInput from translations.fields import TransTextarea, TransField @@ -500,21 +500,19 @@ def _clean_upload(self): class NewAddonForm(AddonUploadForm): - desktop_platforms = forms.ModelMultipleChoiceField( - queryset=Platform.objects, + desktop_platforms = forms.TypedMultipleChoiceField( + choices=amo.DESKTOP_PLATFORMS_CHOICES, widget=forms.CheckboxSelectMultiple(attrs={'class': 'platform'}), initial=[amo.PLATFORM_ALL.id], - required=False + required=False, + coerce=int ) - desktop_platforms.choices = ((p.id, p.name) - for p in amo.DESKTOP_PLATFORMS.values()) - mobile_platforms = forms.ModelMultipleChoiceField( - queryset=Platform.objects, + mobile_platforms = forms.TypedMultipleChoiceField( + choices=amo.MOBILE_PLATFORMS_CHOICES, widget=forms.CheckboxSelectMultiple(attrs={'class': 'platform'}), - required=False + required=False, + coerce=int ) - mobile_platforms.choices = ((p.id, p.name) - for p in amo.MOBILE_PLATFORMS.values()) def clean(self): if not self.errors: @@ -560,10 +558,17 @@ def clean(self): class NewFileForm(AddonUploadForm): - platform = File._meta.get_field('platform').formfield(empty_label=None, - widget=forms.RadioSelect(attrs={'class': 'platform'})) - platform.choices = sorted((p.id, p.name) - for p in amo.SUPPORTED_PLATFORMS.values()) + platform = forms.TypedChoiceField( + choices=amo.SUPPORTED_PLATFORMS_CHOICES, + widget=forms.RadioSelect(attrs={'class': 'platform'}), + coerce=int, + # We don't want the id value of the field to be output to the user + # when choice is invalid. Make a generic error message instead. + error_messages={ + 'invalid_choice': _lazy(u'Select a valid choice. That choice is ' + u'not one of the available choices.') + } + ) def __init__(self, *args, **kw): self.addon = kw.pop('addon') @@ -571,8 +576,8 @@ def __init__(self, *args, **kw): super(NewFileForm, self).__init__(*args, **kw) # Reset platform choices to just those compatible with target app. field = self.fields['platform'] - field.choices = sorted((k, v.name) for k, v in - self.version.compatible_platforms().items()) + field.choices = sorted((p.id, p.name) for p in + self.version.compatible_platforms().values()) # Don't allow platforms we already have. to_exclude = set(File.objects.filter(version=self.version) .values_list('platform', flat=True)) @@ -587,7 +592,6 @@ def __init__(self, *args, **kw): to_exclude.add(amo.PLATFORM_ALL_MOBILE.id) field.choices = [p for p in field.choices if p[0] not in to_exclude] - field.queryset = Platform.objects.filter(id__in=dict(field.choices)) def clean(self): if not self.version.is_allowed_upload(): @@ -603,7 +607,7 @@ def clean(self): class FileForm(happyforms.ModelForm): - platform = File._meta.get_field('platform').formfield(empty_label=None) + platform = File._meta.get_field('platform').formfield() class Meta: model = File @@ -619,7 +623,7 @@ def __init__(self, *args, **kw): # See bug 646268. if amo.PLATFORM_ALL_MOBILE.id in compat: del compat[amo.PLATFORM_ALL_MOBILE.id] - pid = int(kw['instance'].platform_id) + pid = int(kw['instance'].platform) plats = [(p.id, p.name) for p in compat.values()] if pid not in compat: plats.append([pid, amo.PLATFORMS[pid].name]) @@ -647,7 +651,7 @@ def clean(self): if not f.cleaned_data.get('DELETE', False)] if self.forms and 'platform' in self.forms[0].fields: - platforms = [f['platform'].id for f in files] + platforms = [f['platform'] for f in files] if amo.PLATFORM_ALL.id in platforms and len(files) > 1: raise forms.ValidationError( diff --git a/apps/devhub/helpers.py b/apps/devhub/helpers.py index 317ed549168..71c38f5479f 100644 --- a/apps/devhub/helpers.py +++ b/apps/devhub/helpers.py @@ -149,7 +149,7 @@ def status_choices(addon): @register.inclusion_tag('devhub/versions/file_status_message.html') def file_status_message(file, addon, file_history=False): choices = status_choices(addon) - return {'fileid': file.id, 'platform': file.amo_platform.name, + return {'fileid': file.id, 'platform': file.get_platform_display(), 'created': datetime(file.created), 'status': choices[file.status], 'file_history': file_history, diff --git a/apps/devhub/management/commands/search_platforms.py b/apps/devhub/management/commands/search_platforms.py index 837c6de4bf3..6403acdac8b 100644 --- a/apps/devhub/management/commands/search_platforms.py +++ b/apps/devhub/management/commands/search_platforms.py @@ -35,7 +35,7 @@ def change(): print 'Changing %s files' % len(files) for chunk in chunked(files, 100): for file in File.objects.no_cache().filter(pk__in=chunk): - file.platform_id = amo.PLATFORM_ALL.id + file.platform = amo.PLATFORM_ALL.id if not file.datestatuschanged: file.datestatuschanged = datetime.now() file.save() diff --git a/apps/devhub/templates/devhub/addons/listing/perf_file_listing.html b/apps/devhub/templates/devhub/addons/listing/perf_file_listing.html index a294b8c9626..c0a3fe8f6e5 100644 --- a/apps/devhub/templates/devhub/addons/listing/perf_file_listing.html +++ b/apps/devhub/templates/devhub/addons/listing/perf_file_listing.html @@ -1,6 +1,6 @@