prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Make URL redirects from `?next` param safer
  There are a couple places where we redirect to `?next` value without checking if it's safe. There's a `django.http.is_safe_url` function we could use.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `amy/autoemails/utils.py`
  Content:
  ```
  1 from typing import Union
  2 
  3 import django_rq
  4 import pytz
  5 from rq.exceptions import NoSuchJobError
  6 from rq.job import Job
  7 from rq_scheduler.utils import from_unix
  8 
  9 
  10 def scheduled_execution_time(job_id, scheduler=None, naive=True):
  11     """Get RQ-Scheduler scheduled execution time for specific job."""
  12     _scheduler = scheduler
  13     if not scheduler:
  14         _scheduler = django_rq.get_scheduler("default")
  15 
  16     # Scheduler keeps jobs in a single key, they are sorted by score, which is
  17     # scheduled execution time (linux epoch).  We can retrieve single
  18     # entry's score.
  19     time = _scheduler.connection.zscore(_scheduler.scheduled_jobs_key, job_id)
  20 
  21     # Convert linux time epoch to UTC.
  22     if time:
  23         time = from_unix(time)
  24         if not naive:
  25             # By default, RQ-Scheduler uses UTC naive (TZ-unaware) objects,
  26             # which we can "convert" to TZ-aware UTC.
  27             time = time.replace(tzinfo=pytz.UTC)
  28     return time
  29 
  30 
  31 def compare_emails(a, b):
  32     """EmailMultiAlternatives doesn't implement __eq__, so we have to
  33     cheat our way."""
  34     if a is None and b is None:
  35         return True
  36     elif a is None and b or b is None and a:
  37         return False
  38     else:
  39         try:
  40             return (
  41                 a.to == b.to
  42                 and a.cc == b.cc
  43                 and a.bcc == b.bcc
  44                 and a.reply_to == b.reply_to
  45                 and a.subject == b.subject
  46                 and a.body == b.body
  47             )
  48         except AttributeError:
  49             return False
  50 
  51 
  52 def check_status(job: Union[str, Job], scheduler=None):
  53     _scheduler = scheduler
  54     if not scheduler:
  55         _scheduler = django_rq.get_scheduler("default")
  56 
  57     if not isinstance(job, Job):
  58         try:
  59             job = Job.fetch(job, connection=_scheduler.connection)
  60         except NoSuchJobError:
  61             return None
  62 
  63     scheduled = scheduled_execution_time(job.get_id(), scheduler)
  64 
  65     if scheduled:
  66         return job.get_status() or "scheduled"
  67     else:
  68         return job.get_status() or "cancelled"
  69
  ```
  
  Path: `amy/autoemails/views.py`
  Content:
  ```
  1 import logging
  2 
  3 from django.contrib import messages
  4 from django.shortcuts import get_object_or_404, redirect
  5 from django.urls import reverse
  6 from django.utils.html import format_html
  7 from django.views.decorators.http import require_POST
  8 import django_rq
  9 
  10 from workshops.models import WorkshopRequest
  11 from workshops.util import admin_required
  12 
  13 from .actions import GenericAction
  14 from .forms import GenericEmailScheduleForm
  15 from .models import EmailTemplate, Trigger
  16 from .utils import check_status, scheduled_execution_time
  17 
  18 logger = logging.getLogger("amy.signals")
  19 scheduler = django_rq.get_scheduler("default")
  20 redis_connection = django_rq.get_connection("default")
  21 
  22 
  23 @require_POST
  24 @admin_required
  25 def generic_schedule_email(request, pk):
  26     """
  27     Generic view for scheduling an email to be sent.
  28     """
  29     template_slug = request.POST.get("slug", "")
  30     original_template = get_object_or_404(EmailTemplate, slug=template_slug)
  31     # Hardcoded, maybe in future respond to other requests, like
  32     # SelfOrganizedSubmission or WorkshopInquiry
  33     trigger = get_object_or_404(
  34         Trigger,
  35         action__startswith="workshop-request-response",
  36         template__slug=template_slug,
  37         active=True,
  38     )
  39     form = GenericEmailScheduleForm(request.POST, instance=original_template)
  40     workshop_request = get_object_or_404(WorkshopRequest, pk=pk)
  41 
  42     if form.is_valid():
  43         template = EmailTemplate(
  44             slug=form.cleaned_data["slug"],
  45             subject=form.cleaned_data["subject"],
  46             to_header=form.cleaned_data["to_header"],
  47             from_header=form.cleaned_data["from_header"],
  48             cc_header=form.cleaned_data["cc_header"],
  49             bcc_header=form.cleaned_data["bcc_header"],
  50             reply_to_header=form.cleaned_data["reply_to_header"],
  51             body_template=form.cleaned_data["body_template"],
  52         )
  53 
  54         objects = dict(request=workshop_request)
  55         if workshop_request.event:
  56             objects["event"] = workshop_request.event
  57             objects["workshop"] = workshop_request.event
  58 
  59         action = GenericAction(
  60             trigger=trigger,
  61             objects=objects,
  62         )
  63         action_name = GenericAction.__name__
  64         launch_at = action.get_launch_at()
  65         meta = dict(
  66             action=action,
  67             template=template,
  68             launch_at=launch_at,
  69             email=None,
  70             context=None,
  71         )
  72 
  73         job = scheduler.enqueue_in(launch_at, action, meta=meta)
  74         logger.debug("%s: enqueueing", action_name)
  75         scheduled_at = scheduled_execution_time(
  76             job.get_id(), scheduler=scheduler, naive=False
  77         )
  78         logger.debug("%s: job created [%r]", action_name, job)
  79 
  80         rqj = workshop_request.rq_jobs.create(
  81             job_id=job.get_id(),
  82             trigger=trigger,
  83             scheduled_execution=scheduled_at,
  84             status=check_status(job),
  85             mail_status="",
  86             event_slug=action.event_slug(),
  87             recipients=action.all_recipients(),
  88         )
  89 
  90         messages.info(
  91             request,
  92             format_html(
  93                 "New email ({}) was scheduled to run "
  94                 '<relative-time datetime="{}">{}</relative-time>: '
  95                 '<a href="{}">{}</a>.',
  96                 trigger.get_action_display(),
  97                 scheduled_at.isoformat(),
  98                 "{:%Y-%m-%d %H:%M}".format(scheduled_at),
  99                 reverse("admin:autoemails_rqjob_preview", args=[rqj.pk]),
  100                 job.id,
  101             ),
  102             fail_silently=True,
  103         )
  104 
  105         return redirect(
  106             request.POST.get("next", "") or workshop_request.get_absolute_url()
  107         )
  108 
  109     else:
  110         messages.error(
  111             request,
  112             f"Could not send the email due to form errors: {form.errors}",
  113             fail_silently=True,
  114         )
  115 
  116         return redirect(
  117             request.POST.get("next", "") or workshop_request.get_absolute_url()
  118         )
  119
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/amy/autoemails/utils.py b/amy/autoemails/utils.py
  --- a/amy/autoemails/utils.py
  +++ b/amy/autoemails/utils.py
  @@ -1,5 +1,7 @@
  -from typing import Union
  +from typing import Optional, Union
   
  +from django.conf import settings
  +from django.utils.http import is_safe_url
   import django_rq
   import pytz
   from rq.exceptions import NoSuchJobError
  @@ -66,3 +68,9 @@
           return job.get_status() or "scheduled"
       else:
           return job.get_status() or "cancelled"
  +
  +
  +def safe_next_or_default_url(next_url: Optional[str], default: str) -> str:
  +    if next_url is not None and is_safe_url(next_url, settings.ALLOWED_HOSTS):
  +        return next_url
  +    return default
  diff --git a/amy/autoemails/views.py b/amy/autoemails/views.py
  --- a/amy/autoemails/views.py
  +++ b/amy/autoemails/views.py
  @@ -13,7 +13,7 @@
   from .actions import GenericAction
   from .forms import GenericEmailScheduleForm
   from .models import EmailTemplate, Trigger
  -from .utils import check_status, scheduled_execution_time
  +from .utils import check_status, safe_next_or_default_url, scheduled_execution_time
   
   logger = logging.getLogger("amy.signals")
   scheduler = django_rq.get_scheduler("default")
  @@ -102,9 +102,9 @@
               fail_silently=True,
           )
   
  -        return redirect(
  -            request.POST.get("next", "") or workshop_request.get_absolute_url()
  -        )
  +        default_url = workshop_request.get_absolute_url()
  +        next_url = request.POST.get("next", None)
  +        return redirect(safe_next_or_default_url(next_url, default_url))
   
       else:
           messages.error(
  @@ -113,6 +113,6 @@
               fail_silently=True,
           )
   
  -        return redirect(
  -            request.POST.get("next", "") or workshop_request.get_absolute_url()
  -        )
  +        default_url = workshop_request.get_absolute_url()
  +        next_url = request.POST.get("next", None)
  +        return redirect(safe_next_or_default_url(next_url, default_url))
  
verification_info: {"golden_diff": "diff --git a/amy/autoemails/utils.py b/amy/autoemails/utils.py\n--- a/amy/autoemails/utils.py\n+++ b/amy/autoemails/utils.py\n@@ -1,5 +1,7 @@\n-from typing import Union\n+from typing import Optional, Union\n \n+from django.conf import settings\n+from django.utils.http import is_safe_url\n import django_rq\n import pytz\n from rq.exceptions import NoSuchJobError\n@@ -66,3 +68,9 @@\n         return job.get_status() or \"scheduled\"\n     else:\n         return job.get_status() or \"cancelled\"\n+\n+\n+def safe_next_or_default_url(next_url: Optional[str], default: str) -> str:\n+    if next_url is not None and is_safe_url(next_url, settings.ALLOWED_HOSTS):\n+        return next_url\n+    return default\ndiff --git a/amy/autoemails/views.py b/amy/autoemails/views.py\n--- a/amy/autoemails/views.py\n+++ b/amy/autoemails/views.py\n@@ -13,7 +13,7 @@\n from .actions import GenericAction\n from .forms import GenericEmailScheduleForm\n from .models import EmailTemplate, Trigger\n-from .utils import check_status, scheduled_execution_time\n+from .utils import check_status, safe_next_or_default_url, scheduled_execution_time\n \n logger = logging.getLogger(\"amy.signals\")\n scheduler = django_rq.get_scheduler(\"default\")\n@@ -102,9 +102,9 @@\n             fail_silently=True,\n         )\n \n-        return redirect(\n-            request.POST.get(\"next\", \"\") or workshop_request.get_absolute_url()\n-        )\n+        default_url = workshop_request.get_absolute_url()\n+        next_url = request.POST.get(\"next\", None)\n+        return redirect(safe_next_or_default_url(next_url, default_url))\n \n     else:\n         messages.error(\n@@ -113,6 +113,6 @@\n             fail_silently=True,\n         )\n \n-        return redirect(\n-            request.POST.get(\"next\", \"\") or workshop_request.get_absolute_url()\n-        )\n+        default_url = workshop_request.get_absolute_url()\n+        next_url = request.POST.get(\"next\", None)\n+        return redirect(safe_next_or_default_url(next_url, default_url))\n", "issue": "Make URL redirects from `?next` param safer\nThere are a couple places where we redirect to `?next` value without checking if it's safe. There's a `django.http.is_safe_url` function we could use.\n", "before_files": [{"content": "from typing import Union\n\nimport django_rq\nimport pytz\nfrom rq.exceptions import NoSuchJobError\nfrom rq.job import Job\nfrom rq_scheduler.utils import from_unix\n\n\ndef scheduled_execution_time(job_id, scheduler=None, naive=True):\n    \"\"\"Get RQ-Scheduler scheduled execution time for specific job.\"\"\"\n    _scheduler = scheduler\n    if not scheduler:\n        _scheduler = django_rq.get_scheduler(\"default\")\n\n    # Scheduler keeps jobs in a single key, they are sorted by score, which is\n    # scheduled execution time (linux epoch).  We can retrieve single\n    # entry's score.\n    time = _scheduler.connection.zscore(_scheduler.scheduled_jobs_key, job_id)\n\n    # Convert linux time epoch to UTC.\n    if time:\n        time = from_unix(time)\n        if not naive:\n            # By default, RQ-Scheduler uses UTC naive (TZ-unaware) objects,\n            # which we can \"convert\" to TZ-aware UTC.\n            time = time.replace(tzinfo=pytz.UTC)\n    return time\n\n\ndef compare_emails(a, b):\n    \"\"\"EmailMultiAlternatives doesn't implement __eq__, so we have to\n    cheat our way.\"\"\"\n    if a is None and b is None:\n        return True\n    elif a is None and b or b is None and a:\n        return False\n    else:\n        try:\n            return (\n                a.to == b.to\n                and a.cc == b.cc\n                and a.bcc == b.bcc\n                and a.reply_to == b.reply_to\n                and a.subject == b.subject\n                and a.body == b.body\n            )\n        except AttributeError:\n            return False\n\n\ndef check_status(job: Union[str, Job], scheduler=None):\n    _scheduler = scheduler\n    if not scheduler:\n        _scheduler = django_rq.get_scheduler(\"default\")\n\n    if not isinstance(job, Job):\n        try:\n            job = Job.fetch(job, connection=_scheduler.connection)\n        except NoSuchJobError:\n            return None\n\n    scheduled = scheduled_execution_time(job.get_id(), scheduler)\n\n    if scheduled:\n        return job.get_status() or \"scheduled\"\n    else:\n        return job.get_status() or \"cancelled\"\n", "path": "amy/autoemails/utils.py"}, {"content": "import logging\n\nfrom django.contrib import messages\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.urls import reverse\nfrom django.utils.html import format_html\nfrom django.views.decorators.http import require_POST\nimport django_rq\n\nfrom workshops.models import WorkshopRequest\nfrom workshops.util import admin_required\n\nfrom .actions import GenericAction\nfrom .forms import GenericEmailScheduleForm\nfrom .models import EmailTemplate, Trigger\nfrom .utils import check_status, scheduled_execution_time\n\nlogger = logging.getLogger(\"amy.signals\")\nscheduler = django_rq.get_scheduler(\"default\")\nredis_connection = django_rq.get_connection(\"default\")\n\n\n@require_POST\n@admin_required\ndef generic_schedule_email(request, pk):\n    \"\"\"\n    Generic view for scheduling an email to be sent.\n    \"\"\"\n    template_slug = request.POST.get(\"slug\", \"\")\n    original_template = get_object_or_404(EmailTemplate, slug=template_slug)\n    # Hardcoded, maybe in future respond to other requests, like\n    # SelfOrganizedSubmission or WorkshopInquiry\n    trigger = get_object_or_404(\n        Trigger,\n        action__startswith=\"workshop-request-response\",\n        template__slug=template_slug,\n        active=True,\n    )\n    form = GenericEmailScheduleForm(request.POST, instance=original_template)\n    workshop_request = get_object_or_404(WorkshopRequest, pk=pk)\n\n    if form.is_valid():\n        template = EmailTemplate(\n            slug=form.cleaned_data[\"slug\"],\n            subject=form.cleaned_data[\"subject\"],\n            to_header=form.cleaned_data[\"to_header\"],\n            from_header=form.cleaned_data[\"from_header\"],\n            cc_header=form.cleaned_data[\"cc_header\"],\n            bcc_header=form.cleaned_data[\"bcc_header\"],\n            reply_to_header=form.cleaned_data[\"reply_to_header\"],\n            body_template=form.cleaned_data[\"body_template\"],\n        )\n\n        objects = dict(request=workshop_request)\n        if workshop_request.event:\n            objects[\"event\"] = workshop_request.event\n            objects[\"workshop\"] = workshop_request.event\n\n        action = GenericAction(\n            trigger=trigger,\n            objects=objects,\n        )\n        action_name = GenericAction.__name__\n        launch_at = action.get_launch_at()\n        meta = dict(\n            action=action,\n            template=template,\n            launch_at=launch_at,\n            email=None,\n            context=None,\n        )\n\n        job = scheduler.enqueue_in(launch_at, action, meta=meta)\n        logger.debug(\"%s: enqueueing\", action_name)\n        scheduled_at = scheduled_execution_time(\n            job.get_id(), scheduler=scheduler, naive=False\n        )\n        logger.debug(\"%s: job created [%r]\", action_name, job)\n\n        rqj = workshop_request.rq_jobs.create(\n            job_id=job.get_id(),\n            trigger=trigger,\n            scheduled_execution=scheduled_at,\n            status=check_status(job),\n            mail_status=\"\",\n            event_slug=action.event_slug(),\n            recipients=action.all_recipients(),\n        )\n\n        messages.info(\n            request,\n            format_html(\n                \"New email ({}) was scheduled to run \"\n                '<relative-time datetime=\"{}\">{}</relative-time>: '\n                '<a href=\"{}\">{}</a>.',\n                trigger.get_action_display(),\n                scheduled_at.isoformat(),\n                \"{:%Y-%m-%d %H:%M}\".format(scheduled_at),\n                reverse(\"admin:autoemails_rqjob_preview\", args=[rqj.pk]),\n                job.id,\n            ),\n            fail_silently=True,\n        )\n\n        return redirect(\n            request.POST.get(\"next\", \"\") or workshop_request.get_absolute_url()\n        )\n\n    else:\n        messages.error(\n            request,\n            f\"Could not send the email due to form errors: {form.errors}\",\n            fail_silently=True,\n        )\n\n        return redirect(\n            request.POST.get(\"next\", \"\") or workshop_request.get_absolute_url()\n        )\n", "path": "amy/autoemails/views.py"}], "after_files": [{"content": "from typing import Optional, Union\n\nfrom django.conf import settings\nfrom django.utils.http import is_safe_url\nimport django_rq\nimport pytz\nfrom rq.exceptions import NoSuchJobError\nfrom rq.job import Job\nfrom rq_scheduler.utils import from_unix\n\n\ndef scheduled_execution_time(job_id, scheduler=None, naive=True):\n    \"\"\"Get RQ-Scheduler scheduled execution time for specific job.\"\"\"\n    _scheduler = scheduler\n    if not scheduler:\n        _scheduler = django_rq.get_scheduler(\"default\")\n\n    # Scheduler keeps jobs in a single key, they are sorted by score, which is\n    # scheduled execution time (linux epoch).  We can retrieve single\n    # entry's score.\n    time = _scheduler.connection.zscore(_scheduler.scheduled_jobs_key, job_id)\n\n    # Convert linux time epoch to UTC.\n    if time:\n        time = from_unix(time)\n        if not naive:\n            # By default, RQ-Scheduler uses UTC naive (TZ-unaware) objects,\n            # which we can \"convert\" to TZ-aware UTC.\n            time = time.replace(tzinfo=pytz.UTC)\n    return time\n\n\ndef compare_emails(a, b):\n    \"\"\"EmailMultiAlternatives doesn't implement __eq__, so we have to\n    cheat our way.\"\"\"\n    if a is None and b is None:\n        return True\n    elif a is None and b or b is None and a:\n        return False\n    else:\n        try:\n            return (\n                a.to == b.to\n                and a.cc == b.cc\n                and a.bcc == b.bcc\n                and a.reply_to == b.reply_to\n                and a.subject == b.subject\n                and a.body == b.body\n            )\n        except AttributeError:\n            return False\n\n\ndef check_status(job: Union[str, Job], scheduler=None):\n    _scheduler = scheduler\n    if not scheduler:\n        _scheduler = django_rq.get_scheduler(\"default\")\n\n    if not isinstance(job, Job):\n        try:\n            job = Job.fetch(job, connection=_scheduler.connection)\n        except NoSuchJobError:\n            return None\n\n    scheduled = scheduled_execution_time(job.get_id(), scheduler)\n\n    if scheduled:\n        return job.get_status() or \"scheduled\"\n    else:\n        return job.get_status() or \"cancelled\"\n\n\ndef safe_next_or_default_url(next_url: Optional[str], default: str) -> str:\n    if next_url is not None and is_safe_url(next_url, settings.ALLOWED_HOSTS):\n        return next_url\n    return default\n", "path": "amy/autoemails/utils.py"}, {"content": "import logging\n\nfrom django.contrib import messages\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.urls import reverse\nfrom django.utils.html import format_html\nfrom django.views.decorators.http import require_POST\nimport django_rq\n\nfrom workshops.models import WorkshopRequest\nfrom workshops.util import admin_required\n\nfrom .actions import GenericAction\nfrom .forms import GenericEmailScheduleForm\nfrom .models import EmailTemplate, Trigger\nfrom .utils import check_status, safe_next_or_default_url, scheduled_execution_time\n\nlogger = logging.getLogger(\"amy.signals\")\nscheduler = django_rq.get_scheduler(\"default\")\nredis_connection = django_rq.get_connection(\"default\")\n\n\n@require_POST\n@admin_required\ndef generic_schedule_email(request, pk):\n    \"\"\"\n    Generic view for scheduling an email to be sent.\n    \"\"\"\n    template_slug = request.POST.get(\"slug\", \"\")\n    original_template = get_object_or_404(EmailTemplate, slug=template_slug)\n    # Hardcoded, maybe in future respond to other requests, like\n    # SelfOrganizedSubmission or WorkshopInquiry\n    trigger = get_object_or_404(\n        Trigger,\n        action__startswith=\"workshop-request-response\",\n        template__slug=template_slug,\n        active=True,\n    )\n    form = GenericEmailScheduleForm(request.POST, instance=original_template)\n    workshop_request = get_object_or_404(WorkshopRequest, pk=pk)\n\n    if form.is_valid():\n        template = EmailTemplate(\n            slug=form.cleaned_data[\"slug\"],\n            subject=form.cleaned_data[\"subject\"],\n            to_header=form.cleaned_data[\"to_header\"],\n            from_header=form.cleaned_data[\"from_header\"],\n            cc_header=form.cleaned_data[\"cc_header\"],\n            bcc_header=form.cleaned_data[\"bcc_header\"],\n            reply_to_header=form.cleaned_data[\"reply_to_header\"],\n            body_template=form.cleaned_data[\"body_template\"],\n        )\n\n        objects = dict(request=workshop_request)\n        if workshop_request.event:\n            objects[\"event\"] = workshop_request.event\n            objects[\"workshop\"] = workshop_request.event\n\n        action = GenericAction(\n            trigger=trigger,\n            objects=objects,\n        )\n        action_name = GenericAction.__name__\n        launch_at = action.get_launch_at()\n        meta = dict(\n            action=action,\n            template=template,\n            launch_at=launch_at,\n            email=None,\n            context=None,\n        )\n\n        job = scheduler.enqueue_in(launch_at, action, meta=meta)\n        logger.debug(\"%s: enqueueing\", action_name)\n        scheduled_at = scheduled_execution_time(\n            job.get_id(), scheduler=scheduler, naive=False\n        )\n        logger.debug(\"%s: job created [%r]\", action_name, job)\n\n        rqj = workshop_request.rq_jobs.create(\n            job_id=job.get_id(),\n            trigger=trigger,\n            scheduled_execution=scheduled_at,\n            status=check_status(job),\n            mail_status=\"\",\n            event_slug=action.event_slug(),\n            recipients=action.all_recipients(),\n        )\n\n        messages.info(\n            request,\n            format_html(\n                \"New email ({}) was scheduled to run \"\n                '<relative-time datetime=\"{}\">{}</relative-time>: '\n                '<a href=\"{}\">{}</a>.',\n                trigger.get_action_display(),\n                scheduled_at.isoformat(),\n                \"{:%Y-%m-%d %H:%M}\".format(scheduled_at),\n                reverse(\"admin:autoemails_rqjob_preview\", args=[rqj.pk]),\n                job.id,\n            ),\n            fail_silently=True,\n        )\n\n        default_url = workshop_request.get_absolute_url()\n        next_url = request.POST.get(\"next\", None)\n        return redirect(safe_next_or_default_url(next_url, default_url))\n\n    else:\n        messages.error(\n            request,\n            f\"Could not send the email due to form errors: {form.errors}\",\n            fail_silently=True,\n        )\n\n        default_url = workshop_request.get_absolute_url()\n        next_url = request.POST.get(\"next\", None)\n        return redirect(safe_next_or_default_url(next_url, default_url))\n", "path": "amy/autoemails/views.py"}]}