We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ASR Snippet Admin: Be able to search for a snippet by Snippet ID in top search bar on list view page
Currently the search bar only allows for searching keywords.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `snippets/base/admin/adminmodels.py`
Content:
```
1 import re
2 
3 from django.contrib import admin
4 from django.db.models import TextField, Q
5 from django.template.loader import get_template
6 from django.utils.safestring import mark_safe
7 
8 from reversion.admin import VersionAdmin
9 from django_ace import AceWidget
10 from django_statsd.clients import statsd
11 from jinja2.meta import find_undeclared_variables
12 from django_admin_listfilter_dropdown.filters import RelatedDropdownFilter
13 
14 from snippets.base import forms, models
15 from snippets.base.models import JINJA_ENV
16 from snippets.base.admin.filters import ModifiedFilter, ReleaseFilter
17 from snippets.base.admin.actions import duplicate_snippets_action
18 
19 
20 MATCH_LOCALE_REGEX = re.compile('(\w+(?:-\w+)*)')
21 RESERVED_VARIABLES = ('_', 'snippet_id')
22 
23 
24 class ClientMatchRuleAdmin(VersionAdmin, admin.ModelAdmin):
25     list_display = ('description', 'is_exclusion', 'startpage_version', 'name',
26                     'version', 'locale', 'appbuildid', 'build_target',
27                     'channel', 'os_version', 'distribution',
28                     'distribution_version', 'modified')
29     list_filter = ('name', 'version', 'os_version', 'appbuildid',
30                    'build_target', 'channel', 'distribution', 'locale')
31     save_on_top = True
32     search_fields = ('description',)
33 
34 
35 class LogEntryAdmin(admin.ModelAdmin):
36     list_display = ('user', 'content_type', 'object_id', 'object_repr', 'change_message')
37     list_filter = ('user', 'content_type')
38 
39 
40 class SnippetTemplateVariableInline(admin.TabularInline):
41     model = models.SnippetTemplateVariable
42     formset = forms.SnippetTemplateVariableInlineFormset
43     max_num = 0
44     can_delete = False
45     readonly_fields = ('name',)
46     fields = ('name', 'type', 'order', 'description')
47 
48 
49 class SnippetTemplateAdmin(VersionAdmin, admin.ModelAdmin):
50     save_on_top = True
51     list_display = ('name', 'priority', 'hidden')
52     list_filter = ('hidden', 'startpage')
53     inlines = (SnippetTemplateVariableInline,)
54     formfield_overrides = {
55         TextField: {'widget': AceWidget(mode='html', theme='github',
56                                         width='1200px', height='500px')},
57     }
58 
59     class Media:
60         css = {
61             'all': ('css/admin.css',)
62         }
63 
64     def save_related(self, request, form, formsets, change):
65         """
66         After saving the related objects, remove and add
67         SnippetTemplateVariables depending on how the template code changed.
68         """
69         super(SnippetTemplateAdmin, self).save_related(request, form, formsets,
70                                                        change)
71 
72         # Parse the template code and find any undefined variables.
73         ast = JINJA_ENV.env.parse(form.instance.code)
74         new_vars = find_undeclared_variables(ast)
75         var_manager = form.instance.variable_set
76 
77         # Filter out reserved variable names.
78         new_vars = [x for x in new_vars if x not in RESERVED_VARIABLES]
79 
80         # Delete variables not in the new set.
81         var_manager.filter(~Q(name__in=new_vars)).delete()
82 
83         # Create variables that don't exist.
84         for i, variable in enumerate(new_vars, start=1):
85             obj, _ = models.SnippetTemplateVariable.objects.get_or_create(
86                 template=form.instance, name=variable)
87             if obj.order == 0:
88                 obj.order = i * 10
89                 obj.save()
90 
91 
92 class UploadedFileAdmin(admin.ModelAdmin):
93     readonly_fields = ('url', 'preview', 'snippets')
94     list_display = ('name', 'url', 'preview', 'modified')
95     prepopulated_fields = {'name': ('file',)}
96     form = forms.UploadedFileAdminForm
97 
98     def preview(self, obj):
99         template = get_template('base/uploadedfile_preview.jinja')
100         return mark_safe(template.render({'file': obj}))
101 
102     def snippets(self, obj):
103         """Snippets using this file."""
104         template = get_template('base/uploadedfile_snippets.jinja')
105         return mark_safe(template.render({'snippets': obj.snippets}))
106 
107 
108 class AddonAdmin(admin.ModelAdmin):
109     list_display = ('name', 'guid')
110 
111 
112 class ASRSnippetAdmin(admin.ModelAdmin):
113     form = forms.ASRSnippetAdminForm
114 
115     list_display_links = (
116         'id',
117         'name',
118     )
119     list_display = (
120         'id',
121         'name',
122         'status',
123         'modified',
124     )
125     list_filter = (
126         ModifiedFilter,
127         'status',
128         ReleaseFilter,
129         ('template', RelatedDropdownFilter),
130     )
131     search_fields = (
132         'name',
133     )
134     autocomplete_fields = (
135         'campaign',
136         'target',
137     )
138     preserve_filters = True
139     readonly_fields = (
140         'created',
141         'modified',
142         'uuid',
143         'creator',
144         'preview_url',
145     )
146     filter_horizontal = ('locales',)
147     save_on_top = True
148     save_as = True
149     view_on_site = False
150     actions = (
151         duplicate_snippets_action,
152     )
153 
154     fieldsets = (
155         ('ID', {'fields': ('creator', 'name', 'status', 'preview_url')}),
156         ('Content', {
157             'description': (
158                 '''
159                 <strong>Available deep links:</strong><br/>
160                 <ol>
161                   <li><code>special:accounts</code> to open Firefox Accounts</li>
162                   <li><code>special:appMenu</code> to open the hamburger menu</li>
163                 </ol><br/>
164                 <strong>Automatically add Snippet ID:</strong><br/>
165                 You can use <code>[[snippet_id]]</code> in any field and it
166                 will be automatically replaced by Snippet ID when served to users.
167                 <br/>
168                 Example: This is a <code>&lt;a href=&quot;https://example.com?utm_term=[[snippet_id]]&quot;&gt;link&lt;/a&gt;</code>  # noqa
169                 <br/>
170                 '''
171             ),
172             'fields': ('template', 'data'),
173         }),
174         ('Publishing Options', {
175             'fields': ('campaign', 'target', ('publish_start', 'publish_end'), 'locales', 'weight',)
176         }),
177         ('Other Info', {
178             'fields': ('uuid', ('created', 'modified')),
179             'classes': ('collapse',)
180         }),
181     )
182 
183     class Media:
184         css = {
185             'all': ('css/admin/ASRSnippetAdmin.css',)
186         }
187         js = (
188             'js/admin/clipboard.min.js',
189             'js/admin/copy_preview.js',
190         )
191 
192     def save_model(self, request, obj, form, change):
193         if not obj.creator_id:
194             obj.creator = request.user
195         statsd.incr('save.asrsnippet')
196         super().save_model(request, obj, form, change)
197 
198     def preview_url(self, obj):
199         text = f'''
200         <span id="previewLinkUrl">{obj.get_preview_url()}</span>
201         <button id="copyPreviewLink" class="btn"
202                 data-clipboard-target="#previewLinkUrl"
203                 originalText="Copy to Clipboard" type="button">
204           Copy to Clipboard
205         </button>
206         '''
207         return mark_safe(text)
208 
209     def change_view(self, request, *args, **kwargs):
210         if request.method == 'POST' and '_saveasnew' in request.POST:
211             # Always saved cloned snippets as un-published and un-check ready for review.
212             post_data = request.POST.copy()
213             post_data['status'] = models.STATUS_CHOICES['Draft']
214             request.POST = post_data
215         return super().change_view(request, *args, **kwargs)
216 
217 
218 class CampaignAdmin(admin.ModelAdmin):
219     readonly_fields = ('created', 'modified', 'creator',)
220     prepopulated_fields = {'slug': ('name',)}
221 
222     fieldsets = (
223         ('ID', {'fields': ('name', 'slug')}),
224         ('Other Info', {
225             'fields': ('creator', ('created', 'modified')),
226         }),
227     )
228     search_fields = (
229         'name',
230     )
231 
232     def save_model(self, request, obj, form, change):
233         if not obj.creator_id:
234             obj.creator = request.user
235         statsd.incr('save.campaign')
236         super().save_model(request, obj, form, change)
237 
238 
239 class TargetAdmin(admin.ModelAdmin):
240     form = forms.TargetAdminForm
241     readonly_fields = ('created', 'modified', 'creator', 'jexl_expr')
242     search_fields = (
243         'name',
244     )
245     fieldsets = (
246         ('ID', {'fields': ('name',)}),
247         ('Product channels', {
248             'description': 'What channels will this snippet be available in?',
249             'fields': (('on_release', 'on_beta', 'on_aurora', 'on_nightly', 'on_esr'),)
250         }),
251         ('Targeting', {
252             'fields': (
253                 'filtr_is_default_browser',
254                 'filtr_updates_enabled',
255                 'filtr_updates_autodownload_enabled',
256                 'filtr_profile_age_created',
257                 'filtr_firefox_version',
258                 'filtr_previous_session_end',
259                 'filtr_uses_firefox_sync',
260                 'filtr_country',
261                 'filtr_is_developer',
262                 'filtr_current_search_engine',
263                 'filtr_browser_addon',
264                 'filtr_total_bookmarks_count',
265             )
266         }),
267         ('Other Info', {
268             'fields': ('creator', ('created', 'modified'), 'jexl_expr'),
269         }),
270     )
271 
272     def save_model(self, request, obj, form, change):
273         if not obj.creator_id:
274             obj.creator = request.user
275         statsd.incr('save.target')
276         super().save_model(request, obj, form, change)
277
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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
@@ -130,6 +130,9 @@
     )
     search_fields = (
         'name',
+        'id',
+        'campaign__name',
+        'target__name',
     )
     autocomplete_fields = (
         'campaign',
@@ -143,7 +146,9 @@
         'creator',
         'preview_url',
     )
-    filter_horizontal = ('locales',)
+    filter_horizontal = (
+        'locales',
+    )
     save_on_top = True
     save_as = True
     view_on_site = False

{"golden_diff": "diff --git a/snippets/base/admin/adminmodels.py b/snippets/base/admin/adminmodels.py\n--- a/snippets/base/admin/adminmodels.py\n+++ b/snippets/base/admin/adminmodels.py\n@@ -130,6 +130,9 @@\n     )\n     search_fields = (\n         'name',\n+        'id',\n+        'campaign__name',\n+        'target__name',\n     )\n     autocomplete_fields = (\n         'campaign',\n@@ -143,7 +146,9 @@\n         'creator',\n         'preview_url',\n     )\n-    filter_horizontal = ('locales',)\n+    filter_horizontal = (\n+        'locales',\n+    )\n     save_on_top = True\n     save_as = True\n     view_on_site = False\n", "issue": "ASR Snippet Admin: Be able to search for a snippet by Snippet ID in top search bar on list view page\nCurrently the search bar only allows for searching keywords.\n", "before_files": [{"content": "import re\n\nfrom django.contrib import admin\nfrom django.db.models import TextField, Q\nfrom django.template.loader import get_template\nfrom django.utils.safestring import mark_safe\n\nfrom reversion.admin import VersionAdmin\nfrom django_ace import AceWidget\nfrom django_statsd.clients import statsd\nfrom jinja2.meta import find_undeclared_variables\nfrom django_admin_listfilter_dropdown.filters import RelatedDropdownFilter\n\nfrom snippets.base import forms, models\nfrom snippets.base.models import JINJA_ENV\nfrom snippets.base.admin.filters import ModifiedFilter, ReleaseFilter\nfrom snippets.base.admin.actions import duplicate_snippets_action\n\n\nMATCH_LOCALE_REGEX = re.compile('(\\w+(?:-\\w+)*)')\nRESERVED_VARIABLES = ('_', 'snippet_id')\n\n\nclass ClientMatchRuleAdmin(VersionAdmin, admin.ModelAdmin):\n    list_display = ('description', 'is_exclusion', 'startpage_version', 'name',\n                    'version', 'locale', 'appbuildid', 'build_target',\n                    'channel', 'os_version', 'distribution',\n                    'distribution_version', 'modified')\n    list_filter = ('name', 'version', 'os_version', 'appbuildid',\n                   'build_target', 'channel', 'distribution', 'locale')\n    save_on_top = True\n    search_fields = ('description',)\n\n\nclass LogEntryAdmin(admin.ModelAdmin):\n    list_display = ('user', 'content_type', 'object_id', 'object_repr', 'change_message')\n    list_filter = ('user', 'content_type')\n\n\nclass SnippetTemplateVariableInline(admin.TabularInline):\n    model = models.SnippetTemplateVariable\n    formset = forms.SnippetTemplateVariableInlineFormset\n    max_num = 0\n    can_delete = False\n    readonly_fields = ('name',)\n    fields = ('name', 'type', 'order', 'description')\n\n\nclass SnippetTemplateAdmin(VersionAdmin, admin.ModelAdmin):\n    save_on_top = True\n    list_display = ('name', 'priority', 'hidden')\n    list_filter = ('hidden', 'startpage')\n    inlines = (SnippetTemplateVariableInline,)\n    formfield_overrides = {\n        TextField: {'widget': AceWidget(mode='html', theme='github',\n                                        width='1200px', height='500px')},\n    }\n\n    class Media:\n        css = {\n            'all': ('css/admin.css',)\n        }\n\n    def save_related(self, request, form, formsets, change):\n        \"\"\"\n        After saving the related objects, remove and add\n        SnippetTemplateVariables depending on how the template code changed.\n        \"\"\"\n        super(SnippetTemplateAdmin, self).save_related(request, form, formsets,\n                                                       change)\n\n        # Parse the template code and find any undefined variables.\n        ast = JINJA_ENV.env.parse(form.instance.code)\n        new_vars = find_undeclared_variables(ast)\n        var_manager = form.instance.variable_set\n\n        # Filter out reserved variable names.\n        new_vars = [x for x in new_vars if x not in RESERVED_VARIABLES]\n\n        # Delete variables not in the new set.\n        var_manager.filter(~Q(name__in=new_vars)).delete()\n\n        # Create variables that don't exist.\n        for i, variable in enumerate(new_vars, start=1):\n            obj, _ = models.SnippetTemplateVariable.objects.get_or_create(\n                template=form.instance, name=variable)\n            if obj.order == 0:\n                obj.order = i * 10\n                obj.save()\n\n\nclass UploadedFileAdmin(admin.ModelAdmin):\n    readonly_fields = ('url', 'preview', 'snippets')\n    list_display = ('name', 'url', 'preview', 'modified')\n    prepopulated_fields = {'name': ('file',)}\n    form = forms.UploadedFileAdminForm\n\n    def preview(self, obj):\n        template = get_template('base/uploadedfile_preview.jinja')\n        return mark_safe(template.render({'file': obj}))\n\n    def snippets(self, obj):\n        \"\"\"Snippets using this file.\"\"\"\n        template = get_template('base/uploadedfile_snippets.jinja')\n        return mark_safe(template.render({'snippets': obj.snippets}))\n\n\nclass AddonAdmin(admin.ModelAdmin):\n    list_display = ('name', 'guid')\n\n\nclass ASRSnippetAdmin(admin.ModelAdmin):\n    form = forms.ASRSnippetAdminForm\n\n    list_display_links = (\n        'id',\n        'name',\n    )\n    list_display = (\n        'id',\n        'name',\n        'status',\n        'modified',\n    )\n    list_filter = (\n        ModifiedFilter,\n        'status',\n        ReleaseFilter,\n        ('template', RelatedDropdownFilter),\n    )\n    search_fields = (\n        'name',\n    )\n    autocomplete_fields = (\n        'campaign',\n        'target',\n    )\n    preserve_filters = True\n    readonly_fields = (\n        'created',\n        'modified',\n        'uuid',\n        'creator',\n        'preview_url',\n    )\n    filter_horizontal = ('locales',)\n    save_on_top = True\n    save_as = True\n    view_on_site = False\n    actions = (\n        duplicate_snippets_action,\n    )\n\n    fieldsets = (\n        ('ID', {'fields': ('creator', 'name', 'status', 'preview_url')}),\n        ('Content', {\n            'description': (\n                '''\n                <strong>Available deep links:</strong><br/>\n                <ol>\n                  <li><code>special:accounts</code> to open Firefox Accounts</li>\n                  <li><code>special:appMenu</code> to open the hamburger menu</li>\n                </ol><br/>\n                <strong>Automatically add Snippet ID:</strong><br/>\n                You can use <code>[[snippet_id]]</code> in any field and it\n                will be automatically replaced by Snippet ID when served to users.\n                <br/>\n                Example: This is a <code>&lt;a href=&quot;https://example.com?utm_term=[[snippet_id]]&quot;&gt;link&lt;/a&gt;</code>  # noqa\n                <br/>\n                '''\n            ),\n            'fields': ('template', 'data'),\n        }),\n        ('Publishing Options', {\n            'fields': ('campaign', 'target', ('publish_start', 'publish_end'), 'locales', 'weight',)\n        }),\n        ('Other Info', {\n            'fields': ('uuid', ('created', 'modified')),\n            'classes': ('collapse',)\n        }),\n    )\n\n    class Media:\n        css = {\n            'all': ('css/admin/ASRSnippetAdmin.css',)\n        }\n        js = (\n            'js/admin/clipboard.min.js',\n            'js/admin/copy_preview.js',\n        )\n\n    def save_model(self, request, obj, form, change):\n        if not obj.creator_id:\n            obj.creator = request.user\n        statsd.incr('save.asrsnippet')\n        super().save_model(request, obj, form, change)\n\n    def preview_url(self, obj):\n        text = f'''\n        <span id=\"previewLinkUrl\">{obj.get_preview_url()}</span>\n        <button id=\"copyPreviewLink\" class=\"btn\"\n                data-clipboard-target=\"#previewLinkUrl\"\n                originalText=\"Copy to Clipboard\" type=\"button\">\n          Copy to Clipboard\n        </button>\n        '''\n        return mark_safe(text)\n\n    def change_view(self, request, *args, **kwargs):\n        if request.method == 'POST' and '_saveasnew' in request.POST:\n            # Always saved cloned snippets as un-published and un-check ready for review.\n            post_data = request.POST.copy()\n            post_data['status'] = models.STATUS_CHOICES['Draft']\n            request.POST = post_data\n        return super().change_view(request, *args, **kwargs)\n\n\nclass CampaignAdmin(admin.ModelAdmin):\n    readonly_fields = ('created', 'modified', 'creator',)\n    prepopulated_fields = {'slug': ('name',)}\n\n    fieldsets = (\n        ('ID', {'fields': ('name', 'slug')}),\n        ('Other Info', {\n            'fields': ('creator', ('created', 'modified')),\n        }),\n    )\n    search_fields = (\n        'name',\n    )\n\n    def save_model(self, request, obj, form, change):\n        if not obj.creator_id:\n            obj.creator = request.user\n        statsd.incr('save.campaign')\n        super().save_model(request, obj, form, change)\n\n\nclass TargetAdmin(admin.ModelAdmin):\n    form = forms.TargetAdminForm\n    readonly_fields = ('created', 'modified', 'creator', 'jexl_expr')\n    search_fields = (\n        'name',\n    )\n    fieldsets = (\n        ('ID', {'fields': ('name',)}),\n        ('Product channels', {\n            'description': 'What channels will this snippet be available in?',\n            'fields': (('on_release', 'on_beta', 'on_aurora', 'on_nightly', 'on_esr'),)\n        }),\n        ('Targeting', {\n            'fields': (\n                'filtr_is_default_browser',\n                'filtr_updates_enabled',\n                'filtr_updates_autodownload_enabled',\n                'filtr_profile_age_created',\n                'filtr_firefox_version',\n                'filtr_previous_session_end',\n                'filtr_uses_firefox_sync',\n                'filtr_country',\n                'filtr_is_developer',\n                'filtr_current_search_engine',\n                'filtr_browser_addon',\n                'filtr_total_bookmarks_count',\n            )\n        }),\n        ('Other Info', {\n            'fields': ('creator', ('created', 'modified'), 'jexl_expr'),\n        }),\n    )\n\n    def save_model(self, request, obj, form, change):\n        if not obj.creator_id:\n            obj.creator = request.user\n        statsd.incr('save.target')\n        super().save_model(request, obj, form, change)\n", "path": "snippets/base/admin/adminmodels.py"}], "after_files": [{"content": "import re\n\nfrom django.contrib import admin\nfrom django.db.models import TextField, Q\nfrom django.template.loader import get_template\nfrom django.utils.safestring import mark_safe\n\nfrom reversion.admin import VersionAdmin\nfrom django_ace import AceWidget\nfrom django_statsd.clients import statsd\nfrom jinja2.meta import find_undeclared_variables\nfrom django_admin_listfilter_dropdown.filters import RelatedDropdownFilter\n\nfrom snippets.base import forms, models\nfrom snippets.base.models import JINJA_ENV\nfrom snippets.base.admin.filters import ModifiedFilter, ReleaseFilter\nfrom snippets.base.admin.actions import duplicate_snippets_action\n\n\nMATCH_LOCALE_REGEX = re.compile('(\\w+(?:-\\w+)*)')\nRESERVED_VARIABLES = ('_', 'snippet_id')\n\n\nclass ClientMatchRuleAdmin(VersionAdmin, admin.ModelAdmin):\n    list_display = ('description', 'is_exclusion', 'startpage_version', 'name',\n                    'version', 'locale', 'appbuildid', 'build_target',\n                    'channel', 'os_version', 'distribution',\n                    'distribution_version', 'modified')\n    list_filter = ('name', 'version', 'os_version', 'appbuildid',\n                   'build_target', 'channel', 'distribution', 'locale')\n    save_on_top = True\n    search_fields = ('description',)\n\n\nclass LogEntryAdmin(admin.ModelAdmin):\n    list_display = ('user', 'content_type', 'object_id', 'object_repr', 'change_message')\n    list_filter = ('user', 'content_type')\n\n\nclass SnippetTemplateVariableInline(admin.TabularInline):\n    model = models.SnippetTemplateVariable\n    formset = forms.SnippetTemplateVariableInlineFormset\n    max_num = 0\n    can_delete = False\n    readonly_fields = ('name',)\n    fields = ('name', 'type', 'order', 'description')\n\n\nclass SnippetTemplateAdmin(VersionAdmin, admin.ModelAdmin):\n    save_on_top = True\n    list_display = ('name', 'priority', 'hidden')\n    list_filter = ('hidden', 'startpage')\n    inlines = (SnippetTemplateVariableInline,)\n    formfield_overrides = {\n        TextField: {'widget': AceWidget(mode='html', theme='github',\n                                        width='1200px', height='500px')},\n    }\n\n    class Media:\n        css = {\n            'all': ('css/admin.css',)\n        }\n\n    def save_related(self, request, form, formsets, change):\n        \"\"\"\n        After saving the related objects, remove and add\n        SnippetTemplateVariables depending on how the template code changed.\n        \"\"\"\n        super(SnippetTemplateAdmin, self).save_related(request, form, formsets,\n                                                       change)\n\n        # Parse the template code and find any undefined variables.\n        ast = JINJA_ENV.env.parse(form.instance.code)\n        new_vars = find_undeclared_variables(ast)\n        var_manager = form.instance.variable_set\n\n        # Filter out reserved variable names.\n        new_vars = [x for x in new_vars if x not in RESERVED_VARIABLES]\n\n        # Delete variables not in the new set.\n        var_manager.filter(~Q(name__in=new_vars)).delete()\n\n        # Create variables that don't exist.\n        for i, variable in enumerate(new_vars, start=1):\n            obj, _ = models.SnippetTemplateVariable.objects.get_or_create(\n                template=form.instance, name=variable)\n            if obj.order == 0:\n                obj.order = i * 10\n                obj.save()\n\n\nclass UploadedFileAdmin(admin.ModelAdmin):\n    readonly_fields = ('url', 'preview', 'snippets')\n    list_display = ('name', 'url', 'preview', 'modified')\n    prepopulated_fields = {'name': ('file',)}\n    form = forms.UploadedFileAdminForm\n\n    def preview(self, obj):\n        template = get_template('base/uploadedfile_preview.jinja')\n        return mark_safe(template.render({'file': obj}))\n\n    def snippets(self, obj):\n        \"\"\"Snippets using this file.\"\"\"\n        template = get_template('base/uploadedfile_snippets.jinja')\n        return mark_safe(template.render({'snippets': obj.snippets}))\n\n\nclass AddonAdmin(admin.ModelAdmin):\n    list_display = ('name', 'guid')\n\n\nclass ASRSnippetAdmin(admin.ModelAdmin):\n    form = forms.ASRSnippetAdminForm\n\n    list_display_links = (\n        'id',\n        'name',\n    )\n    list_display = (\n        'id',\n        'name',\n        'status',\n        'modified',\n    )\n    list_filter = (\n        ModifiedFilter,\n        'status',\n        ReleaseFilter,\n        ('template', RelatedDropdownFilter),\n    )\n    search_fields = (\n        'name',\n        'id',\n        'campaign__name',\n        'target__name',\n    )\n    autocomplete_fields = (\n        'campaign',\n        'target',\n    )\n    preserve_filters = True\n    readonly_fields = (\n        'created',\n        'modified',\n        'uuid',\n        'creator',\n        'preview_url',\n    )\n    filter_horizontal = (\n        'locales',\n    )\n    save_on_top = True\n    save_as = True\n    view_on_site = False\n    actions = (\n        duplicate_snippets_action,\n    )\n\n    fieldsets = (\n        ('ID', {'fields': ('creator', 'name', 'status', 'preview_url')}),\n        ('Content', {\n            'description': (\n                '''\n                <strong>Available deep links:</strong><br/>\n                <ol>\n                  <li><code>special:accounts</code> to open Firefox Accounts</li>\n                  <li><code>special:appMenu</code> to open the hamburger menu</li>\n                </ol><br/>\n                <strong>Automatically add Snippet ID:</strong><br/>\n                You can use <code>[[snippet_id]]</code> in any field and it\n                will be automatically replaced by Snippet ID when served to users.\n                <br/>\n                Example: This is a <code>&lt;a href=&quot;https://example.com?utm_term=[[snippet_id]]&quot;&gt;link&lt;/a&gt;</code>  # noqa\n                <br/>\n                '''\n            ),\n            'fields': ('template', 'data'),\n        }),\n        ('Publishing Options', {\n            'fields': ('campaign', 'target', ('publish_start', 'publish_end'), 'locales', 'weight',)\n        }),\n        ('Other Info', {\n            'fields': ('uuid', ('created', 'modified')),\n            'classes': ('collapse',)\n        }),\n    )\n\n    class Media:\n        css = {\n            'all': ('css/admin/ASRSnippetAdmin.css',)\n        }\n        js = (\n            'js/admin/clipboard.min.js',\n            'js/admin/copy_preview.js',\n        )\n\n    def save_model(self, request, obj, form, change):\n        if not obj.creator_id:\n            obj.creator = request.user\n        statsd.incr('save.asrsnippet')\n        super().save_model(request, obj, form, change)\n\n    def preview_url(self, obj):\n        text = f'''\n        <span id=\"previewLinkUrl\">{obj.get_preview_url()}</span>\n        <button id=\"copyPreviewLink\" class=\"btn\"\n                data-clipboard-target=\"#previewLinkUrl\"\n                originalText=\"Copy to Clipboard\" type=\"button\">\n          Copy to Clipboard\n        </button>\n        '''\n        return mark_safe(text)\n\n    def change_view(self, request, *args, **kwargs):\n        if request.method == 'POST' and '_saveasnew' in request.POST:\n            # Always saved cloned snippets as un-published and un-check ready for review.\n            post_data = request.POST.copy()\n            post_data['status'] = models.STATUS_CHOICES['Draft']\n            request.POST = post_data\n        return super().change_view(request, *args, **kwargs)\n\n\nclass CampaignAdmin(admin.ModelAdmin):\n    readonly_fields = ('created', 'modified', 'creator',)\n    prepopulated_fields = {'slug': ('name',)}\n\n    fieldsets = (\n        ('ID', {'fields': ('name', 'slug')}),\n        ('Other Info', {\n            'fields': ('creator', ('created', 'modified')),\n        }),\n    )\n    search_fields = (\n        'name',\n    )\n\n    def save_model(self, request, obj, form, change):\n        if not obj.creator_id:\n            obj.creator = request.user\n        statsd.incr('save.campaign')\n        super().save_model(request, obj, form, change)\n\n\nclass TargetAdmin(admin.ModelAdmin):\n    form = forms.TargetAdminForm\n    readonly_fields = ('created', 'modified', 'creator', 'jexl_expr')\n    search_fields = (\n        'name',\n    )\n    fieldsets = (\n        ('ID', {'fields': ('name',)}),\n        ('Product channels', {\n            'description': 'What channels will this snippet be available in?',\n            'fields': (('on_release', 'on_beta', 'on_aurora', 'on_nightly', 'on_esr'),)\n        }),\n        ('Targeting', {\n            'fields': (\n                'filtr_is_default_browser',\n                'filtr_updates_enabled',\n                'filtr_updates_autodownload_enabled',\n                'filtr_profile_age_created',\n                'filtr_firefox_version',\n                'filtr_previous_session_end',\n                'filtr_uses_firefox_sync',\n                'filtr_country',\n                'filtr_is_developer',\n                'filtr_current_search_engine',\n                'filtr_browser_addon',\n                'filtr_total_bookmarks_count',\n            )\n        }),\n        ('Other Info', {\n            'fields': ('creator', ('created', 'modified'), 'jexl_expr'),\n        }),\n    )\n\n    def save_model(self, request, obj, form, change):\n        if not obj.creator_id:\n            obj.creator = request.user\n        statsd.incr('save.target')\n        super().save_model(request, obj, form, change)\n", "path": "snippets/base/admin/adminmodels.py"}]}