Repository: mozmeao/snippets-service

Issue:
JEXL Targeting: Snippet Weight
Waiting on ASR implementation  https://bugzilla.mozilla.org/show_bug.cgi?id=1484996 


Discussion:
This is marked "Third Priority" by the ASR team and may not be implemented for Fx63. Moved to the bottom of the milestone
Update from the AS team: Bug got fixed, will try to get this uplifted.

Resolving patch:
diff --git a/snippets/base/admin/adminmodels.py b/snippets/base/admin/adminmodels.py
--- a/snippets/base/admin/adminmodels.py
+++ b/snippets/base/admin/adminmodels.py
@@ -144,7 +144,7 @@ class ASRSnippetAdmin(admin.ModelAdmin):
     fieldsets = (
         ('ID', {'fields': ('creator', 'name', 'status', 'preview_url')}),
         ('Publishing Options', {
-            'fields': ('campaign', 'target', ('publish_start', 'publish_end'))
+            'fields': ('campaign', 'target', ('publish_start', 'publish_end'), 'weight',)
         }),
         ('Content', {
             'fields': ('template', 'data'),
diff --git a/snippets/base/migrations/0049_auto_20180925_1059.py b/snippets/base/migrations/0049_auto_20180925_1059.py
new file mode 100644
--- /dev/null
+++ b/snippets/base/migrations/0049_auto_20180925_1059.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.1 on 2018-09-25 10:59
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0048_auto_20180919_0816'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='asrsnippet',
+            name='weight',
+            field=models.IntegerField(choices=[(33, 'Appear 1/3rd as often as an average snippet'), (50, 'Appear half as often as an average snippet'), (66, 'Appear 2/3rds as often as an average snippet'), (100, 'Appear as often as an average snippet'), (150, 'Appear 1.5 times as often as an average snippet'), (200, 'Appear twice as often as an average snippet'), (300, 'Appear three times as often as an average snippet')], default=100, help_text='How often should this snippet be shown to users?', verbose_name='Prevalence'),
+        ),
+    ]
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -592,6 +592,10 @@ class ASRSnippet(django_mysql.models.Model):
     target = models.ForeignKey(Target, on_delete=models.PROTECT,
                                default=None, blank=True, null=True)
 
+    weight = models.IntegerField(
+        choices=SNIPPET_WEIGHTS, default=100,
+        help_text='How often should this snippet be shown to users?')
+
     objects = ASRSnippetManager()
 
     class Meta:
@@ -621,6 +625,7 @@ def render(self):
             'template': self.template.code_name,
             'template_version': self.template.version,
             'campaign': self.campaign.slug,
+            'weight': self.weight,
             'content': data,
         }
 


Test patch:
diff --git a/snippets/base/tests/test_models.py b/snippets/base/tests/test_models.py
--- a/snippets/base/tests/test_models.py
+++ b/snippets/base/tests/test_models.py
@@ -339,6 +339,7 @@ def test_render(self):
             'template': snippet.template.code_name,
             'template_version': snippet.template.version,
             'campaign': snippet.campaign.slug,
+            'weight': snippet.weight,
             'content': {
                 'text': 'snippet id {}'.format(snippet.id),
                 'foo': 'bar',