We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add Feature to notify users about new challenge on EvalAI.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/web/views.py`
Content:
```
1 from django.contrib.auth.models import User
2 from django.shortcuts import render
3 
4 from .models import Team
5 
6 from rest_framework import permissions, status
7 from rest_framework.decorators import (api_view,
8                                        permission_classes,
9                                        throttle_classes,)
10 from rest_framework.response import Response
11 from rest_framework.throttling import AnonRateThrottle
12 
13 from .serializers import ContactSerializer, TeamSerializer
14 
15 
16 def home(request, template_name="index.html"):
17     """
18     Home Page View
19     """
20     return render(request, template_name)
21 
22 
23 def page_not_found(request):
24     response = render(request, 'error404.html',
25                       )
26     response.status_code = 404
27     return response
28 
29 
30 def internal_server_error(request):
31     response = render(request, 'error500.html',
32                       )
33     response.status_code = 500
34     return response
35 
36 
37 @throttle_classes([AnonRateThrottle, ])
38 @api_view(['GET', 'POST'])
39 @permission_classes((permissions.AllowAny,))
40 def contact_us(request):
41     user_does_not_exist = False
42     try:
43         user = User.objects.get(username=request.user)
44         name = user.username
45         email = user.email
46         request_data = {'name': name, 'email': email}
47     except:
48         request_data = request.data
49         user_does_not_exist = True
50 
51     if request.method == 'POST' or user_does_not_exist:
52         if request.POST.get('message'):
53             request_data['message'] = request.POST.get('message')
54         serializer = ContactSerializer(data=request_data)
55         if serializer.is_valid():
56             serializer.save()
57             response_data = {'message': 'We have received your request and will contact you shortly.'}
58             return Response(response_data, status=status.HTTP_201_CREATED)
59         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
60 
61     elif request.method == 'GET':
62         response_data = {"name": name, "email": email}
63         return Response(response_data, status=status.HTTP_200_OK)
64 
65 
66 @throttle_classes([AnonRateThrottle])
67 @api_view(['GET', 'POST'])
68 @permission_classes((permissions.AllowAny,))
69 def our_team(request):
70     if request.method == 'GET':
71         teams = Team.objects.all()
72         serializer = TeamSerializer(teams, many=True, context={'request': request})
73         response_data = serializer.data
74         return Response(response_data, status=status.HTTP_200_OK)
75     elif request.method == 'POST':
76         # team_type is set to Team.CONTRIBUTOR by default and can be overridden by the requester
77         request.data['team_type'] = request.data.get('team_type', Team.CONTRIBUTOR)
78         serializer = TeamSerializer(data=request.data)
79         if serializer.is_valid():
80             serializer.save()
81             response_data = {'message', 'Successfully added the contributor.'}
82             return Response(response_data, status=status.HTTP_201_CREATED)
83         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
84
```

Path: `apps/web/urls.py`
Content:
```
1 from django.conf.urls import url
2 
3 from . import views
4 
5 urlpatterns = [
6     url(r'^contact/$', views.contact_us, name='contact_us'),
7     url(r'^team/$', views.our_team, name='our_team'),
8 ]
9
```
--- 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/apps/web/urls.py b/apps/web/urls.py
--- a/apps/web/urls.py
+++ b/apps/web/urls.py
@@ -5,4 +5,5 @@
 urlpatterns = [
     url(r'^contact/$', views.contact_us, name='contact_us'),
     url(r'^team/$', views.our_team, name='our_team'),
+    url(r'^notify_users/$', views.notify_users_about_challenge, name='notify_users_about_challenge'),
 ]
diff --git a/apps/web/views.py b/apps/web/views.py
--- a/apps/web/views.py
+++ b/apps/web/views.py
@@ -1,7 +1,14 @@
 from django.contrib.auth.models import User
+from django.conf import settings
+from django.core.mail import EmailMultiAlternatives
 from django.shortcuts import render
+from django.template.loader import get_template
+from django.template import Context
+
+from email.MIMEImage import MIMEImage
 
 from .models import Team
+from .serializers import ContactSerializer, TeamSerializer
 
 from rest_framework import permissions, status
 from rest_framework.decorators import (api_view,
@@ -10,8 +17,6 @@
 from rest_framework.response import Response
 from rest_framework.throttling import AnonRateThrottle
 
-from .serializers import ContactSerializer, TeamSerializer
-
 
 def home(request, template_name="index.html"):
     """
@@ -34,6 +39,57 @@
     return response
 
 
+def notify_users_about_challenge(request):
+    """
+    Email New Challenge Details to EvalAI Users
+    """
+    if request.user.is_authenticated() and request.user.is_superuser:
+        if request.method == 'GET':
+            template_name = 'notification_email_data.html'
+            return render(request, template_name)
+
+        elif request.method == 'POST':
+            template_name = 'notification_email.html'
+            emails = User.objects.all().exclude(email__isnull=True, email__exact='').values_list('email', flat=True)
+            htmly = get_template('notification_email.html')
+
+            subject = request.POST.get('subject')
+            body = request.POST.get('body')
+
+            try:
+                challenge_image = request.FILES['challenge_image']
+            except:
+                challenge_image = None
+
+            if challenge_image:
+                image = MIMEImage(challenge_image.read())
+                image.add_header('Content-ID', '<{}>'.format(challenge_image))
+
+            context = Context({'body': body,
+                               'image': challenge_image})
+
+            for email in emails:
+                from_email = settings.EMAIL_HOST_USER
+                to = [email]
+                html_content = htmly.render(context)
+
+                msg = EmailMultiAlternatives(subject, html_content, from_email, to)
+                msg.attach_alternative(html_content, "text/html")
+                msg.mixed_subtype = 'related'
+
+                if challenge_image:
+                    msg.attach(image)
+
+                msg.send()
+            return render(request,
+                          'notification_email_conformation.html',
+                          {'message': 'All the emails are sent successfully!'})
+        else:
+            return render(request, 'error404.html')
+    else:
+        return render(request, 'error404.html')
+
+
 @throttle_classes([AnonRateThrottle, ])
 @api_view(['GET', 'POST'])
 @permission_classes((permissions.AllowAny,))

{"golden_diff": "diff --git a/apps/web/urls.py b/apps/web/urls.py\n--- a/apps/web/urls.py\n+++ b/apps/web/urls.py\n@@ -5,4 +5,5 @@\n urlpatterns = [\n     url(r'^contact/$', views.contact_us, name='contact_us'),\n     url(r'^team/$', views.our_team, name='our_team'),\n+    url(r'^notify_users/$', views.notify_users_about_challenge, name='notify_users_about_challenge'),\n ]\ndiff --git a/apps/web/views.py b/apps/web/views.py\n--- a/apps/web/views.py\n+++ b/apps/web/views.py\n@@ -1,7 +1,14 @@\n from django.contrib.auth.models import User\n+from django.conf import settings\n+from django.core.mail import EmailMultiAlternatives\n from django.shortcuts import render\n+from django.template.loader import get_template\n+from django.template import Context\n+\n+from email.MIMEImage import MIMEImage\n \n from .models import Team\n+from .serializers import ContactSerializer, TeamSerializer\n \n from rest_framework import permissions, status\n from rest_framework.decorators import (api_view,\n@@ -10,8 +17,6 @@\n from rest_framework.response import Response\n from rest_framework.throttling import AnonRateThrottle\n \n-from .serializers import ContactSerializer, TeamSerializer\n-\n \n def home(request, template_name=\"index.html\"):\n     \"\"\"\n@@ -34,6 +39,57 @@\n     return response\n \n \n+def notify_users_about_challenge(request):\n+    \"\"\"\n+    Email New Challenge Details to EvalAI Users\n+    \"\"\"\n+    if request.user.is_authenticated() and request.user.is_superuser:\n+        if request.method == 'GET':\n+            template_name = 'notification_email_data.html'\n+            return render(request, template_name)\n+\n+        elif request.method == 'POST':\n+            template_name = 'notification_email.html'\n+            emails = User.objects.all().exclude(email__isnull=True, email__exact='').values_list('email', flat=True)\n+            htmly = get_template('notification_email.html')\n+\n+            subject = request.POST.get('subject')\n+            body = request.POST.get('body')\n+\n+            try:\n+                challenge_image = request.FILES['challenge_image']\n+            except:\n+                challenge_image = None\n+\n+            if challenge_image:\n+                image = MIMEImage(challenge_image.read())\n+                image.add_header('Content-ID', '<{}>'.format(challenge_image))\n+\n+            context = Context({'body': body,\n+                               'image': challenge_image})\n+\n+            for email in emails:\n+                from_email = settings.EMAIL_HOST_USER\n+                to = [email]\n+                html_content = htmly.render(context)\n+\n+                msg = EmailMultiAlternatives(subject, html_content, from_email, to)\n+                msg.attach_alternative(html_content, \"text/html\")\n+                msg.mixed_subtype = 'related'\n+\n+                if challenge_image:\n+                    msg.attach(image)\n+\n+                msg.send()\n+            return render(request,\n+                          'notification_email_conformation.html',\n+                          {'message': 'All the emails are sent successfully!'})\n+        else:\n+            return render(request, 'error404.html')\n+    else:\n+        return render(request, 'error404.html')\n+\n+\n @throttle_classes([AnonRateThrottle, ])\n @api_view(['GET', 'POST'])\n @permission_classes((permissions.AllowAny,))\n", "issue": "Add Feature to notify users about new challenge on EvalAI.\n\n", "before_files": [{"content": "from django.contrib.auth.models import User\nfrom django.shortcuts import render\n\nfrom .models import Team\n\nfrom rest_framework import permissions, status\nfrom rest_framework.decorators import (api_view,\n                                       permission_classes,\n                                       throttle_classes,)\nfrom rest_framework.response import Response\nfrom rest_framework.throttling import AnonRateThrottle\n\nfrom .serializers import ContactSerializer, TeamSerializer\n\n\ndef home(request, template_name=\"index.html\"):\n    \"\"\"\n    Home Page View\n    \"\"\"\n    return render(request, template_name)\n\n\ndef page_not_found(request):\n    response = render(request, 'error404.html',\n                      )\n    response.status_code = 404\n    return response\n\n\ndef internal_server_error(request):\n    response = render(request, 'error500.html',\n                      )\n    response.status_code = 500\n    return response\n\n\n@throttle_classes([AnonRateThrottle, ])\n@api_view(['GET', 'POST'])\n@permission_classes((permissions.AllowAny,))\ndef contact_us(request):\n    user_does_not_exist = False\n    try:\n        user = User.objects.get(username=request.user)\n        name = user.username\n        email = user.email\n        request_data = {'name': name, 'email': email}\n    except:\n        request_data = request.data\n        user_does_not_exist = True\n\n    if request.method == 'POST' or user_does_not_exist:\n        if request.POST.get('message'):\n            request_data['message'] = request.POST.get('message')\n        serializer = ContactSerializer(data=request_data)\n        if serializer.is_valid():\n            serializer.save()\n            response_data = {'message': 'We have received your request and will contact you shortly.'}\n            return Response(response_data, status=status.HTTP_201_CREATED)\n        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n\n    elif request.method == 'GET':\n        response_data = {\"name\": name, \"email\": email}\n        return Response(response_data, status=status.HTTP_200_OK)\n\n\n@throttle_classes([AnonRateThrottle])\n@api_view(['GET', 'POST'])\n@permission_classes((permissions.AllowAny,))\ndef our_team(request):\n    if request.method == 'GET':\n        teams = Team.objects.all()\n        serializer = TeamSerializer(teams, many=True, context={'request': request})\n        response_data = serializer.data\n        return Response(response_data, status=status.HTTP_200_OK)\n    elif request.method == 'POST':\n        # team_type is set to Team.CONTRIBUTOR by default and can be overridden by the requester\n        request.data['team_type'] = request.data.get('team_type', Team.CONTRIBUTOR)\n        serializer = TeamSerializer(data=request.data)\n        if serializer.is_valid():\n            serializer.save()\n            response_data = {'message', 'Successfully added the contributor.'}\n            return Response(response_data, status=status.HTTP_201_CREATED)\n        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n", "path": "apps/web/views.py"}, {"content": "from django.conf.urls import url\n\nfrom . import views\n\nurlpatterns = [\n    url(r'^contact/$', views.contact_us, name='contact_us'),\n    url(r'^team/$', views.our_team, name='our_team'),\n]\n", "path": "apps/web/urls.py"}], "after_files": [{"content": "from django.contrib.auth.models import User\nfrom django.conf import settings\nfrom django.core.mail import EmailMultiAlternatives\nfrom django.shortcuts import render\nfrom django.template.loader import get_template\nfrom django.template import Context\n\nfrom email.MIMEImage import MIMEImage\n\nfrom .models import Team\nfrom .serializers import ContactSerializer, TeamSerializer\n\nfrom rest_framework import permissions, status\nfrom rest_framework.decorators import (api_view,\n                                       permission_classes,\n                                       throttle_classes,)\nfrom rest_framework.response import Response\nfrom rest_framework.throttling import AnonRateThrottle\n\n\ndef home(request, template_name=\"index.html\"):\n    \"\"\"\n    Home Page View\n    \"\"\"\n    return render(request, template_name)\n\n\ndef page_not_found(request):\n    response = render(request, 'error404.html',\n                      )\n    response.status_code = 404\n    return response\n\n\ndef internal_server_error(request):\n    response = render(request, 'error500.html',\n                      )\n    response.status_code = 500\n    return response\n\n\ndef notify_users_about_challenge(request):\n    \"\"\"\n    Email New Challenge Details to EvalAI Users\n    \"\"\"\n    if request.user.is_authenticated() and request.user.is_superuser:\n        if request.method == 'GET':\n            template_name = 'notification_email_data.html'\n            return render(request, template_name)\n\n        elif request.method == 'POST':\n            template_name = 'notification_email.html'\n            emails = User.objects.all().exclude(email__isnull=True, email__exact='').values_list('email', flat=True)\n            htmly = get_template('notification_email.html')\n\n            subject = request.POST.get('subject')\n            body = request.POST.get('body')\n\n            try:\n                challenge_image = request.FILES['challenge_image']\n            except:\n                challenge_image = None\n\n            if challenge_image:\n                image = MIMEImage(challenge_image.read())\n                image.add_header('Content-ID', '<{}>'.format(challenge_image))\n\n            context = Context({'body': body,\n                               'image': challenge_image})\n\n            for email in emails:\n                from_email = settings.EMAIL_HOST_USER\n                to = [email]\n                html_content = htmly.render(context)\n\n                msg = EmailMultiAlternatives(subject, html_content, from_email, to)\n                msg.attach_alternative(html_content, \"text/html\")\n                msg.mixed_subtype = 'related'\n\n                if challenge_image:\n                    msg.attach(image)\n\n                msg.send()\n            return render(request,\n                          'notification_email_conformation.html',\n                          {'message': 'All the emails are sent successfully!'})\n        else:\n            return render(request, 'error404.html')\n    else:\n        return render(request, 'error404.html')\n\n\n@throttle_classes([AnonRateThrottle, ])\n@api_view(['GET', 'POST'])\n@permission_classes((permissions.AllowAny,))\ndef contact_us(request):\n    user_does_not_exist = False\n    try:\n        user = User.objects.get(username=request.user)\n        name = user.username\n        email = user.email\n        request_data = {'name': name, 'email': email}\n    except:\n        request_data = request.data\n        user_does_not_exist = True\n\n    if request.method == 'POST' or user_does_not_exist:\n        if request.POST.get('message'):\n            request_data['message'] = request.POST.get('message')\n        serializer = ContactSerializer(data=request_data)\n        if serializer.is_valid():\n            serializer.save()\n            response_data = {'message': 'We have received your request and will contact you shortly.'}\n            return Response(response_data, status=status.HTTP_201_CREATED)\n        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n\n    elif request.method == 'GET':\n        response_data = {\"name\": name, \"email\": email}\n        return Response(response_data, status=status.HTTP_200_OK)\n\n\n@throttle_classes([AnonRateThrottle])\n@api_view(['GET', 'POST'])\n@permission_classes((permissions.AllowAny,))\ndef our_team(request):\n    if request.method == 'GET':\n        teams = Team.objects.all()\n        serializer = TeamSerializer(teams, many=True, context={'request': request})\n        response_data = serializer.data\n        return Response(response_data, status=status.HTTP_200_OK)\n    elif request.method == 'POST':\n        # team_type is set to Team.CONTRIBUTOR by default and can be overridden by the requester\n        request.data['team_type'] = request.data.get('team_type', Team.CONTRIBUTOR)\n        serializer = TeamSerializer(data=request.data)\n        if serializer.is_valid():\n            serializer.save()\n            response_data = {'message', 'Successfully added the contributor.'}\n            return Response(response_data, status=status.HTTP_201_CREATED)\n        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n", "path": "apps/web/views.py"}, {"content": "from django.conf.urls import url\n\nfrom . import views\n\nurlpatterns = [\n    url(r'^contact/$', views.contact_us, name='contact_us'),\n    url(r'^team/$', views.our_team, name='our_team'),\n    url(r'^notify_users/$', views.notify_users_about_challenge, name='notify_users_about_challenge'),\n]\n", "path": "apps/web/urls.py"}]}