We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Set snippet to `Draft` when `Save as New`


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

{"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@@ -202,6 +202,14 @@\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 \n class CampaignAdmin(admin.ModelAdmin):\n     readonly_fields = ('created', 'modified', 'creator',)\n", "issue": "Set snippet to `Draft` when `Save as New`\n\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\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\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\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\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\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"}]}