We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Update links in lessons to use generate resources
Items in the "CS Unplugged Provided Resources" still have links pointing at google drive where there are now generated resources available, these links should be updated.
Spotted in Lesson 1 (8-10) of Binary Numbers.
Update binary numbers 8 - 10 lessons
This includes adding learning outcomes and updating text.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `csunplugged/topics/views.py`
Content:
```
1 """Views for the topics application."""
2 
3 from django.shortcuts import get_object_or_404
4 from django.views import generic
5 from django.http import JsonResponse, Http404
6 from general.templatetags.render_html_field import render_html_with_static
7 from utils.group_lessons_by_age import group_lessons_by_age
8 from .models import (
9     Topic,
10     CurriculumIntegration,
11     UnitPlan,
12     Lesson,
13     ProgrammingExercise,
14     ProgrammingExerciseLanguageImplementation,
15     ConnectedGeneratedResource,
16     GlossaryTerm,
17 )
18 
19 
20 class IndexView(generic.ListView):
21     """View for the topics application homepage."""
22 
23     template_name = "topics/index.html"
24     context_object_name = "all_topics"
25 
26     def get_queryset(self):
27         """Get queryset of all topics.
28 
29         Returns:
30             Queryset of Topic objects ordered by name.
31         """
32         return Topic.objects.order_by("name")
33 
34 
35 class TopicView(generic.DetailView):
36     """View for a specific topic."""
37 
38     model = Topic
39     template_name = "topics/topic.html"
40     slug_url_kwarg = "topic_slug"
41 
42     def get_context_data(self, **kwargs):
43         """Provide the context data for the topic view.
44 
45         Returns:
46             Dictionary of context data.
47         """
48         # Call the base implementation first to get a context
49         context = super(TopicView, self).get_context_data(**kwargs)
50         # Add in a QuerySet of all the connected unit plans
51         unit_plans = UnitPlan.objects.filter(topic=self.object).order_by("name").select_related()
52         for unit_plan in unit_plans:
53             unit_plan.grouped_lessons = group_lessons_by_age(unit_plan.unit_plan_lessons)
54         context["unit_plans"] = unit_plans
55         # Add in a QuerySet of all the connected curriculum integrations
56         context["curriculum_integrations"] = CurriculumIntegration.objects.filter(topic=self.object).order_by("number")
57         context["programming_exercises"] = ProgrammingExercise.objects.filter(topic=self.object).order_by(
58             "exercise_set_number",
59             "exercise_number"
60         )
61         return context
62 
63 
64 class UnitPlanView(generic.DetailView):
65     """View for a specific unit plan."""
66 
67     model = UnitPlan
68     template_name = "topics/unit-plan.html"
69     context_object_name = "unit_plan"
70 
71     def get_object(self, **kwargs):
72         """Retrieve object for the unit plan view.
73 
74         Returns:
75             UnitPlan object, or raises 404 error if not found.
76         """
77         return get_object_or_404(
78             self.model.objects.select_related(),
79             topic__slug=self.kwargs.get("topic_slug", None),
80             slug=self.kwargs.get("unit_plan_slug", None)
81         )
82 
83     def get_context_data(self, **kwargs):
84         """Provide the context data for the unit plan view.
85 
86         Returns:
87             Dictionary of context data.
88         """
89         # Call the base implementation first to get a context
90         context = super(UnitPlanView, self).get_context_data(**kwargs)
91         # Loading object under consistent context names for breadcrumbs
92         context["topic"] = self.object.topic
93         # Add all the connected lessons
94         context["grouped_lessons"] = group_lessons_by_age(self.object.unit_plan_lessons)
95         return context
96 
97 
98 class LessonView(generic.DetailView):
99     """View for a specific lesson."""
100 
101     model = Lesson
102     template_name = "topics/lesson.html"
103     context_object_name = "lesson"
104 
105     def get_object(self, **kwargs):
106         """Retrieve object for the lesson view.
107 
108         Returns:
109             Lesson object, or raises 404 error if not found.
110         """
111         return get_object_or_404(
112             self.model.objects.select_related(),
113             topic__slug=self.kwargs.get("topic_slug", None),
114             unit_plan__slug=self.kwargs.get("unit_plan_slug", None),
115             slug=self.kwargs.get("lesson_slug", None),
116         )
117 
118     def get_context_data(self, **kwargs):
119         """Provide the context data for the lesson view.
120 
121         Returns:
122             Dictionary of context data.
123         """
124         # Call the base implementation first to get a context
125         context = super(LessonView, self).get_context_data(**kwargs)
126         # Loading objects under consistent context names for breadcrumbs
127         context["topic"] = self.object.topic
128         context["unit_plan"] = self.object.unit_plan
129         # Add all the connected programming exercises
130         context["programming_exercises"] = self.object.programming_exercises.all()
131         # Add all the connected learning outcomes
132         context["lesson_learning_outcomes"] = self.object.learning_outcomes.all().select_related()
133         # Add all the connected generated resources
134         related_resources = self.object.generated_resources.all()
135         generated_resources = []
136         for related_resource in related_resources:
137             generated_resource = dict()
138             generated_resource["slug"] = related_resource.slug
139             generated_resource["name"] = related_resource.name
140             generated_resource["thumbnail"] = related_resource.thumbnail_static_path
141             relationship = ConnectedGeneratedResource.objects.get(resource=related_resource, lesson=self.object)
142             generated_resource["description"] = relationship.description
143             generated_resources.append(generated_resource)
144         context["lesson_generated_resources"] = generated_resources
145 
146         return context
147 
148 
149 class ProgrammingExerciseList(generic.ListView):
150     """View for listing all programming exercises for a lesson."""
151 
152     model = ProgrammingExercise
153     template_name = "topics/programming-exercise-lesson-list.html"
154     context_object_name = "programming_exercises"
155 
156     def get_queryset(self, **kwargs):
157         """Retrieve all programming exercises for a topic.
158 
159         Returns:
160             Queryset of ProgrammingExercise objects.
161         """
162         lesson_slug = self.kwargs.get("lesson_slug", None)
163         exercises = ProgrammingExercise.objects.filter(lessons__slug=lesson_slug)
164         return exercises.order_by("exercise_set_number", "exercise_number")
165 
166     def get_context_data(self, **kwargs):
167         """Provide the context data for the programming exercise list view.
168 
169         Returns:
170             Dictionary of context data.
171         """
172         context = super(ProgrammingExerciseList, self).get_context_data(**kwargs)
173         lesson = get_object_or_404(
174             Lesson.objects.select_related(),
175             topic__slug=self.kwargs.get("topic_slug", None),
176             unit_plan__slug=self.kwargs.get("unit_plan_slug", None),
177             slug=self.kwargs.get("lesson_slug", None),
178         )
179         context["lesson"] = lesson
180         context["unit_plan"] = lesson.unit_plan
181         context["topic"] = lesson.topic
182         return context
183 
184 
185 class ProgrammingExerciseView(generic.DetailView):
186     """View for a specific programming exercise."""
187 
188     model = ProgrammingExercise
189     template_name = "topics/programming-exercise.html"
190     context_object_name = "programming_exercise"
191 
192     def get_object(self, **kwargs):
193         """Retrieve object for the programming exercise view.
194 
195         Returns:
196             ProgrammingExercise object, or raises 404 error if not found.
197         """
198         return get_object_or_404(
199             self.model.objects.select_related(),
200             topic__slug=self.kwargs.get("topic_slug", None),
201             slug=self.kwargs.get("programming_exercise_slug", None)
202         )
203 
204     def get_context_data(self, **kwargs):
205         """Provide the context data for the programming exercise view.
206 
207         Returns:
208             Dictionary of context data.
209         """
210         # Call the base implementation first to get a context
211         context = super(ProgrammingExerciseView, self).get_context_data(**kwargs)
212         context["lessons"] = self.object.lessons.order_by("number")
213         context["topic"] = self.object.topic
214         # Add all the connected learning outcomes
215         context["programming_exercise_learning_outcomes"] = self.object.learning_outcomes.all()
216         context["implementations"] = self.object.ordered_implementations()
217         return context
218 
219 
220 class ProgrammingExerciseLanguageSolutionView(generic.DetailView):
221     """View for a language implementation for a programming exercise."""
222 
223     model = ProgrammingExerciseLanguageImplementation
224     template_name = "topics/programming-exercise-language-solution.html"
225     context_object_name = "implementation"
226 
227     def get_object(self, **kwargs):
228         """Retrieve object for the language implementation view.
229 
230         Returns:
231             ProgrammingExerciseLanguageImplementation object, or raises 404
232             error if not found.
233         """
234         return get_object_or_404(
235             self.model.objects.select_related(),
236             topic__slug=self.kwargs.get("topic_slug", None),
237             exercise__slug=self.kwargs.get("programming_exercise_slug", None),
238             language__slug=self.kwargs.get("programming_language_slug", None)
239         )
240 
241     def get_context_data(self, **kwargs):
242         """Provide the context data for the language implementation view.
243 
244         Returns:
245             Dictionary of context data.
246         """
247         # Call the base implementation first to get a context
248         context = super(ProgrammingExerciseLanguageSolutionView, self).get_context_data(**kwargs)
249         # Loading object under consistent context names for breadcrumbs
250         context["topic"] = self.object.topic
251         context["programming_exercise"] = self.object.exercise
252         return context
253 
254 
255 class AllCurriculumIntegrationList(generic.ListView):
256     """View for listing all curriculum integrations."""
257 
258     model = CurriculumIntegration
259     template_name = "topics/all-curriculum-integration-list.html"
260     context_object_name = "curriculum_integrations"
261 
262     def get_queryset(self, **kwargs):
263         """Retrieve all curriculum integrations.
264 
265         Returns:
266             Queryset of CurriculumIntegration objects.
267         """
268         return CurriculumIntegration.objects.select_related().order_by("topic__name", "number")
269 
270 
271 class CurriculumIntegrationView(generic.DetailView):
272     """View for a specific curriculum integration."""
273 
274     model = CurriculumIntegration
275     queryset = CurriculumIntegration.objects.all()
276     template_name = "topics/curriculum-integration.html"
277     context_object_name = "integration"
278 
279     def get_object(self, **kwargs):
280         """Retrieve object for the curriculum integration view.
281 
282         Returns:
283             CurriculumIntegration object, or raises 404 error if not found.
284         """
285         return get_object_or_404(
286             self.model.objects.select_related(),
287             topic__slug=self.kwargs.get("topic_slug", None),
288             slug=self.kwargs.get("integration_slug", None)
289         )
290 
291     def get_context_data(self, **kwargs):
292         """Provide the context data for the curriculum integration view.
293 
294         Returns:
295             Dictionary of context data.
296         """
297         # Call the base implementation first to get a context
298         context = super(CurriculumIntegrationView, self).get_context_data(**kwargs)
299         # Loading objects under consistent context names for breadcrumbs
300         context["topic"] = self.object.topic
301         # Add in a QuerySet of all the connected curriculum areas
302         context["integration_curriculum_areas"] = self.object.curriculum_areas.order_by("name")
303         # Add in a QuerySet of all the prerequisite lessons
304         context["prerequisite_lessons"] = self.object.prerequisite_lessons.select_related().order_by(
305             "unit_plan__name",
306             "age_range",
307             "number"
308         )
309         return context
310 
311 
312 class OtherResourcesView(generic.DetailView):
313     """View for detailing other resources for a specific topic."""
314 
315     model = Topic
316     template_name = "topics/topic-other-resources.html"
317     slug_url_kwarg = "topic_slug"
318 
319 
320 class GlossaryList(generic.ListView):
321     """Provide glossary view of all terms."""
322 
323     template_name = "topics/glossary.html"
324     context_object_name = "glossary_terms"
325 
326     def get_queryset(self):
327         """Get queryset of all glossary terms.
328 
329         Returns:
330             Queryset of GlossaryTerm objects ordered by term.
331         """
332         return GlossaryTerm.objects.order_by("term")
333 
334 
335 def glossary_json(request, **kwargs):
336     """Provide JSON data for glossary term.
337 
338     Args:
339         request: The HTTP request.
340 
341     Returns:
342         JSON response is sent containing data for the requested term.
343     """
344     # If term parameter, then return JSON
345     if "term" in request.GET:
346         glossary_slug = request.GET.get("term")
347         glossary_item = get_object_or_404(
348             GlossaryTerm,
349             slug=glossary_slug
350         )
351         data = {
352             "slug": glossary_slug,
353             "term": glossary_item.term,
354             "definition": render_html_with_static(glossary_item.definition)
355         }
356         return JsonResponse(data)
357     else:
358         raise Http404("Term parameter not specified.")
359
```
--- 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/csunplugged/topics/views.py b/csunplugged/topics/views.py
--- a/csunplugged/topics/views.py
+++ b/csunplugged/topics/views.py
@@ -58,6 +58,13 @@
             "exercise_set_number",
             "exercise_number"
         )
+        lessons = self.object.topic_lessons.all()
+        resources = set()
+        for lesson in lessons:
+            lesson_resources = lesson.generated_resources.all()
+            for lesson_resource in lesson_resources:
+                resources.add(lesson_resource)
+        context["resources"] = resources
         return context

{"golden_diff": "diff --git a/csunplugged/topics/views.py b/csunplugged/topics/views.py\n--- a/csunplugged/topics/views.py\n+++ b/csunplugged/topics/views.py\n@@ -58,6 +58,13 @@\n             \"exercise_set_number\",\n             \"exercise_number\"\n         )\n+        lessons = self.object.topic_lessons.all()\n+        resources = set()\n+        for lesson in lessons:\n+            lesson_resources = lesson.generated_resources.all()\n+            for lesson_resource in lesson_resources:\n+                resources.add(lesson_resource)\n+        context[\"resources\"] = resources\n         return context\n", "issue": "Update links in lessons to use generate resources\nItems in the \"CS Unplugged Provided Resources\" still have links pointing at google drive where there are now generated resources available, these links should be updated.\r\nSpotted in Lesson 1 (8-10) of Binary Numbers.\nUpdate binary numbers 8 - 10 lessons\nThis includes adding learning outcomes and updating text.\n", "before_files": [{"content": "\"\"\"Views for the topics application.\"\"\"\n\nfrom django.shortcuts import get_object_or_404\nfrom django.views import generic\nfrom django.http import JsonResponse, Http404\nfrom general.templatetags.render_html_field import render_html_with_static\nfrom utils.group_lessons_by_age import group_lessons_by_age\nfrom .models import (\n    Topic,\n    CurriculumIntegration,\n    UnitPlan,\n    Lesson,\n    ProgrammingExercise,\n    ProgrammingExerciseLanguageImplementation,\n    ConnectedGeneratedResource,\n    GlossaryTerm,\n)\n\n\nclass IndexView(generic.ListView):\n    \"\"\"View for the topics application homepage.\"\"\"\n\n    template_name = \"topics/index.html\"\n    context_object_name = \"all_topics\"\n\n    def get_queryset(self):\n        \"\"\"Get queryset of all topics.\n\n        Returns:\n            Queryset of Topic objects ordered by name.\n        \"\"\"\n        return Topic.objects.order_by(\"name\")\n\n\nclass TopicView(generic.DetailView):\n    \"\"\"View for a specific topic.\"\"\"\n\n    model = Topic\n    template_name = \"topics/topic.html\"\n    slug_url_kwarg = \"topic_slug\"\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the topic view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(TopicView, self).get_context_data(**kwargs)\n        # Add in a QuerySet of all the connected unit plans\n        unit_plans = UnitPlan.objects.filter(topic=self.object).order_by(\"name\").select_related()\n        for unit_plan in unit_plans:\n            unit_plan.grouped_lessons = group_lessons_by_age(unit_plan.unit_plan_lessons)\n        context[\"unit_plans\"] = unit_plans\n        # Add in a QuerySet of all the connected curriculum integrations\n        context[\"curriculum_integrations\"] = CurriculumIntegration.objects.filter(topic=self.object).order_by(\"number\")\n        context[\"programming_exercises\"] = ProgrammingExercise.objects.filter(topic=self.object).order_by(\n            \"exercise_set_number\",\n            \"exercise_number\"\n        )\n        return context\n\n\nclass UnitPlanView(generic.DetailView):\n    \"\"\"View for a specific unit plan.\"\"\"\n\n    model = UnitPlan\n    template_name = \"topics/unit-plan.html\"\n    context_object_name = \"unit_plan\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the unit plan view.\n\n        Returns:\n            UnitPlan object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            slug=self.kwargs.get(\"unit_plan_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the unit plan view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(UnitPlanView, self).get_context_data(**kwargs)\n        # Loading object under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        # Add all the connected lessons\n        context[\"grouped_lessons\"] = group_lessons_by_age(self.object.unit_plan_lessons)\n        return context\n\n\nclass LessonView(generic.DetailView):\n    \"\"\"View for a specific lesson.\"\"\"\n\n    model = Lesson\n    template_name = \"topics/lesson.html\"\n    context_object_name = \"lesson\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the lesson view.\n\n        Returns:\n            Lesson object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            unit_plan__slug=self.kwargs.get(\"unit_plan_slug\", None),\n            slug=self.kwargs.get(\"lesson_slug\", None),\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the lesson view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(LessonView, self).get_context_data(**kwargs)\n        # Loading objects under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        context[\"unit_plan\"] = self.object.unit_plan\n        # Add all the connected programming exercises\n        context[\"programming_exercises\"] = self.object.programming_exercises.all()\n        # Add all the connected learning outcomes\n        context[\"lesson_learning_outcomes\"] = self.object.learning_outcomes.all().select_related()\n        # Add all the connected generated resources\n        related_resources = self.object.generated_resources.all()\n        generated_resources = []\n        for related_resource in related_resources:\n            generated_resource = dict()\n            generated_resource[\"slug\"] = related_resource.slug\n            generated_resource[\"name\"] = related_resource.name\n            generated_resource[\"thumbnail\"] = related_resource.thumbnail_static_path\n            relationship = ConnectedGeneratedResource.objects.get(resource=related_resource, lesson=self.object)\n            generated_resource[\"description\"] = relationship.description\n            generated_resources.append(generated_resource)\n        context[\"lesson_generated_resources\"] = generated_resources\n\n        return context\n\n\nclass ProgrammingExerciseList(generic.ListView):\n    \"\"\"View for listing all programming exercises for a lesson.\"\"\"\n\n    model = ProgrammingExercise\n    template_name = \"topics/programming-exercise-lesson-list.html\"\n    context_object_name = \"programming_exercises\"\n\n    def get_queryset(self, **kwargs):\n        \"\"\"Retrieve all programming exercises for a topic.\n\n        Returns:\n            Queryset of ProgrammingExercise objects.\n        \"\"\"\n        lesson_slug = self.kwargs.get(\"lesson_slug\", None)\n        exercises = ProgrammingExercise.objects.filter(lessons__slug=lesson_slug)\n        return exercises.order_by(\"exercise_set_number\", \"exercise_number\")\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the programming exercise list view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        context = super(ProgrammingExerciseList, self).get_context_data(**kwargs)\n        lesson = get_object_or_404(\n            Lesson.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            unit_plan__slug=self.kwargs.get(\"unit_plan_slug\", None),\n            slug=self.kwargs.get(\"lesson_slug\", None),\n        )\n        context[\"lesson\"] = lesson\n        context[\"unit_plan\"] = lesson.unit_plan\n        context[\"topic\"] = lesson.topic\n        return context\n\n\nclass ProgrammingExerciseView(generic.DetailView):\n    \"\"\"View for a specific programming exercise.\"\"\"\n\n    model = ProgrammingExercise\n    template_name = \"topics/programming-exercise.html\"\n    context_object_name = \"programming_exercise\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the programming exercise view.\n\n        Returns:\n            ProgrammingExercise object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            slug=self.kwargs.get(\"programming_exercise_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the programming exercise view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(ProgrammingExerciseView, self).get_context_data(**kwargs)\n        context[\"lessons\"] = self.object.lessons.order_by(\"number\")\n        context[\"topic\"] = self.object.topic\n        # Add all the connected learning outcomes\n        context[\"programming_exercise_learning_outcomes\"] = self.object.learning_outcomes.all()\n        context[\"implementations\"] = self.object.ordered_implementations()\n        return context\n\n\nclass ProgrammingExerciseLanguageSolutionView(generic.DetailView):\n    \"\"\"View for a language implementation for a programming exercise.\"\"\"\n\n    model = ProgrammingExerciseLanguageImplementation\n    template_name = \"topics/programming-exercise-language-solution.html\"\n    context_object_name = \"implementation\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the language implementation view.\n\n        Returns:\n            ProgrammingExerciseLanguageImplementation object, or raises 404\n            error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            exercise__slug=self.kwargs.get(\"programming_exercise_slug\", None),\n            language__slug=self.kwargs.get(\"programming_language_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the language implementation view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(ProgrammingExerciseLanguageSolutionView, self).get_context_data(**kwargs)\n        # Loading object under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        context[\"programming_exercise\"] = self.object.exercise\n        return context\n\n\nclass AllCurriculumIntegrationList(generic.ListView):\n    \"\"\"View for listing all curriculum integrations.\"\"\"\n\n    model = CurriculumIntegration\n    template_name = \"topics/all-curriculum-integration-list.html\"\n    context_object_name = \"curriculum_integrations\"\n\n    def get_queryset(self, **kwargs):\n        \"\"\"Retrieve all curriculum integrations.\n\n        Returns:\n            Queryset of CurriculumIntegration objects.\n        \"\"\"\n        return CurriculumIntegration.objects.select_related().order_by(\"topic__name\", \"number\")\n\n\nclass CurriculumIntegrationView(generic.DetailView):\n    \"\"\"View for a specific curriculum integration.\"\"\"\n\n    model = CurriculumIntegration\n    queryset = CurriculumIntegration.objects.all()\n    template_name = \"topics/curriculum-integration.html\"\n    context_object_name = \"integration\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the curriculum integration view.\n\n        Returns:\n            CurriculumIntegration object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            slug=self.kwargs.get(\"integration_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the curriculum integration view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(CurriculumIntegrationView, self).get_context_data(**kwargs)\n        # Loading objects under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        # Add in a QuerySet of all the connected curriculum areas\n        context[\"integration_curriculum_areas\"] = self.object.curriculum_areas.order_by(\"name\")\n        # Add in a QuerySet of all the prerequisite lessons\n        context[\"prerequisite_lessons\"] = self.object.prerequisite_lessons.select_related().order_by(\n            \"unit_plan__name\",\n            \"age_range\",\n            \"number\"\n        )\n        return context\n\n\nclass OtherResourcesView(generic.DetailView):\n    \"\"\"View for detailing other resources for a specific topic.\"\"\"\n\n    model = Topic\n    template_name = \"topics/topic-other-resources.html\"\n    slug_url_kwarg = \"topic_slug\"\n\n\nclass GlossaryList(generic.ListView):\n    \"\"\"Provide glossary view of all terms.\"\"\"\n\n    template_name = \"topics/glossary.html\"\n    context_object_name = \"glossary_terms\"\n\n    def get_queryset(self):\n        \"\"\"Get queryset of all glossary terms.\n\n        Returns:\n            Queryset of GlossaryTerm objects ordered by term.\n        \"\"\"\n        return GlossaryTerm.objects.order_by(\"term\")\n\n\ndef glossary_json(request, **kwargs):\n    \"\"\"Provide JSON data for glossary term.\n\n    Args:\n        request: The HTTP request.\n\n    Returns:\n        JSON response is sent containing data for the requested term.\n    \"\"\"\n    # If term parameter, then return JSON\n    if \"term\" in request.GET:\n        glossary_slug = request.GET.get(\"term\")\n        glossary_item = get_object_or_404(\n            GlossaryTerm,\n            slug=glossary_slug\n        )\n        data = {\n            \"slug\": glossary_slug,\n            \"term\": glossary_item.term,\n            \"definition\": render_html_with_static(glossary_item.definition)\n        }\n        return JsonResponse(data)\n    else:\n        raise Http404(\"Term parameter not specified.\")\n", "path": "csunplugged/topics/views.py"}], "after_files": [{"content": "\"\"\"Views for the topics application.\"\"\"\n\nfrom django.shortcuts import get_object_or_404\nfrom django.views import generic\nfrom django.http import JsonResponse, Http404\nfrom general.templatetags.render_html_field import render_html_with_static\nfrom utils.group_lessons_by_age import group_lessons_by_age\nfrom .models import (\n    Topic,\n    CurriculumIntegration,\n    UnitPlan,\n    Lesson,\n    ProgrammingExercise,\n    ProgrammingExerciseLanguageImplementation,\n    ConnectedGeneratedResource,\n    GlossaryTerm,\n)\n\n\nclass IndexView(generic.ListView):\n    \"\"\"View for the topics application homepage.\"\"\"\n\n    template_name = \"topics/index.html\"\n    context_object_name = \"all_topics\"\n\n    def get_queryset(self):\n        \"\"\"Get queryset of all topics.\n\n        Returns:\n            Queryset of Topic objects ordered by name.\n        \"\"\"\n        return Topic.objects.order_by(\"name\")\n\n\nclass TopicView(generic.DetailView):\n    \"\"\"View for a specific topic.\"\"\"\n\n    model = Topic\n    template_name = \"topics/topic.html\"\n    slug_url_kwarg = \"topic_slug\"\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the topic view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(TopicView, self).get_context_data(**kwargs)\n        # Add in a QuerySet of all the connected unit plans\n        unit_plans = UnitPlan.objects.filter(topic=self.object).order_by(\"name\").select_related()\n        for unit_plan in unit_plans:\n            unit_plan.grouped_lessons = group_lessons_by_age(unit_plan.unit_plan_lessons)\n        context[\"unit_plans\"] = unit_plans\n        # Add in a QuerySet of all the connected curriculum integrations\n        context[\"curriculum_integrations\"] = CurriculumIntegration.objects.filter(topic=self.object).order_by(\"number\")\n        context[\"programming_exercises\"] = ProgrammingExercise.objects.filter(topic=self.object).order_by(\n            \"exercise_set_number\",\n            \"exercise_number\"\n        )\n        lessons = self.object.topic_lessons.all()\n        resources = set()\n        for lesson in lessons:\n            lesson_resources = lesson.generated_resources.all()\n            for lesson_resource in lesson_resources:\n                resources.add(lesson_resource)\n        context[\"resources\"] = resources\n        return context\n\n\nclass UnitPlanView(generic.DetailView):\n    \"\"\"View for a specific unit plan.\"\"\"\n\n    model = UnitPlan\n    template_name = \"topics/unit-plan.html\"\n    context_object_name = \"unit_plan\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the unit plan view.\n\n        Returns:\n            UnitPlan object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            slug=self.kwargs.get(\"unit_plan_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the unit plan view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(UnitPlanView, self).get_context_data(**kwargs)\n        # Loading object under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        # Add all the connected lessons\n        context[\"grouped_lessons\"] = group_lessons_by_age(self.object.unit_plan_lessons)\n        return context\n\n\nclass LessonView(generic.DetailView):\n    \"\"\"View for a specific lesson.\"\"\"\n\n    model = Lesson\n    template_name = \"topics/lesson.html\"\n    context_object_name = \"lesson\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the lesson view.\n\n        Returns:\n            Lesson object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            unit_plan__slug=self.kwargs.get(\"unit_plan_slug\", None),\n            slug=self.kwargs.get(\"lesson_slug\", None),\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the lesson view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(LessonView, self).get_context_data(**kwargs)\n        # Loading objects under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        context[\"unit_plan\"] = self.object.unit_plan\n        # Add all the connected programming exercises\n        context[\"programming_exercises\"] = self.object.programming_exercises.all()\n        # Add all the connected learning outcomes\n        context[\"lesson_learning_outcomes\"] = self.object.learning_outcomes.all().select_related()\n        # Add all the connected generated resources\n        related_resources = self.object.generated_resources.all()\n        generated_resources = []\n        for related_resource in related_resources:\n            generated_resource = dict()\n            generated_resource[\"slug\"] = related_resource.slug\n            generated_resource[\"name\"] = related_resource.name\n            generated_resource[\"thumbnail\"] = related_resource.thumbnail_static_path\n            relationship = ConnectedGeneratedResource.objects.get(resource=related_resource, lesson=self.object)\n            generated_resource[\"description\"] = relationship.description\n            generated_resources.append(generated_resource)\n        context[\"lesson_generated_resources\"] = generated_resources\n\n        return context\n\n\nclass ProgrammingExerciseList(generic.ListView):\n    \"\"\"View for listing all programming exercises for a lesson.\"\"\"\n\n    model = ProgrammingExercise\n    template_name = \"topics/programming-exercise-lesson-list.html\"\n    context_object_name = \"programming_exercises\"\n\n    def get_queryset(self, **kwargs):\n        \"\"\"Retrieve all programming exercises for a topic.\n\n        Returns:\n            Queryset of ProgrammingExercise objects.\n        \"\"\"\n        lesson_slug = self.kwargs.get(\"lesson_slug\", None)\n        exercises = ProgrammingExercise.objects.filter(lessons__slug=lesson_slug)\n        return exercises.order_by(\"exercise_set_number\", \"exercise_number\")\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the programming exercise list view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        context = super(ProgrammingExerciseList, self).get_context_data(**kwargs)\n        lesson = get_object_or_404(\n            Lesson.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            unit_plan__slug=self.kwargs.get(\"unit_plan_slug\", None),\n            slug=self.kwargs.get(\"lesson_slug\", None),\n        )\n        context[\"lesson\"] = lesson\n        context[\"unit_plan\"] = lesson.unit_plan\n        context[\"topic\"] = lesson.topic\n        return context\n\n\nclass ProgrammingExerciseView(generic.DetailView):\n    \"\"\"View for a specific programming exercise.\"\"\"\n\n    model = ProgrammingExercise\n    template_name = \"topics/programming-exercise.html\"\n    context_object_name = \"programming_exercise\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the programming exercise view.\n\n        Returns:\n            ProgrammingExercise object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            slug=self.kwargs.get(\"programming_exercise_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the programming exercise view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(ProgrammingExerciseView, self).get_context_data(**kwargs)\n        context[\"lessons\"] = self.object.lessons.order_by(\"number\")\n        context[\"topic\"] = self.object.topic\n        # Add all the connected learning outcomes\n        context[\"programming_exercise_learning_outcomes\"] = self.object.learning_outcomes.all()\n        context[\"implementations\"] = self.object.ordered_implementations()\n        return context\n\n\nclass ProgrammingExerciseLanguageSolutionView(generic.DetailView):\n    \"\"\"View for a language implementation for a programming exercise.\"\"\"\n\n    model = ProgrammingExerciseLanguageImplementation\n    template_name = \"topics/programming-exercise-language-solution.html\"\n    context_object_name = \"implementation\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the language implementation view.\n\n        Returns:\n            ProgrammingExerciseLanguageImplementation object, or raises 404\n            error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            exercise__slug=self.kwargs.get(\"programming_exercise_slug\", None),\n            language__slug=self.kwargs.get(\"programming_language_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the language implementation view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(ProgrammingExerciseLanguageSolutionView, self).get_context_data(**kwargs)\n        # Loading object under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        context[\"programming_exercise\"] = self.object.exercise\n        return context\n\n\nclass AllCurriculumIntegrationList(generic.ListView):\n    \"\"\"View for listing all curriculum integrations.\"\"\"\n\n    model = CurriculumIntegration\n    template_name = \"topics/all-curriculum-integration-list.html\"\n    context_object_name = \"curriculum_integrations\"\n\n    def get_queryset(self, **kwargs):\n        \"\"\"Retrieve all curriculum integrations.\n\n        Returns:\n            Queryset of CurriculumIntegration objects.\n        \"\"\"\n        return CurriculumIntegration.objects.select_related().order_by(\"topic__name\", \"number\")\n\n\nclass CurriculumIntegrationView(generic.DetailView):\n    \"\"\"View for a specific curriculum integration.\"\"\"\n\n    model = CurriculumIntegration\n    queryset = CurriculumIntegration.objects.all()\n    template_name = \"topics/curriculum-integration.html\"\n    context_object_name = \"integration\"\n\n    def get_object(self, **kwargs):\n        \"\"\"Retrieve object for the curriculum integration view.\n\n        Returns:\n            CurriculumIntegration object, or raises 404 error if not found.\n        \"\"\"\n        return get_object_or_404(\n            self.model.objects.select_related(),\n            topic__slug=self.kwargs.get(\"topic_slug\", None),\n            slug=self.kwargs.get(\"integration_slug\", None)\n        )\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Provide the context data for the curriculum integration view.\n\n        Returns:\n            Dictionary of context data.\n        \"\"\"\n        # Call the base implementation first to get a context\n        context = super(CurriculumIntegrationView, self).get_context_data(**kwargs)\n        # Loading objects under consistent context names for breadcrumbs\n        context[\"topic\"] = self.object.topic\n        # Add in a QuerySet of all the connected curriculum areas\n        context[\"integration_curriculum_areas\"] = self.object.curriculum_areas.order_by(\"name\")\n        # Add in a QuerySet of all the prerequisite lessons\n        context[\"prerequisite_lessons\"] = self.object.prerequisite_lessons.select_related().order_by(\n            \"unit_plan__name\",\n            \"age_range\",\n            \"number\"\n        )\n        return context\n\n\nclass OtherResourcesView(generic.DetailView):\n    \"\"\"View for detailing other resources for a specific topic.\"\"\"\n\n    model = Topic\n    template_name = \"topics/topic-other-resources.html\"\n    slug_url_kwarg = \"topic_slug\"\n\n\nclass GlossaryList(generic.ListView):\n    \"\"\"Provide glossary view of all terms.\"\"\"\n\n    template_name = \"topics/glossary.html\"\n    context_object_name = \"glossary_terms\"\n\n    def get_queryset(self):\n        \"\"\"Get queryset of all glossary terms.\n\n        Returns:\n            Queryset of GlossaryTerm objects ordered by term.\n        \"\"\"\n        return GlossaryTerm.objects.order_by(\"term\")\n\n\ndef glossary_json(request, **kwargs):\n    \"\"\"Provide JSON data for glossary term.\n\n    Args:\n        request: The HTTP request.\n\n    Returns:\n        JSON response is sent containing data for the requested term.\n    \"\"\"\n    # If term parameter, then return JSON\n    if \"term\" in request.GET:\n        glossary_slug = request.GET.get(\"term\")\n        glossary_item = get_object_or_404(\n            GlossaryTerm,\n            slug=glossary_slug\n        )\n        data = {\n            \"slug\": glossary_slug,\n            \"term\": glossary_item.term,\n            \"definition\": render_html_with_static(glossary_item.definition)\n        }\n        return JsonResponse(data)\n    else:\n        raise Http404(\"Term parameter not specified.\")\n", "path": "csunplugged/topics/views.py"}]}