diff --git a/normandy/recipes/filters.py b/normandy/recipes/filters.py index abfa60fb6..532202cd4 100644 --- a/normandy/recipes/filters.py +++ b/normandy/recipes/filters.py @@ -602,7 +602,7 @@ class WindowsVersionFilter(BaseComparisonFilter): ``windows_version`` .. attribute:: value - string, must be one of the following: 6.1, 6.2, 6.3, 10.0 + number, decimal, must be one of the following: 6.1, 6.2, 6.3, 10.0 :example: ``6.1`` @@ -614,7 +614,7 @@ class WindowsVersionFilter(BaseComparisonFilter): """ type = "windows_version" - value = serializers.CharField() + value = serializers.DecimalField(max_digits=3, decimal_places=1) @property def left_of_operator(self): @@ -626,7 +626,7 @@ def to_jexl(self): def validate_value(self, value): from normandy.recipes.models import WindowsVersion - if not WindowsVersion.objects.filter(slug=value).exists(): + if not WindowsVersion.objects.filter(nt_version=value).exists(): raise serializers.ValidationError(f"Unrecognized windows version slug {value!r}") return value @@ -700,6 +700,7 @@ def capabilities(self): PrefExistsFilter, PrefCompareFilter, PrefUserSetFilter, + WindowsVersionFilter, ] } diff --git a/normandy/recipes/management/commands/initial_data.py b/normandy/recipes/management/commands/initial_data.py index 2da072fc6..0b4a0999f 100644 --- a/normandy/recipes/management/commands/initial_data.py +++ b/normandy/recipes/management/commands/initial_data.py @@ -45,13 +45,13 @@ def add_countries(self): def add_windows_versions(self): self.stdout.write("Adding Windows Versions...", ending="") - versions = { - "6.1": "Windows 7", - "6.2": "Windows 8", - "6.3": "Windows 8.1", - "10.0": "Windows 10.0", - } - - for slug, name in versions.items(): - WindowsVersion.objects.update_or_create(slug=slug, defaults={"name": name}) + versions = [ + (6.1, "Windows 7"), + (6.2, "Windows 8"), + (6.3, "Windows 8.1"), + (10.0, "Windows 10"), + ] + + for nt_version, name in versions: + WindowsVersion.objects.update_or_create(nt_version=nt_version, defaults={"name": name}) self.stdout.write("Done") diff --git a/normandy/recipes/migrations/0018_windowsversion.py b/normandy/recipes/migrations/0018_windowsversion.py index fcf1595e6..04b3b93c3 100644 --- a/normandy/recipes/migrations/0018_windowsversion.py +++ b/normandy/recipes/migrations/0018_windowsversion.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.10 on 2020-03-16 23:24 +# Generated by Django 2.2.10 on 2020-03-18 20:48 from django.db import migrations, models @@ -17,9 +17,9 @@ class Migration(migrations.Migration): auto_created=True, primary_key=True, serialize=False, verbose_name="ID" ), ), - ("slug", models.CharField(max_length=255, unique=True)), + ("nt_version", models.DecimalField(decimal_places=1, max_digits=3)), ("name", models.CharField(max_length=255)), ], - options={"ordering": ("slug",)}, + options={"ordering": ("nt_version",)}, ) ] diff --git a/normandy/recipes/models.py b/normandy/recipes/models.py index f2a122647..30a69c9f0 100644 --- a/normandy/recipes/models.py +++ b/normandy/recipes/models.py @@ -45,14 +45,14 @@ def __repr__(self): class WindowsVersion(models.Model): - slug = models.CharField(max_length=255, unique=True) + nt_version = models.DecimalField(max_digits=3, decimal_places=1) name = models.CharField(max_length=255) class Meta: - ordering = ("slug",) + ordering = ("nt_version",) def __repr__(self): - return "".format(self.slug) + return "".format(self.nt_version) class Country(models.Model): diff --git a/normandy/recipes/tests/__init__.py b/normandy/recipes/tests/__init__.py index fcf96dbbe..765858324 100644 --- a/normandy/recipes/tests/__init__.py +++ b/normandy/recipes/tests/__init__.py @@ -34,9 +34,9 @@ class Meta: class WindowsVersionFactory(factory.DjangoModelFactory): class Meta: model = WindowsVersion - django_get_or_create = ("slug",) + django_get_or_create = ("nt_version",) - slug = "6.1" + nt_version = 6.1 name = "Windows 7" diff --git a/normandy/recipes/tests/test_filters.py b/normandy/recipes/tests/test_filters.py index 3c979067d..0b678061d 100644 --- a/normandy/recipes/tests/test_filters.py +++ b/normandy/recipes/tests/test_filters.py @@ -156,8 +156,8 @@ def test_generates_jexl_error_on_bad_comparison(self): class TestWindowsVersionFilter(FilterTestsBase): - def create_basic_filter(self, value="6.1", comparison="equal"): - WindowsVersionFactory(slug="6.1") + def create_basic_filter(self, value=6.1, comparison="equal"): + WindowsVersionFactory(nt_version=6.1) return WindowsVersionFilter.create(value=value, comparison=comparison)