We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot view upcoming teaching opportunities
Hi @maneesha 
Could you please help me with this?

The blue button at https://amy.carpentries.org/dashboard/instructor/
as shown in the screenshot below
![image](https://user-images.githubusercontent.com/3046889/197223287-5b007ba0-fd6a-47d6-b719-ec1509a54cc6.png)

leads to "Server Error (500)" at https://amy.carpentries.org/dashboard/instructor/teaching_opportunities/
as shown in the screenshot below
![image](https://user-images.githubusercontent.com/3046889/197223554-9cf5bde1-58e2-4f5c-b93f-392b79e46a3c.png)

Tried a few times at different hours.

Thank you in advance.

--- 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/recruitment/templatetags/instructorrecruitment.py`
Content:
```
1 from datetime import timedelta
2 from typing import Sequence, Union
3 
4 from django import template
5 from django.conf import settings
6 
7 from recruitment.models import (
8     InstructorRecruitment,
9     InstructorRecruitmentSignup,
10     RecruitmentPriority,
11 )
12 from workshops.models import Event
13 
14 register = template.Library()
15 
16 
17 @register.simple_tag
18 def is_instructor_recruitment_enabled() -> bool:
19     try:
20         return bool(settings.INSTRUCTOR_RECRUITMENT_ENABLED)
21     except AttributeError:
22         return False
23 
24 
25 @register.simple_tag
26 def get_event_conflicts(events: Sequence[Event], event: Event) -> list[Event]:
27     conflicts: list[Event] = []
28 
29     for event_to_check in events:
30         if event == event_to_check:
31             continue
32 
33         if event.start <= event_to_check.end and event.end >= event_to_check.start:
34             conflicts.append(event_to_check)
35 
36     return conflicts
37 
38 
39 @register.simple_tag
40 def get_events_nearby(
41     events: Sequence[Event], event: Event, days_before: int = 14, days_after: int = 14
42 ) -> list[Event]:
43     nearby: list[Event] = []
44 
45     for event_to_check in events:
46         if event == event_to_check:
47             continue
48 
49         if (
50             event.start - timedelta(days=days_before) <= event_to_check.end
51             and event.end + timedelta(days=days_after) >= event_to_check.start
52         ):
53             nearby.append(event_to_check)
54 
55     return nearby
56 
57 
58 @register.simple_tag
59 def get_signup_conflicts(
60     signups: Sequence[InstructorRecruitmentSignup], recruitment: InstructorRecruitment
61 ) -> list[InstructorRecruitmentSignup]:
62     conflicts: list[InstructorRecruitmentSignup] = []
63 
64     for signup_to_check in signups:
65         if recruitment == signup_to_check.recruitment:
66             continue
67 
68         if (
69             recruitment.event.start <= signup_to_check.recruitment.event.end
70             and recruitment.event.end >= signup_to_check.recruitment.event.start
71         ):
72             conflicts.append(signup_to_check)
73 
74     return conflicts
75 
76 
77 @register.filter
78 def priority_label(value: Union[int, RecruitmentPriority]) -> str:
79     return RecruitmentPriority(value).label
80
```
--- 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/amy/recruitment/templatetags/instructorrecruitment.py b/amy/recruitment/templatetags/instructorrecruitment.py
--- a/amy/recruitment/templatetags/instructorrecruitment.py
+++ b/amy/recruitment/templatetags/instructorrecruitment.py
@@ -23,13 +23,21 @@
 
 
 @register.simple_tag
-def get_event_conflicts(events: Sequence[Event], event: Event) -> list[Event]:
+def get_event_conflicts(events_to_check: Sequence[Event], event: Event) -> list[Event]:
     conflicts: list[Event] = []
 
-    for event_to_check in events:
+    # event must have start and end dates, otherwise we can't get conflicts
+    if not (event.start and event.end):
+        return conflicts
+
+    for event_to_check in events_to_check:
         if event == event_to_check:
             continue
 
+        # event getting checked must have start and end dates
+        if not (event_to_check.start and event_to_check.end):
+            continue
+
         if event.start <= event_to_check.end and event.end >= event_to_check.start:
             conflicts.append(event_to_check)
 
@@ -38,14 +46,26 @@
 
 @register.simple_tag
 def get_events_nearby(
-    events: Sequence[Event], event: Event, days_before: int = 14, days_after: int = 14
+    events_to_check: Sequence[Event],
+    event: Event,
+    days_before: int = 14,
+    days_after: int = 14,
 ) -> list[Event]:
+    """Get events nearby another event time-wise."""
     nearby: list[Event] = []
 
-    for event_to_check in events:
+    # event must have start and end dates, otherwise we can't get nearby events
+    if not (event.start and event.end):
+        return nearby
+
+    for event_to_check in events_to_check:
         if event == event_to_check:
             continue
 
+        # event getting checked must have start and end dates
+        if not (event_to_check.start and event_to_check.end):
+            continue
+
         if (
             event.start - timedelta(days=days_before) <= event_to_check.end
             and event.end + timedelta(days=days_after) >= event_to_check.start
@@ -57,14 +77,26 @@
 
 @register.simple_tag
 def get_signup_conflicts(
-    signups: Sequence[InstructorRecruitmentSignup], recruitment: InstructorRecruitment
+    signups_to_check: Sequence[InstructorRecruitmentSignup],
+    recruitment: InstructorRecruitment,
 ) -> list[InstructorRecruitmentSignup]:
     conflicts: list[InstructorRecruitmentSignup] = []
 
-    for signup_to_check in signups:
+    # recruitment event must have start and end dates, otherwise we can't get conflicts
+    if not (recruitment.event.start and recruitment.event.end):
+        return conflicts
+
+    for signup_to_check in signups_to_check:
         if recruitment == signup_to_check.recruitment:
             continue
 
+        # event getting checked must have start and end dates
+        if not (
+            signup_to_check.recruitment.event.start
+            and signup_to_check.recruitment.event.end
+        ):
+            continue
+
         if (
             recruitment.event.start <= signup_to_check.recruitment.event.end
             and recruitment.event.end >= signup_to_check.recruitment.event.start

{"golden_diff": "diff --git a/amy/recruitment/templatetags/instructorrecruitment.py b/amy/recruitment/templatetags/instructorrecruitment.py\n--- a/amy/recruitment/templatetags/instructorrecruitment.py\n+++ b/amy/recruitment/templatetags/instructorrecruitment.py\n@@ -23,13 +23,21 @@\n \n \n @register.simple_tag\n-def get_event_conflicts(events: Sequence[Event], event: Event) -> list[Event]:\n+def get_event_conflicts(events_to_check: Sequence[Event], event: Event) -> list[Event]:\n     conflicts: list[Event] = []\n \n-    for event_to_check in events:\n+    # event must have start and end dates, otherwise we can't get conflicts\n+    if not (event.start and event.end):\n+        return conflicts\n+\n+    for event_to_check in events_to_check:\n         if event == event_to_check:\n             continue\n \n+        # event getting checked must have start and end dates\n+        if not (event_to_check.start and event_to_check.end):\n+            continue\n+\n         if event.start <= event_to_check.end and event.end >= event_to_check.start:\n             conflicts.append(event_to_check)\n \n@@ -38,14 +46,26 @@\n \n @register.simple_tag\n def get_events_nearby(\n-    events: Sequence[Event], event: Event, days_before: int = 14, days_after: int = 14\n+    events_to_check: Sequence[Event],\n+    event: Event,\n+    days_before: int = 14,\n+    days_after: int = 14,\n ) -> list[Event]:\n+    \"\"\"Get events nearby another event time-wise.\"\"\"\n     nearby: list[Event] = []\n \n-    for event_to_check in events:\n+    # event must have start and end dates, otherwise we can't get nearby events\n+    if not (event.start and event.end):\n+        return nearby\n+\n+    for event_to_check in events_to_check:\n         if event == event_to_check:\n             continue\n \n+        # event getting checked must have start and end dates\n+        if not (event_to_check.start and event_to_check.end):\n+            continue\n+\n         if (\n             event.start - timedelta(days=days_before) <= event_to_check.end\n             and event.end + timedelta(days=days_after) >= event_to_check.start\n@@ -57,14 +77,26 @@\n \n @register.simple_tag\n def get_signup_conflicts(\n-    signups: Sequence[InstructorRecruitmentSignup], recruitment: InstructorRecruitment\n+    signups_to_check: Sequence[InstructorRecruitmentSignup],\n+    recruitment: InstructorRecruitment,\n ) -> list[InstructorRecruitmentSignup]:\n     conflicts: list[InstructorRecruitmentSignup] = []\n \n-    for signup_to_check in signups:\n+    # recruitment event must have start and end dates, otherwise we can't get conflicts\n+    if not (recruitment.event.start and recruitment.event.end):\n+        return conflicts\n+\n+    for signup_to_check in signups_to_check:\n         if recruitment == signup_to_check.recruitment:\n             continue\n \n+        # event getting checked must have start and end dates\n+        if not (\n+            signup_to_check.recruitment.event.start\n+            and signup_to_check.recruitment.event.end\n+        ):\n+            continue\n+\n         if (\n             recruitment.event.start <= signup_to_check.recruitment.event.end\n             and recruitment.event.end >= signup_to_check.recruitment.event.start\n", "issue": "Cannot view upcoming teaching opportunities\nHi @maneesha \r\nCould you please help me with this?\r\n\r\nThe blue button at https://amy.carpentries.org/dashboard/instructor/\r\nas shown in the screenshot below\r\n![image](https://user-images.githubusercontent.com/3046889/197223287-5b007ba0-fd6a-47d6-b719-ec1509a54cc6.png)\r\n\r\nleads to \"Server Error (500)\" at https://amy.carpentries.org/dashboard/instructor/teaching_opportunities/\r\nas shown in the screenshot below\r\n![image](https://user-images.githubusercontent.com/3046889/197223554-9cf5bde1-58e2-4f5c-b93f-392b79e46a3c.png)\r\n\r\nTried a few times at different hours.\r\n\r\nThank you in advance.\n", "before_files": [{"content": "from datetime import timedelta\nfrom typing import Sequence, Union\n\nfrom django import template\nfrom django.conf import settings\n\nfrom recruitment.models import (\n    InstructorRecruitment,\n    InstructorRecruitmentSignup,\n    RecruitmentPriority,\n)\nfrom workshops.models import Event\n\nregister = template.Library()\n\n\n@register.simple_tag\ndef is_instructor_recruitment_enabled() -> bool:\n    try:\n        return bool(settings.INSTRUCTOR_RECRUITMENT_ENABLED)\n    except AttributeError:\n        return False\n\n\n@register.simple_tag\ndef get_event_conflicts(events: Sequence[Event], event: Event) -> list[Event]:\n    conflicts: list[Event] = []\n\n    for event_to_check in events:\n        if event == event_to_check:\n            continue\n\n        if event.start <= event_to_check.end and event.end >= event_to_check.start:\n            conflicts.append(event_to_check)\n\n    return conflicts\n\n\n@register.simple_tag\ndef get_events_nearby(\n    events: Sequence[Event], event: Event, days_before: int = 14, days_after: int = 14\n) -> list[Event]:\n    nearby: list[Event] = []\n\n    for event_to_check in events:\n        if event == event_to_check:\n            continue\n\n        if (\n            event.start - timedelta(days=days_before) <= event_to_check.end\n            and event.end + timedelta(days=days_after) >= event_to_check.start\n        ):\n            nearby.append(event_to_check)\n\n    return nearby\n\n\n@register.simple_tag\ndef get_signup_conflicts(\n    signups: Sequence[InstructorRecruitmentSignup], recruitment: InstructorRecruitment\n) -> list[InstructorRecruitmentSignup]:\n    conflicts: list[InstructorRecruitmentSignup] = []\n\n    for signup_to_check in signups:\n        if recruitment == signup_to_check.recruitment:\n            continue\n\n        if (\n            recruitment.event.start <= signup_to_check.recruitment.event.end\n            and recruitment.event.end >= signup_to_check.recruitment.event.start\n        ):\n            conflicts.append(signup_to_check)\n\n    return conflicts\n\n\n@register.filter\ndef priority_label(value: Union[int, RecruitmentPriority]) -> str:\n    return RecruitmentPriority(value).label\n", "path": "amy/recruitment/templatetags/instructorrecruitment.py"}], "after_files": [{"content": "from datetime import timedelta\nfrom typing import Sequence, Union\n\nfrom django import template\nfrom django.conf import settings\n\nfrom recruitment.models import (\n    InstructorRecruitment,\n    InstructorRecruitmentSignup,\n    RecruitmentPriority,\n)\nfrom workshops.models import Event\n\nregister = template.Library()\n\n\n@register.simple_tag\ndef is_instructor_recruitment_enabled() -> bool:\n    try:\n        return bool(settings.INSTRUCTOR_RECRUITMENT_ENABLED)\n    except AttributeError:\n        return False\n\n\n@register.simple_tag\ndef get_event_conflicts(events_to_check: Sequence[Event], event: Event) -> list[Event]:\n    conflicts: list[Event] = []\n\n    # event must have start and end dates, otherwise we can't get conflicts\n    if not (event.start and event.end):\n        return conflicts\n\n    for event_to_check in events_to_check:\n        if event == event_to_check:\n            continue\n\n        # event getting checked must have start and end dates\n        if not (event_to_check.start and event_to_check.end):\n            continue\n\n        if event.start <= event_to_check.end and event.end >= event_to_check.start:\n            conflicts.append(event_to_check)\n\n    return conflicts\n\n\n@register.simple_tag\ndef get_events_nearby(\n    events_to_check: Sequence[Event],\n    event: Event,\n    days_before: int = 14,\n    days_after: int = 14,\n) -> list[Event]:\n    \"\"\"Get events nearby another event time-wise.\"\"\"\n    nearby: list[Event] = []\n\n    # event must have start and end dates, otherwise we can't get nearby events\n    if not (event.start and event.end):\n        return nearby\n\n    for event_to_check in events_to_check:\n        if event == event_to_check:\n            continue\n\n        # event getting checked must have start and end dates\n        if not (event_to_check.start and event_to_check.end):\n            continue\n\n        if (\n            event.start - timedelta(days=days_before) <= event_to_check.end\n            and event.end + timedelta(days=days_after) >= event_to_check.start\n        ):\n            nearby.append(event_to_check)\n\n    return nearby\n\n\n@register.simple_tag\ndef get_signup_conflicts(\n    signups_to_check: Sequence[InstructorRecruitmentSignup],\n    recruitment: InstructorRecruitment,\n) -> list[InstructorRecruitmentSignup]:\n    conflicts: list[InstructorRecruitmentSignup] = []\n\n    # recruitment event must have start and end dates, otherwise we can't get conflicts\n    if not (recruitment.event.start and recruitment.event.end):\n        return conflicts\n\n    for signup_to_check in signups_to_check:\n        if recruitment == signup_to_check.recruitment:\n            continue\n\n        # event getting checked must have start and end dates\n        if not (\n            signup_to_check.recruitment.event.start\n            and signup_to_check.recruitment.event.end\n        ):\n            continue\n\n        if (\n            recruitment.event.start <= signup_to_check.recruitment.event.end\n            and recruitment.event.end >= signup_to_check.recruitment.event.start\n        ):\n            conflicts.append(signup_to_check)\n\n    return conflicts\n\n\n@register.filter\ndef priority_label(value: Union[int, RecruitmentPriority]) -> str:\n    return RecruitmentPriority(value).label\n", "path": "amy/recruitment/templatetags/instructorrecruitment.py"}]}