We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Potential new `datetime` issues
### Describe the issue

See CI failures
* https://github.com/ietf-tools/datatracker/actions/runs/3899998769/jobs/6660186805
* https://github.com/ietf-tools/datatracker/actions/runs/3900011570/jobs/6660211516

There is also this one, which is different but possibly related:
* https://github.com/ietf-tools/datatracker/actions/runs/3900217767/jobs/6660629415

CC @jennifer-richards 

### Code of Conduct

- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ietf/iesg/agenda.py`
Content:
```
1 # Copyright The IETF Trust 2013-2020, All Rights Reserved
2 # -*- coding: utf-8 -*-
3 
4 
5 # utilities for constructing agendas for IESG telechats
6 
7 import io
8 import datetime
9 from collections import OrderedDict
10 
11 from django.conf import settings
12 from django.http import Http404
13 
14 import debug                            # pyflakes:ignore
15 
16 from ietf.doc.models import Document, LastCallDocEvent, ConsensusDocEvent
17 from ietf.doc.utils_search import fill_in_telechat_date
18 from ietf.iesg.models import TelechatDate, TelechatAgendaItem
19 from ietf.review.utils import review_assignments_to_list_for_docs
20 from ietf.utils.timezone import date_today
21 
22 def get_agenda_date(date=None):
23     if not date:
24         try:
25             return TelechatDate.objects.active().order_by('date')[0].date
26         except IndexError:
27             return date_today()
28     else:
29         try:
30             return TelechatDate.objects.active().get(date=datetime.datetime.strptime(date, "%Y-%m-%d").date()).date
31         except (ValueError, TelechatDate.DoesNotExist):
32             raise Http404
33 
34 def get_doc_section(doc):
35     if doc.type_id == 'draft':
36         if doc.intended_std_level_id in ["bcp", "ds", "ps", "std"]:
37             s = "2"
38         else:
39             s = "3"
40 
41         g = doc.group_acronym()
42         if g and str(g) != 'none':
43             s += ".1"
44         elif s == "3" and doc.stream_id in ("ise","irtf"):
45             s += ".3"
46         else:
47             s += ".2"
48         if doc.get_state_slug() != "rfc" and doc.get_state_slug('draft-iesg') not in ("lc", "writeupw", "goaheadw", "iesg-eva", "defer", "approved", "ann", "rfcqueue", "pub"):
49             s += ".3"
50         elif doc.returning_item():
51             s += ".2"
52         else:
53             s += ".1"
54 
55     elif doc.type_id == 'charter':
56         s = "4"
57         if doc.group.state_id in ('active', 'dormant'):
58             s += ".2"
59         else:
60             s += ".1"
61         if doc.get_state_slug() in ('extrev', 'iesgrev'):
62             s += '.2'
63         else:
64             s += '.1'
65 
66     elif doc.type_id == 'statchg':
67         protocol_action = False
68         for relation in doc.relateddocument_set.filter(relationship__slug__in=('tops','tois','tohist','toinf','tobcp','toexp')):
69             if relation.relationship_id in ('tops','tois') or relation.target.document.std_level_id in ('std','ds','ps'):
70                 protocol_action = True
71         if protocol_action:
72             s = "2.3"
73         else:
74             s = "3.3"
75         if doc.get_state_slug() not in ("iesgeval", "defer", "appr-pr", "appr-pend", "appr-sent"):
76             s += ".3"
77         elif doc.returning_item():
78             s += ".2"
79         else:
80             s += ".1"
81 
82     elif doc.type_id == 'conflrev':
83         if not doc.get_state('conflrev') or doc.get_state('conflrev').slug not in ('adrev','iesgeval','appr-reqnopub-pend','appr-reqnopub-sent','appr-noprob-pend','appr-noprob-sent','defer'):
84              s = "3.4.3"
85         elif doc.returning_item():
86              s = "3.4.2"
87         else:
88              s = "3.4.1"
89 
90     return s
91 
92 def agenda_sections():
93     return OrderedDict([
94         ('1', {'title':"Administrivia"}),
95         ('1.1', {'title':"Roll call"}),
96         ('1.2', {'title':"Bash the agenda"}),
97         ('1.3', {'title':"Approval of the minutes of past telechats"}),
98         ('1.4', {'title':"List of remaining action items from last telechat"}),
99         ('2', {'title':"Protocol actions"}),
100         ('2.1', {'title':"WG submissions"}),
101         ('2.1.1', {'title':"New items", 'docs': []}),
102         ('2.1.2', {'title':"Returning items", 'docs':[]}),
103         ('2.1.3', {'title':"For action", 'docs':[]}),
104         ('2.2', {'title':"Individual submissions"}),
105         ('2.2.1', {'title':"New items", 'docs':[]}),
106         ('2.2.2', {'title':"Returning items", 'docs':[]}),
107         ('2.2.3', {'title':"For action", 'docs':[]}),
108         ('2.3', {'title':"Status changes"}),
109         ('2.3.1', {'title':"New items", 'docs':[]}),
110         ('2.3.2', {'title':"Returning items", 'docs':[]}),
111         ('2.3.3', {'title':"For action", 'docs':[]}),
112         ('3', {'title':"Document actions"}),
113         ('3.1', {'title':"WG submissions"}),
114         ('3.1.1', {'title':"New items", 'docs':[]}),
115         ('3.1.2', {'title':"Returning items", 'docs':[]}),
116         ('3.1.3', {'title':"For action", 'docs':[]}),
117         ('3.2', {'title':"Individual submissions via AD"}),
118         ('3.2.1', {'title':"New items", 'docs':[]}),
119         ('3.2.2', {'title':"Returning items", 'docs':[]}),
120         ('3.2.3', {'title':"For action", 'docs':[]}),
121         ('3.3', {'title':"Status changes"}),
122         ('3.3.1', {'title':"New items", 'docs':[]}),
123         ('3.3.2', {'title':"Returning items", 'docs':[]}),
124         ('3.3.3', {'title':"For action", 'docs':[]}),
125         ('3.4', {'title':"IRTF and Independent Submission stream documents"}),
126         ('3.4.1', {'title':"New items", 'docs':[]}),
127         ('3.4.2', {'title':"Returning items", 'docs':[]}),
128         ('3.4.3', {'title':"For action", 'docs':[]}),
129         ('4', {'title':"Working Group actions"}),
130         ('4.1', {'title':"WG creation"}),
131         ('4.1.1', {'title':"Proposed for IETF review", 'docs':[]}),
132         ('4.1.2', {'title':"Proposed for approval", 'docs':[]}),
133         ('4.2', {'title':"WG rechartering"}),
134         ('4.2.1', {'title':"Under evaluation for IETF review", 'docs':[]}),
135         ('4.2.2', {'title':"Proposed for approval", 'docs':[]}),
136         ('5', {'title':"IAB news we can use"}),
137         ('6', {'title':"Management issues"}),
138         ('7', {'title':"Any Other Business (WG News, New Proposals, etc.)"}),
139         ])
140 
141 def fill_in_agenda_administrivia(date, sections):
142     extra_info_files = (
143         ("1.1", "roll_call", settings.IESG_ROLL_CALL_FILE),
144         ("1.3", "minutes", settings.IESG_MINUTES_FILE),
145         ("1.4", "action_items", settings.IESG_TASK_FILE),
146         )
147 
148     for s, key, filename in extra_info_files:
149         try:
150             with io.open(filename, 'r', encoding='utf-8', errors='replace') as f:
151                 t = f.read().strip()
152         except IOError:
153             t = "(Error reading %s)" % filename
154 
155         sections[s]["text"] = t
156 
157 def fill_in_agenda_docs(date, sections, docs=None):
158     if not docs:
159         docs = Document.objects.filter(docevent__telechatdocevent__telechat_date=date)
160         docs = docs.select_related("stream", "group").distinct()
161         fill_in_telechat_date(docs)
162 
163     review_assignments_for_docs = review_assignments_to_list_for_docs(docs)
164 
165     for doc in docs:
166         if doc.telechat_date() != date:
167             continue
168 
169         if not hasattr(doc, 'balloting_started'):
170             e = doc.latest_event(type="started_iesg_process")
171             doc.balloting_started = e.time if e else datetime.datetime.min
172 
173         if doc.type_id == "draft":
174             s = doc.get_state("draft-iana-review")
175             if s: # and s.slug in ("not-ok", "changed", "need-rev"):
176                 doc.iana_review_state = str(s)
177 
178             if doc.get_state_slug("draft-iesg") == "lc":
179                 e = doc.latest_event(LastCallDocEvent, type="sent_last_call")
180                 if e:
181                     doc.lastcall_expires = e.expires
182 
183             if doc.stream_id in ("ietf", "irtf", "iab"):
184                 doc.consensus = "Unknown"
185                 e = doc.latest_event(ConsensusDocEvent, type="changed_consensus")
186                 if e and (e.consensus != None):
187                     doc.consensus = "Yes" if e.consensus else "No"
188 
189             doc.review_assignments = review_assignments_for_docs.get(doc.name, [])
190         elif doc.type_id == "conflrev":
191             doc.conflictdoc = doc.relateddocument_set.get(relationship__slug='conflrev').target.document
192         elif doc.type_id == "charter":
193             pass
194 
195         number = get_doc_section(doc)
196         if number: #  and num in sections
197             sections[number]["docs"].append(doc)
198 
199     # prune empty "For action" sections
200     empty_for_action = [n for n, section in sections.items()
201                         if section["title"] == "For action" and not section["docs"]]
202     for num in empty_for_action:
203         del sections[num]
204 
205     # Be careful to keep this the same as what's used in agenda_documents
206     for s in sections.values():
207         if "docs" in s:
208             s["docs"].sort(key=lambda d: d.balloting_started)
209 
210 def fill_in_agenda_management_issues(date, sections):
211     s = "6.%s"
212     for i, item in enumerate(TelechatAgendaItem.objects.filter(type=3).order_by('id'), start=1):
213         sections[s % i] = { "title": item.title, "text": item.text }
214 
215 def agenda_data(date=None):
216     """Return a dict with the different IESG telechat agenda components."""
217     date = get_agenda_date(date)
218     sections = agenda_sections()
219 
220     fill_in_agenda_administrivia(date, sections)
221     fill_in_agenda_docs(date, sections)
222     fill_in_agenda_management_issues(date, sections)
223 
224     return { 'date': date.isoformat(), 'sections': sections }
```
--- 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/ietf/iesg/agenda.py b/ietf/iesg/agenda.py
--- a/ietf/iesg/agenda.py
+++ b/ietf/iesg/agenda.py
@@ -17,7 +17,7 @@
 from ietf.doc.utils_search import fill_in_telechat_date
 from ietf.iesg.models import TelechatDate, TelechatAgendaItem
 from ietf.review.utils import review_assignments_to_list_for_docs
-from ietf.utils.timezone import date_today
+from ietf.utils.timezone import date_today, make_aware
 
 def get_agenda_date(date=None):
     if not date:
@@ -26,8 +26,9 @@
         except IndexError:
             return date_today()
     else:
+        parsed_date = make_aware(datetime.datetime.strptime(date, "%Y-%m-%d"), settings.TIME_ZONE).date()
         try:
-            return TelechatDate.objects.active().get(date=datetime.datetime.strptime(date, "%Y-%m-%d").date()).date
+            return TelechatDate.objects.active().get(date=parsed_date).date
         except (ValueError, TelechatDate.DoesNotExist):
             raise Http404

{"golden_diff": "diff --git a/ietf/iesg/agenda.py b/ietf/iesg/agenda.py\n--- a/ietf/iesg/agenda.py\n+++ b/ietf/iesg/agenda.py\n@@ -17,7 +17,7 @@\n from ietf.doc.utils_search import fill_in_telechat_date\n from ietf.iesg.models import TelechatDate, TelechatAgendaItem\n from ietf.review.utils import review_assignments_to_list_for_docs\n-from ietf.utils.timezone import date_today\n+from ietf.utils.timezone import date_today, make_aware\n \n def get_agenda_date(date=None):\n     if not date:\n@@ -26,8 +26,9 @@\n         except IndexError:\n             return date_today()\n     else:\n+        parsed_date = make_aware(datetime.datetime.strptime(date, \"%Y-%m-%d\"), settings.TIME_ZONE).date()\n         try:\n-            return TelechatDate.objects.active().get(date=datetime.datetime.strptime(date, \"%Y-%m-%d\").date()).date\n+            return TelechatDate.objects.active().get(date=parsed_date).date\n         except (ValueError, TelechatDate.DoesNotExist):\n             raise Http404\n", "issue": "Potential new `datetime` issues\n### Describe the issue\r\n\r\nSee CI failures\r\n* https://github.com/ietf-tools/datatracker/actions/runs/3899998769/jobs/6660186805\r\n* https://github.com/ietf-tools/datatracker/actions/runs/3900011570/jobs/6660211516\r\n\r\nThere is also this one, which is different but possibly related:\r\n* https://github.com/ietf-tools/datatracker/actions/runs/3900217767/jobs/6660629415\r\n\r\nCC @jennifer-richards \r\n\r\n### Code of Conduct\r\n\r\n- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)\n", "before_files": [{"content": "# Copyright The IETF Trust 2013-2020, All Rights Reserved\n# -*- coding: utf-8 -*-\n\n\n# utilities for constructing agendas for IESG telechats\n\nimport io\nimport datetime\nfrom collections import OrderedDict\n\nfrom django.conf import settings\nfrom django.http import Http404\n\nimport debug                            # pyflakes:ignore\n\nfrom ietf.doc.models import Document, LastCallDocEvent, ConsensusDocEvent\nfrom ietf.doc.utils_search import fill_in_telechat_date\nfrom ietf.iesg.models import TelechatDate, TelechatAgendaItem\nfrom ietf.review.utils import review_assignments_to_list_for_docs\nfrom ietf.utils.timezone import date_today\n\ndef get_agenda_date(date=None):\n    if not date:\n        try:\n            return TelechatDate.objects.active().order_by('date')[0].date\n        except IndexError:\n            return date_today()\n    else:\n        try:\n            return TelechatDate.objects.active().get(date=datetime.datetime.strptime(date, \"%Y-%m-%d\").date()).date\n        except (ValueError, TelechatDate.DoesNotExist):\n            raise Http404\n\ndef get_doc_section(doc):\n    if doc.type_id == 'draft':\n        if doc.intended_std_level_id in [\"bcp\", \"ds\", \"ps\", \"std\"]:\n            s = \"2\"\n        else:\n            s = \"3\"\n\n        g = doc.group_acronym()\n        if g and str(g) != 'none':\n            s += \".1\"\n        elif s == \"3\" and doc.stream_id in (\"ise\",\"irtf\"):\n            s += \".3\"\n        else:\n            s += \".2\"\n        if doc.get_state_slug() != \"rfc\" and doc.get_state_slug('draft-iesg') not in (\"lc\", \"writeupw\", \"goaheadw\", \"iesg-eva\", \"defer\", \"approved\", \"ann\", \"rfcqueue\", \"pub\"):\n            s += \".3\"\n        elif doc.returning_item():\n            s += \".2\"\n        else:\n            s += \".1\"\n\n    elif doc.type_id == 'charter':\n        s = \"4\"\n        if doc.group.state_id in ('active', 'dormant'):\n            s += \".2\"\n        else:\n            s += \".1\"\n        if doc.get_state_slug() in ('extrev', 'iesgrev'):\n            s += '.2'\n        else:\n            s += '.1'\n\n    elif doc.type_id == 'statchg':\n        protocol_action = False\n        for relation in doc.relateddocument_set.filter(relationship__slug__in=('tops','tois','tohist','toinf','tobcp','toexp')):\n            if relation.relationship_id in ('tops','tois') or relation.target.document.std_level_id in ('std','ds','ps'):\n                protocol_action = True\n        if protocol_action:\n            s = \"2.3\"\n        else:\n            s = \"3.3\"\n        if doc.get_state_slug() not in (\"iesgeval\", \"defer\", \"appr-pr\", \"appr-pend\", \"appr-sent\"):\n            s += \".3\"\n        elif doc.returning_item():\n            s += \".2\"\n        else:\n            s += \".1\"\n\n    elif doc.type_id == 'conflrev':\n        if not doc.get_state('conflrev') or doc.get_state('conflrev').slug not in ('adrev','iesgeval','appr-reqnopub-pend','appr-reqnopub-sent','appr-noprob-pend','appr-noprob-sent','defer'):\n             s = \"3.4.3\"\n        elif doc.returning_item():\n             s = \"3.4.2\"\n        else:\n             s = \"3.4.1\"\n\n    return s\n\ndef agenda_sections():\n    return OrderedDict([\n        ('1', {'title':\"Administrivia\"}),\n        ('1.1', {'title':\"Roll call\"}),\n        ('1.2', {'title':\"Bash the agenda\"}),\n        ('1.3', {'title':\"Approval of the minutes of past telechats\"}),\n        ('1.4', {'title':\"List of remaining action items from last telechat\"}),\n        ('2', {'title':\"Protocol actions\"}),\n        ('2.1', {'title':\"WG submissions\"}),\n        ('2.1.1', {'title':\"New items\", 'docs': []}),\n        ('2.1.2', {'title':\"Returning items\", 'docs':[]}),\n        ('2.1.3', {'title':\"For action\", 'docs':[]}),\n        ('2.2', {'title':\"Individual submissions\"}),\n        ('2.2.1', {'title':\"New items\", 'docs':[]}),\n        ('2.2.2', {'title':\"Returning items\", 'docs':[]}),\n        ('2.2.3', {'title':\"For action\", 'docs':[]}),\n        ('2.3', {'title':\"Status changes\"}),\n        ('2.3.1', {'title':\"New items\", 'docs':[]}),\n        ('2.3.2', {'title':\"Returning items\", 'docs':[]}),\n        ('2.3.3', {'title':\"For action\", 'docs':[]}),\n        ('3', {'title':\"Document actions\"}),\n        ('3.1', {'title':\"WG submissions\"}),\n        ('3.1.1', {'title':\"New items\", 'docs':[]}),\n        ('3.1.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.1.3', {'title':\"For action\", 'docs':[]}),\n        ('3.2', {'title':\"Individual submissions via AD\"}),\n        ('3.2.1', {'title':\"New items\", 'docs':[]}),\n        ('3.2.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.2.3', {'title':\"For action\", 'docs':[]}),\n        ('3.3', {'title':\"Status changes\"}),\n        ('3.3.1', {'title':\"New items\", 'docs':[]}),\n        ('3.3.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.3.3', {'title':\"For action\", 'docs':[]}),\n        ('3.4', {'title':\"IRTF and Independent Submission stream documents\"}),\n        ('3.4.1', {'title':\"New items\", 'docs':[]}),\n        ('3.4.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.4.3', {'title':\"For action\", 'docs':[]}),\n        ('4', {'title':\"Working Group actions\"}),\n        ('4.1', {'title':\"WG creation\"}),\n        ('4.1.1', {'title':\"Proposed for IETF review\", 'docs':[]}),\n        ('4.1.2', {'title':\"Proposed for approval\", 'docs':[]}),\n        ('4.2', {'title':\"WG rechartering\"}),\n        ('4.2.1', {'title':\"Under evaluation for IETF review\", 'docs':[]}),\n        ('4.2.2', {'title':\"Proposed for approval\", 'docs':[]}),\n        ('5', {'title':\"IAB news we can use\"}),\n        ('6', {'title':\"Management issues\"}),\n        ('7', {'title':\"Any Other Business (WG News, New Proposals, etc.)\"}),\n        ])\n\ndef fill_in_agenda_administrivia(date, sections):\n    extra_info_files = (\n        (\"1.1\", \"roll_call\", settings.IESG_ROLL_CALL_FILE),\n        (\"1.3\", \"minutes\", settings.IESG_MINUTES_FILE),\n        (\"1.4\", \"action_items\", settings.IESG_TASK_FILE),\n        )\n\n    for s, key, filename in extra_info_files:\n        try:\n            with io.open(filename, 'r', encoding='utf-8', errors='replace') as f:\n                t = f.read().strip()\n        except IOError:\n            t = \"(Error reading %s)\" % filename\n\n        sections[s][\"text\"] = t\n\ndef fill_in_agenda_docs(date, sections, docs=None):\n    if not docs:\n        docs = Document.objects.filter(docevent__telechatdocevent__telechat_date=date)\n        docs = docs.select_related(\"stream\", \"group\").distinct()\n        fill_in_telechat_date(docs)\n\n    review_assignments_for_docs = review_assignments_to_list_for_docs(docs)\n\n    for doc in docs:\n        if doc.telechat_date() != date:\n            continue\n\n        if not hasattr(doc, 'balloting_started'):\n            e = doc.latest_event(type=\"started_iesg_process\")\n            doc.balloting_started = e.time if e else datetime.datetime.min\n\n        if doc.type_id == \"draft\":\n            s = doc.get_state(\"draft-iana-review\")\n            if s: # and s.slug in (\"not-ok\", \"changed\", \"need-rev\"):\n                doc.iana_review_state = str(s)\n\n            if doc.get_state_slug(\"draft-iesg\") == \"lc\":\n                e = doc.latest_event(LastCallDocEvent, type=\"sent_last_call\")\n                if e:\n                    doc.lastcall_expires = e.expires\n\n            if doc.stream_id in (\"ietf\", \"irtf\", \"iab\"):\n                doc.consensus = \"Unknown\"\n                e = doc.latest_event(ConsensusDocEvent, type=\"changed_consensus\")\n                if e and (e.consensus != None):\n                    doc.consensus = \"Yes\" if e.consensus else \"No\"\n\n            doc.review_assignments = review_assignments_for_docs.get(doc.name, [])\n        elif doc.type_id == \"conflrev\":\n            doc.conflictdoc = doc.relateddocument_set.get(relationship__slug='conflrev').target.document\n        elif doc.type_id == \"charter\":\n            pass\n\n        number = get_doc_section(doc)\n        if number: #  and num in sections\n            sections[number][\"docs\"].append(doc)\n\n    # prune empty \"For action\" sections\n    empty_for_action = [n for n, section in sections.items()\n                        if section[\"title\"] == \"For action\" and not section[\"docs\"]]\n    for num in empty_for_action:\n        del sections[num]\n\n    # Be careful to keep this the same as what's used in agenda_documents\n    for s in sections.values():\n        if \"docs\" in s:\n            s[\"docs\"].sort(key=lambda d: d.balloting_started)\n\ndef fill_in_agenda_management_issues(date, sections):\n    s = \"6.%s\"\n    for i, item in enumerate(TelechatAgendaItem.objects.filter(type=3).order_by('id'), start=1):\n        sections[s % i] = { \"title\": item.title, \"text\": item.text }\n\ndef agenda_data(date=None):\n    \"\"\"Return a dict with the different IESG telechat agenda components.\"\"\"\n    date = get_agenda_date(date)\n    sections = agenda_sections()\n\n    fill_in_agenda_administrivia(date, sections)\n    fill_in_agenda_docs(date, sections)\n    fill_in_agenda_management_issues(date, sections)\n\n    return { 'date': date.isoformat(), 'sections': sections }", "path": "ietf/iesg/agenda.py"}], "after_files": [{"content": "# Copyright The IETF Trust 2013-2020, All Rights Reserved\n# -*- coding: utf-8 -*-\n\n\n# utilities for constructing agendas for IESG telechats\n\nimport io\nimport datetime\nfrom collections import OrderedDict\n\nfrom django.conf import settings\nfrom django.http import Http404\n\nimport debug                            # pyflakes:ignore\n\nfrom ietf.doc.models import Document, LastCallDocEvent, ConsensusDocEvent\nfrom ietf.doc.utils_search import fill_in_telechat_date\nfrom ietf.iesg.models import TelechatDate, TelechatAgendaItem\nfrom ietf.review.utils import review_assignments_to_list_for_docs\nfrom ietf.utils.timezone import date_today, make_aware\n\ndef get_agenda_date(date=None):\n    if not date:\n        try:\n            return TelechatDate.objects.active().order_by('date')[0].date\n        except IndexError:\n            return date_today()\n    else:\n        parsed_date = make_aware(datetime.datetime.strptime(date, \"%Y-%m-%d\"), settings.TIME_ZONE).date()\n        try:\n            return TelechatDate.objects.active().get(date=parsed_date).date\n        except (ValueError, TelechatDate.DoesNotExist):\n            raise Http404\n\ndef get_doc_section(doc):\n    if doc.type_id == 'draft':\n        if doc.intended_std_level_id in [\"bcp\", \"ds\", \"ps\", \"std\"]:\n            s = \"2\"\n        else:\n            s = \"3\"\n\n        g = doc.group_acronym()\n        if g and str(g) != 'none':\n            s += \".1\"\n        elif s == \"3\" and doc.stream_id in (\"ise\",\"irtf\"):\n            s += \".3\"\n        else:\n            s += \".2\"\n        if doc.get_state_slug() != \"rfc\" and doc.get_state_slug('draft-iesg') not in (\"lc\", \"writeupw\", \"goaheadw\", \"iesg-eva\", \"defer\", \"approved\", \"ann\", \"rfcqueue\", \"pub\"):\n            s += \".3\"\n        elif doc.returning_item():\n            s += \".2\"\n        else:\n            s += \".1\"\n\n    elif doc.type_id == 'charter':\n        s = \"4\"\n        if doc.group.state_id in ('active', 'dormant'):\n            s += \".2\"\n        else:\n            s += \".1\"\n        if doc.get_state_slug() in ('extrev', 'iesgrev'):\n            s += '.2'\n        else:\n            s += '.1'\n\n    elif doc.type_id == 'statchg':\n        protocol_action = False\n        for relation in doc.relateddocument_set.filter(relationship__slug__in=('tops','tois','tohist','toinf','tobcp','toexp')):\n            if relation.relationship_id in ('tops','tois') or relation.target.document.std_level_id in ('std','ds','ps'):\n                protocol_action = True\n        if protocol_action:\n            s = \"2.3\"\n        else:\n            s = \"3.3\"\n        if doc.get_state_slug() not in (\"iesgeval\", \"defer\", \"appr-pr\", \"appr-pend\", \"appr-sent\"):\n            s += \".3\"\n        elif doc.returning_item():\n            s += \".2\"\n        else:\n            s += \".1\"\n\n    elif doc.type_id == 'conflrev':\n        if not doc.get_state('conflrev') or doc.get_state('conflrev').slug not in ('adrev','iesgeval','appr-reqnopub-pend','appr-reqnopub-sent','appr-noprob-pend','appr-noprob-sent','defer'):\n             s = \"3.4.3\"\n        elif doc.returning_item():\n             s = \"3.4.2\"\n        else:\n             s = \"3.4.1\"\n\n    return s\n\ndef agenda_sections():\n    return OrderedDict([\n        ('1', {'title':\"Administrivia\"}),\n        ('1.1', {'title':\"Roll call\"}),\n        ('1.2', {'title':\"Bash the agenda\"}),\n        ('1.3', {'title':\"Approval of the minutes of past telechats\"}),\n        ('1.4', {'title':\"List of remaining action items from last telechat\"}),\n        ('2', {'title':\"Protocol actions\"}),\n        ('2.1', {'title':\"WG submissions\"}),\n        ('2.1.1', {'title':\"New items\", 'docs': []}),\n        ('2.1.2', {'title':\"Returning items\", 'docs':[]}),\n        ('2.1.3', {'title':\"For action\", 'docs':[]}),\n        ('2.2', {'title':\"Individual submissions\"}),\n        ('2.2.1', {'title':\"New items\", 'docs':[]}),\n        ('2.2.2', {'title':\"Returning items\", 'docs':[]}),\n        ('2.2.3', {'title':\"For action\", 'docs':[]}),\n        ('2.3', {'title':\"Status changes\"}),\n        ('2.3.1', {'title':\"New items\", 'docs':[]}),\n        ('2.3.2', {'title':\"Returning items\", 'docs':[]}),\n        ('2.3.3', {'title':\"For action\", 'docs':[]}),\n        ('3', {'title':\"Document actions\"}),\n        ('3.1', {'title':\"WG submissions\"}),\n        ('3.1.1', {'title':\"New items\", 'docs':[]}),\n        ('3.1.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.1.3', {'title':\"For action\", 'docs':[]}),\n        ('3.2', {'title':\"Individual submissions via AD\"}),\n        ('3.2.1', {'title':\"New items\", 'docs':[]}),\n        ('3.2.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.2.3', {'title':\"For action\", 'docs':[]}),\n        ('3.3', {'title':\"Status changes\"}),\n        ('3.3.1', {'title':\"New items\", 'docs':[]}),\n        ('3.3.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.3.3', {'title':\"For action\", 'docs':[]}),\n        ('3.4', {'title':\"IRTF and Independent Submission stream documents\"}),\n        ('3.4.1', {'title':\"New items\", 'docs':[]}),\n        ('3.4.2', {'title':\"Returning items\", 'docs':[]}),\n        ('3.4.3', {'title':\"For action\", 'docs':[]}),\n        ('4', {'title':\"Working Group actions\"}),\n        ('4.1', {'title':\"WG creation\"}),\n        ('4.1.1', {'title':\"Proposed for IETF review\", 'docs':[]}),\n        ('4.1.2', {'title':\"Proposed for approval\", 'docs':[]}),\n        ('4.2', {'title':\"WG rechartering\"}),\n        ('4.2.1', {'title':\"Under evaluation for IETF review\", 'docs':[]}),\n        ('4.2.2', {'title':\"Proposed for approval\", 'docs':[]}),\n        ('5', {'title':\"IAB news we can use\"}),\n        ('6', {'title':\"Management issues\"}),\n        ('7', {'title':\"Any Other Business (WG News, New Proposals, etc.)\"}),\n        ])\n\ndef fill_in_agenda_administrivia(date, sections):\n    extra_info_files = (\n        (\"1.1\", \"roll_call\", settings.IESG_ROLL_CALL_FILE),\n        (\"1.3\", \"minutes\", settings.IESG_MINUTES_FILE),\n        (\"1.4\", \"action_items\", settings.IESG_TASK_FILE),\n        )\n\n    for s, key, filename in extra_info_files:\n        try:\n            with io.open(filename, 'r', encoding='utf-8', errors='replace') as f:\n                t = f.read().strip()\n        except IOError:\n            t = \"(Error reading %s)\" % filename\n\n        sections[s][\"text\"] = t\n\ndef fill_in_agenda_docs(date, sections, docs=None):\n    if not docs:\n        docs = Document.objects.filter(docevent__telechatdocevent__telechat_date=date)\n        docs = docs.select_related(\"stream\", \"group\").distinct()\n        fill_in_telechat_date(docs)\n\n    review_assignments_for_docs = review_assignments_to_list_for_docs(docs)\n\n    for doc in docs:\n        if doc.telechat_date() != date:\n            continue\n\n        if not hasattr(doc, 'balloting_started'):\n            e = doc.latest_event(type=\"started_iesg_process\")\n            doc.balloting_started = e.time if e else datetime.datetime.min\n\n        if doc.type_id == \"draft\":\n            s = doc.get_state(\"draft-iana-review\")\n            if s: # and s.slug in (\"not-ok\", \"changed\", \"need-rev\"):\n                doc.iana_review_state = str(s)\n\n            if doc.get_state_slug(\"draft-iesg\") == \"lc\":\n                e = doc.latest_event(LastCallDocEvent, type=\"sent_last_call\")\n                if e:\n                    doc.lastcall_expires = e.expires\n\n            if doc.stream_id in (\"ietf\", \"irtf\", \"iab\"):\n                doc.consensus = \"Unknown\"\n                e = doc.latest_event(ConsensusDocEvent, type=\"changed_consensus\")\n                if e and (e.consensus != None):\n                    doc.consensus = \"Yes\" if e.consensus else \"No\"\n\n            doc.review_assignments = review_assignments_for_docs.get(doc.name, [])\n        elif doc.type_id == \"conflrev\":\n            doc.conflictdoc = doc.relateddocument_set.get(relationship__slug='conflrev').target.document\n        elif doc.type_id == \"charter\":\n            pass\n\n        number = get_doc_section(doc)\n        if number: #  and num in sections\n            sections[number][\"docs\"].append(doc)\n\n    # prune empty \"For action\" sections\n    empty_for_action = [n for n, section in sections.items()\n                        if section[\"title\"] == \"For action\" and not section[\"docs\"]]\n    for num in empty_for_action:\n        del sections[num]\n\n    # Be careful to keep this the same as what's used in agenda_documents\n    for s in sections.values():\n        if \"docs\" in s:\n            s[\"docs\"].sort(key=lambda d: d.balloting_started)\n\ndef fill_in_agenda_management_issues(date, sections):\n    s = \"6.%s\"\n    for i, item in enumerate(TelechatAgendaItem.objects.filter(type=3).order_by('id'), start=1):\n        sections[s % i] = { \"title\": item.title, \"text\": item.text }\n\ndef agenda_data(date=None):\n    \"\"\"Return a dict with the different IESG telechat agenda components.\"\"\"\n    date = get_agenda_date(date)\n    sections = agenda_sections()\n\n    fill_in_agenda_administrivia(date, sections)\n    fill_in_agenda_docs(date, sections)\n    fill_in_agenda_management_issues(date, sections)\n\n    return { 'date': date.isoformat(), 'sections': sections }", "path": "ietf/iesg/agenda.py"}]}