Repository: mozmeao/snippets-service

Issue:
Add filter to distinguish between AS and non AS snippets.



Discussion:

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
@@ -13,7 +13,7 @@
 
 from snippets.base import forms, models
 from snippets.base.models import JINJA_ENV
-from snippets.base.admin.filters import ModifiedFilter, ReleaseFilter
+from snippets.base.admin import filters
 from snippets.base.admin.actions import duplicate_snippets_action
 
 
@@ -123,9 +123,9 @@ class ASRSnippetAdmin(admin.ModelAdmin):
         'modified',
     )
     list_filter = (
-        ModifiedFilter,
+        filters.ModifiedFilter,
         'status',
-        ReleaseFilter,
+        filters.ChannelFilter,
         ('template', RelatedDropdownFilter),
     )
     search_fields = (
diff --git a/snippets/base/admin/filters.py b/snippets/base/admin/filters.py
--- a/snippets/base/admin/filters.py
+++ b/snippets/base/admin/filters.py
@@ -36,9 +36,9 @@ def choices(self, cl):
             }
 
 
-class ReleaseFilter(admin.SimpleListFilter):
-    title = 'Release'
-    parameter_name = 'release'
+class ChannelFilter(admin.SimpleListFilter):
+    title = 'Channel'
+    parameter_name = 'channel'
 
     def lookups(self, request, model_admin):
         return (
@@ -54,3 +54,22 @@ def queryset(self, request, queryset):
             return queryset
 
         return queryset.filter(**{self.value(): True})
+
+
+class ActivityStreamFilter(admin.SimpleListFilter):
+    title = 'Activity Stream'
+    parameter_name = 'is_activity_stream'
+
+    def lookups(self, request, model_admin):
+        return (
+            ('yes', 'Yes'),
+            ('no', 'No'),
+        )
+
+    def queryset(self, request, queryset):
+        if self.value() is None:
+            return queryset
+        elif self.value() == 'yes':
+            return queryset.filter(on_startpage_5=True)
+        elif self.value() == 'no':
+            return queryset.exclude(on_startpage_5=True)
diff --git a/snippets/base/admin/legacy.py b/snippets/base/admin/legacy.py
--- a/snippets/base/admin/legacy.py
+++ b/snippets/base/admin/legacy.py
@@ -9,7 +9,7 @@
 
 from snippets.base import forms
 from snippets.base.admin.actions import duplicate_snippets_action
-from snippets.base.admin.filters import ModifiedFilter, ReleaseFilter
+from snippets.base.admin import filters
 
 
 class BaseSnippetAdmin(VersionAdmin, admin.ModelAdmin):
@@ -59,10 +59,11 @@ class SnippetAdmin(QuickEditAdmin, BaseSnippetAdmin):
     search_fields = ('id', 'name', 'client_match_rules__description',
                      'template__name', 'campaign')
     list_filter = (
-        ModifiedFilter,
+        filters.ModifiedFilter,
         'published',
         'ready_for_review',
-        ReleaseFilter,
+        filters.ChannelFilter,
+        filters.ActivityStreamFilter,
         ('locales', RelatedDropdownFilter),
         ('client_match_rules', RelatedDropdownFilter),
         ('template', RelatedDropdownFilter),
@@ -187,9 +188,9 @@ class JSONSnippetAdmin(BaseSnippetAdmin):
     form = forms.JSONSnippetAdminForm
     search_fields = ('name', 'client_match_rules__description')
     list_filter = (
-        ModifiedFilter,
+        filters.ModifiedFilter,
         'published',
-        ReleaseFilter,
+        filters.ChannelFilter,
         ('locales', RelatedDropdownFilter),
         ('client_match_rules', RelatedDropdownFilter),
     )


Test patch: