internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mozmeao/snippets-service

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.


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


Test patch:
Repository: mozmeao/snippets-service

Issue:
Set `target="_blank"` for time.is link in admin
The link "See the current time in UTC" on the Change ASR Snippet page should be target="_blank" (because otherwise, when you click the link, unsaved work is lost when the url loads)


Discussion:
![screen shot 2018-10-25 at 10 34 58 am](https://user-images.githubusercontent.com/6807556/47519122-abb46400-d841-11e8-9668-16fea753a89c.png)


Resolving patch:
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -614,11 +614,13 @@ class ASRSnippet(django_mysql.models.Model):
     publish_start = models.DateTimeField(
         blank=True, null=True,
         verbose_name='Publish Starts',
-        help_text=format_html('See the current time in <a href="http://time.is/UTC">UTC</a>'))
+        help_text=format_html(
+            'See the current time in <a target="_blank" href="http://time.is/UTC">UTC</a>'))
     publish_end = models.DateTimeField(
         blank=True, null=True,
         verbose_name='Publish Ends',
-        help_text=format_html('See the current time in <a href="http://time.is/UTC">UTC</a>'))
+        help_text=format_html(
+            'See the current time in <a target="_blank" href="http://time.is/UTC">UTC</a>'))
 
     locales = models.ManyToManyField('TargetedLocale', blank=True, verbose_name='Targeted Locales')
     target = models.ForeignKey(Target, on_delete=models.PROTECT,


Test patch:
Repository: mozmeao/snippets-service

Issue:
Don't include empty data fields on ASRSnippets render



Discussion:
/cc @piatra @k88hudson 

Resolving patch:
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -657,6 +657,9 @@ def render(self, preview=False):
         # Convert inline links to fluent.js format.
         data = util.fluent_link_extractor(data, self.template.get_rich_text_variables())
 
+        # Remove values that are empty strings
+        data = {k: v for k, v in data.items() if v != ''}
+
         rendered_snippet = {
             'id': str(self.id),
             'template': self.template.code_name,


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
@@ -335,7 +335,7 @@ class ASRSnippetTests(TestCase):
     def test_render(self):
         snippet = ASRSnippetFactory.create(
             template__code='<p>{{ text }} {{ foo }}</p>',
-            data='{"text": "snippet id [[snippet_id]]", "foo": "bar"}',
+            data='{"text": "snippet id [[snippet_id]]", "foo": "bar", "empty": ""}',
             target__jexl_expr='foo == bar')
         generated_result = snippet.render()
         expected_result = {
Repository: mozmeao/snippets-service

Issue:
Filter by release channel on ASRSnippets raises an error



Discussion:

Resolving patch:
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
@@ -3,6 +3,8 @@
 from django.contrib import admin
 from django.utils.encoding import force_text
 
+from snippets.base.managers import SnippetQuerySet
+
 
 class ModifiedFilter(admin.SimpleListFilter):
     title = 'Last modified'
@@ -53,7 +55,9 @@ def queryset(self, request, queryset):
         if self.value() is None:
             return queryset
 
-        return queryset.filter(**{self.value(): True})
+        if isinstance(queryset, SnippetQuerySet):
+            return queryset.filter(**{self.value(): True})
+        return queryset.filter(**{f'target__{self.value()}': True})
 
 
 class ActivityStreamFilter(admin.SimpleListFilter):


Test patch:
diff --git a/snippets/base/tests/test_filters.py b/snippets/base/tests/test_filters.py
new file mode 100644
--- /dev/null
+++ b/snippets/base/tests/test_filters.py
@@ -0,0 +1,28 @@
+from snippets.base.admin import ASRSnippetAdmin, SnippetAdmin
+from snippets.base.admin.filters import ChannelFilter
+from snippets.base.models import ASRSnippet, Snippet
+from snippets.base.tests import ASRSnippetFactory, SnippetFactory, TestCase
+
+
+class ChannelFilterTests(TestCase):
+    def test_asrsnippet(self):
+        nightly_snippets = ASRSnippetFactory.create_batch(
+            2, target__on_release=False, target__on_nightly=True)
+        ASRSnippetFactory.create_batch(2, target__on_release=False, target__on_beta=True)
+
+        filtr = ChannelFilter(None, {'channel': 'on_nightly'}, ASRSnippet, ASRSnippetAdmin)
+        result = filtr.queryset(None, ASRSnippet.objects.all())
+
+        self.assertTrue(result.count(), 2)
+        self.assertTrue(set(result.all()), set(nightly_snippets))
+
+    def test_snippet(self):
+        nightly_snippets = SnippetFactory.create_batch(
+            2, on_release=False, on_nightly=True)
+        SnippetFactory.create_batch(2, on_release=False, on_beta=True)
+
+        filtr = ChannelFilter(None, {'channel': 'on_nightly'}, Snippet, SnippetAdmin)
+        result = filtr.queryset(None, Snippet.objects.all())
+
+        self.assertTrue(result.count(), 2)
+        self.assertTrue(set(result.all()), set(nightly_snippets))
Repository: mozmeao/snippets-service

Issue:
Parse `currentDate` as `date` in JEXL
It seems that JEXL's `currentDate` is a string, instead of unix time, and thus it needs to be passed through `date` filter.


Discussion:

Resolving patch:
diff --git a/snippets/base/forms.py b/snippets/base/forms.py
--- a/snippets/base/forms.py
+++ b/snippets/base/forms.py
@@ -611,8 +611,8 @@ class TargetAdminForm(forms.ModelForm):
         # profileAgeCreated is in milliseconds. We first calculate the
         # difference from currentDate and then we convert to week.
         jexl={
-            'minimum': '((currentDate - profileAgeCreated) / 604800000) >= {value}',
-            'maximum': '((currentDate - profileAgeCreated) / 604800000) < {value}',
+            'minimum': '((currentDate|date - profileAgeCreated) / 604800000) >= {value}',
+            'maximum': '((currentDate|date - profileAgeCreated) / 604800000) < {value}',
         },
         choices=PROFILE_AGE_CHOICES_ASR,
         required=False,
@@ -629,8 +629,8 @@ class TargetAdminForm(forms.ModelForm):
         # previousSessionEnd is in milliseconds. We first calculate the
         # difference from currentDate and then we convert to week.
         jexl={
-            'minimum': '((currentDate - previousSessionEnd) / 604800000) >= {value}',
-            'maximum': '((currentDate - previousSessionEnd) / 604800000) < {value}',
+            'minimum': '((currentDate|date - previousSessionEnd) / 604800000) >= {value}',
+            'maximum': '((currentDate|date - previousSessionEnd) / 604800000) < {value}',
         },
         choices=PROFILE_AGE_CHOICES_ASR,
         required=False,


Test patch:
Repository: mozmeao/snippets-service

Issue:
Add Publish Action for ASRSnippets in list view



Discussion:

Resolving patch:
diff --git a/snippets/base/admin/actions.py b/snippets/base/admin/actions.py
--- a/snippets/base/admin/actions.py
+++ b/snippets/base/admin/actions.py
@@ -17,6 +17,14 @@ def duplicate_snippets_action(modeladmin, request, queryset):
 duplicate_snippets_action.short_description = 'Duplicate selected snippets'  # noqa
 
 
+@transaction.atomic
+def publish_snippets_action(modeladmin, request, queryset):
+    for snippet in queryset:
+        snippet.status = STATUS_CHOICES['Published']
+        snippet.save()
+publish_snippets_action.short_description = 'Publish selected snippets'  # noqa
+
+
 @transaction.atomic
 def migrate_snippets_action(modeladmin, request, queryset):
     for snippet in queryset:
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
@@ -14,7 +14,7 @@
 from snippets.base import forms, models
 from snippets.base.models import JINJA_ENV
 from snippets.base.admin import filters
-from snippets.base.admin.actions import duplicate_snippets_action
+from snippets.base.admin import actions
 
 
 MATCH_LOCALE_REGEX = re.compile(r'(\w+(?:-\w+)*)')
@@ -155,7 +155,8 @@ class ASRSnippetAdmin(admin.ModelAdmin):
     save_as = True
     view_on_site = False
     actions = (
-        duplicate_snippets_action,
+        actions.duplicate_snippets_action,
+        actions.publish_snippets_action,
     )
 
     fieldsets = (


Test patch:
diff --git a/snippets/base/tests/test_actions.py b/snippets/base/tests/test_actions.py
--- a/snippets/base/tests/test_actions.py
+++ b/snippets/base/tests/test_actions.py
@@ -11,6 +11,25 @@
                                  SnippetTemplateFactory, TestCase, UserFactory)
 
 
+class PublishSnippetsActions(TestCase):
+    def test_base(self):
+        to_be_published = ASRSnippetFactory.create_batch(2, status=models.STATUS_CHOICES['Draft'])
+        already_published = ASRSnippetFactory(status=models.STATUS_CHOICES['Published'])
+        ASRSnippetFactory.create_batch(2, status=models.STATUS_CHOICES['Draft'])
+
+        queryset = models.ASRSnippet.objects.filter(id__in=[
+            to_be_published[0].id,
+            to_be_published[1].id,
+            already_published.id
+        ])
+        actions.publish_snippets_action(None, None, queryset)
+
+        self.assertEqual(
+            set(models.ASRSnippet.objects.filter(status=models.STATUS_CHOICES['Published'])),
+            set(to_be_published + [already_published])
+        )
+
+
 class MigrateSnippetActionTests(TestCase):
     def setUp(self):
         request_factory = RequestFactory()
Repository: mozmeao/snippets-service

Issue:
ASRSnippet list view search refers to target
ASRSnippet list view search requires update to refer to `targets` after #875 


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
@@ -132,7 +132,7 @@ class ASRSnippetAdmin(admin.ModelAdmin):
         'name',
         'id',
         'campaign__name',
-        'target__name',
+        'targets__name',
     )
     autocomplete_fields = (
         'campaign',


Test patch:
Repository: mozmeao/snippets-service

Issue:
ASR Send to Device Template: Input Field Gets Cut Off
Can we make this input field flexible so it accepts more characters? It cuts off when I input "Enter your email or phone number" or "Enter your email or phone (10 digits, no spaces) here" 


![screen shot 2019-01-02 at 10 15 23 am](https://user-images.githubusercontent.com/6807556/50605620-9a0dbf00-0e77-11e9-931a-b180da368060.png)



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
@@ -55,11 +55,6 @@ class SnippetTemplateAdmin(VersionAdmin, admin.ModelAdmin):
                                         width='1200px', height='500px')},
     }
 
-    class Media:
-        css = {
-            'all': ('css/admin.css',)
-        }
-
     def save_related(self, request, form, formsets, change):
         """
         After saving the related objects, remove and add
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
@@ -152,7 +152,7 @@ class SnippetAdmin(QuickEditAdmin, BaseSnippetAdmin):
     class Media:
         css = {
             'all': (
-                'css/admin.css',
+                'css/admin/SnippetAdmin.css',
                 'css/admin/IDFieldHighlight.css',
             )
         }
@@ -238,7 +238,6 @@ class JSONSnippetAdmin(BaseSnippetAdmin):
     class Media:
         css = {
             'all': (
-                'css/admin.css',
                 'css/admin/IDFieldHighlight.css',
             )
         }


Test patch:
Repository: mozmeao/snippets-service

Issue:
Remove MariaDB related code and references
After we complete the migration to PostgreSQL, remove MariaDB related code and references:
 - Dockerfile
 - requirements.txt
 - python code
Update dev docs with `create_countries` and `create_locales` info



Discussion:

Resolving patch:
diff --git a/snippets/settings.py b/snippets/settings.py
--- a/snippets/settings.py
+++ b/snippets/settings.py
@@ -99,16 +99,6 @@
     'default': config('DATABASE_URL', cast=dj_database_url.parse)
 }
 
-
-if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql':
-    DATABASES['default']['OPTIONS'] = {
-        'init_command': "SET sql_mode='STRICT_TRANS_TABLES'; SET innodb_strict_mode=1;",
-    }
-    DATABASES['default']['TEST'] = {
-        'CHARSET': 'utf8',
-        'COLLATION': 'utf8_general_ci',
-    }
-
 SILENCED_SYSTEM_CHECKS = [
     'cachalot.E003',
 ]


Test patch:
Repository: mozmeao/snippets-service

Issue:
Validate all ASRSnippet.data content for insecure links.
Current we check for insecure links in Rich Text fields (link `text`) but not in `button_url`. We need to check all content for insecure links


Discussion:

Resolving patch:
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -777,6 +777,7 @@ class FundraisingTemplate(Template):
 
     donation_form_url = models.URLField(
         default='https://donate.mozilla.org/?utm_source=desktop-snippet&utm_medium=snippet',
+        validators=[django_validators.URLValidator(schemes=['https'])],
         max_length=500,
     )
     currency_code = models.CharField(max_length=10, default='usd')


Test patch:
Repository: mozmeao/snippets-service

Issue:
Add more snippet weight options
Giorgos, as we talked about in our last Tuesday meeting, we may want lower weights for snippets available, specifically for when we want to test new snippets.

This would allow us to test snippets with a lower rotation that would not disrupt the overall content users view. Thanks!

Would it be possible to add in these weights:
1/10 (10%)
1/20 (5%)
1/40 (2.5%)


Discussion:
Sure, I'll go ahead and add those additional options.


Resolving patch:
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -35,13 +35,18 @@
 JINJA_ENV = engines['backend']
 
 CHANNELS = ('release', 'beta', 'aurora', 'nightly', 'esr')
-SNIPPET_WEIGHTS = ((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'))
+SNIPPET_WEIGHTS = (
+    (2, 'Appear 1/50th as often as an average snippet'),
+    (5, 'Appear 1/20th as often as an average snippet'),
+    (10, 'Appear 1/10th as often as an average snippet'),
+    (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')
+)
 
 
 # NamedTuple that represents a user's client program.


Test patch:
Repository: mozmeao/snippets-service

Issue:
List snippets locale and provide locale filter in list view 



Discussion:
P1
We can limit this to top 10 locales used if it's easier!


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
@@ -10,7 +10,8 @@
 from django_ace import AceWidget
 from django_statsd.clients import statsd
 from jinja2.meta import find_undeclared_variables
-from django_admin_listfilter_dropdown.filters import RelatedDropdownFilter
+from django_admin_listfilter_dropdown.filters import (RelatedDropdownFilter,
+                                                      RelatedOnlyDropdownFilter)
 
 from snippets.base import forms, models, slack
 from snippets.base.admin import actions, filters
@@ -429,10 +430,12 @@ class ASRSnippetAdmin(admin.ModelAdmin):
         'id',
         'name',
         'status',
+        'locale_list',
         'modified',
     )
     list_filter = (
         filters.ModifiedFilter,
+        ('locales', RelatedOnlyDropdownFilter),
         'status',
         filters.ChannelFilter,
         ('campaign', RelatedDropdownFilter),
@@ -602,6 +605,14 @@ def has_global_publish_permission(self, request):
             ]
         ])
 
+    def locale_list(self, obj):
+        num_locales = obj.locales.count()
+        locales = obj.locales.all()[:3]
+        active_locales = ', '.join([str(locale) for locale in locales])
+        if num_locales > 3:
+            active_locales += ' and {0} more.'.format(num_locales - 3)
+        return active_locales
+
 
 class CampaignAdmin(admin.ModelAdmin):
     readonly_fields = ('created', 'modified', 'creator',)


Test patch:
Repository: mozmeao/snippets-service

Issue:
ASR Snippet Admin: Pop up reminder to save edits on editing page
Need a pop-up message that appears whenever there have been edits but the snippet has not been saved, so when the user clicks off the page it will prompt “Save edits made?” or something similar.



Discussion:
Great idea! will do!

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
@@ -30,6 +30,12 @@ class ClientMatchRuleAdmin(VersionAdmin, admin.ModelAdmin):
     save_on_top = True
     search_fields = ('description',)
 
+    class Media:
+        js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
+        )
+
 
 class LogEntryAdmin(admin.ModelAdmin):
     list_display = ('user', 'content_type', 'object_id', 'object_repr', 'change_message')
@@ -86,6 +92,12 @@ def save_related(self, request, form, formsets, change):
 class AddonAdmin(admin.ModelAdmin):
     list_display = ('name', 'guid')
 
+    class Media:
+        js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
+        )
+
 
 class IconAdmin(admin.ModelAdmin):
     search_fields = [
@@ -118,6 +130,10 @@ class Media:
                 'css/admin/IconListSnippets.css',
             )
         }
+        js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
+        )
 
     def save_model(self, request, obj, form, change):
         if not obj.creator_id:
@@ -518,6 +534,8 @@ class Media:
             )
         }
         js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
             'js/admin/clipboard.min.js',
             'js/admin/copy_preview.js',
         )
@@ -617,6 +635,12 @@ class CampaignAdmin(admin.ModelAdmin):
         'name',
     )
 
+    class Media:
+        js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
+        )
+
     def save_model(self, request, obj, form, change):
         if not obj.creator_id:
             obj.creator = request.user
@@ -652,6 +676,12 @@ class CategoryAdmin(admin.ModelAdmin):
         'total_snippets_in_category',
     )
 
+    class Media:
+        js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
+        )
+
     def save_model(self, request, obj, form, change):
         if not obj.creator_id:
             obj.creator = request.user
@@ -707,6 +737,12 @@ class TargetAdmin(admin.ModelAdmin):
         }),
     )
 
+    class Media:
+        js = (
+            'js/admin/jquery.are-you-sure.js',
+            'js/admin/alert-page-leaving.js',
+        )
+
     def save_model(self, request, obj, form, change):
         if not obj.creator_id:
             obj.creator = request.user


Test patch:
Repository: mozmeao/snippets-service

Issue:
Targets with only CMR rules render to incomplete JEXL 
Targets with only CMR don't product JEXL (correctly) but when concatenated in a Snippet's `targeting` attribute result in empty `&&`.

E.g. the result of three Targets, one with only CMR defined combined
`foo == bar && lalo == true && `

Since we haven't used CMR yet in the ASR system this was never a real issue, but a fix it's needed for #965 


Discussion:

Resolving patch:
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -1465,7 +1465,9 @@ def render(self, preview=False):
                 rendered_snippet['campaign'] = self.campaign.slug
 
             rendered_snippet['targeting'] = ' && '.join(
-                [target.jexl_expr for target in self.targets.all().order_by('id')]
+                [target.jexl_expr for
+                 target in self.targets.all().order_by('id') if
+                 target.jexl_expr]
             )
 
         return rendered_snippet


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
@@ -404,7 +404,9 @@ def test_render(self):
                                      '<a href="https://example.com/[[snippet_id]]/foo">link</a>'),
             targets=[
                 TargetFactory(jexl_expr='foo == bar'),
-                TargetFactory(jexl_expr='lalo == true')
+                TargetFactory(jexl_expr='lalo == true'),
+                TargetFactory(jexl_expr=''),  # This can be a Target with only
+                                              # CMR which produces no JEXL
             ]
         )
         self.maxDiff = None
Repository: mozmeao/snippets-service

Issue:
Fix NR reporting
See https://github.com/mozmeao/infra/issues/1106


Discussion:

Resolving patch:
diff --git a/snippets/wsgi/app.py b/snippets/wsgi/app.py
--- a/snippets/wsgi/app.py
+++ b/snippets/wsgi/app.py
@@ -6,22 +6,14 @@
 For more information on this file, see
 https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
 """
-import os
-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'snippets.settings')  # NOQA
-
-from django.core.wsgi import get_wsgi_application
-
 import newrelic.agent
-from decouple import config
-from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
+newrelic.agent.initialize('newrelic.ini')
 
+import os  # NOQA
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'snippets.settings')  # NOQA
+
+from django.core.wsgi import get_wsgi_application  # NOQA
 application = get_wsgi_application()
 
+from raven.contrib.django.raven_compat.middleware.wsgi import Sentry  # NOQA
 application = Sentry(application)
-
-# Add NewRelic
-newrelic_ini = config('NEW_RELIC_CONFIG_FILE', default='newrelic.ini')
-newrelic_license_key = config('NEW_RELIC_LICENSE_KEY', default=None)
-if newrelic_ini and newrelic_license_key:
-    newrelic.agent.initialize(newrelic_ini)
-    application = newrelic.agent.wsgi_application()(application)


Test patch: