Skip to content

page_views

main.views.page_views ¤

Views for the page-related pages of the main app.

Classes¤

AboutPageView ¤

Bases: TemplateView

View that renders the about page.

EventsPageView ¤

Bases: TemplateView

View that renders the events page.

Methods:¤
get_context_data(**kwargs) ¤

Add events from CSV to the template context.

Source code in main/views/page_views.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add events from CSV to the template context."""
    context = super().get_context_data(**kwargs)
    csv_path = Path("data/events.csv")
    events = []

    if csv_path.exists():
        with open(csv_path, newline="", encoding="utf-8") as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                events.append(
                    {
                        "title": row.get("Title", ""),
                        "start_date": row.get("Start Date", ""),
                        "end_date": row.get("End Date", ""),
                        "description": row.get("Description", ""),
                        "contributors": row.get("Contributors", ""),
                        "image": static(
                            row.get("Image", "assets/img/blog/single/image.jpg")
                        ),
                    }
                )

    events.sort(key=lambda e: e["start_date"], reverse=True)

    context["events"] = events
    return context

FrameworkOverviewPageView ¤

Bases: TemplateView

View that renders an overview page for the framework.

GetInvolvedPageView ¤

Bases: TemplateView

View that renders the get involved page.

GitHubMarkdownPageView ¤

Bases: TemplateView

Base view for pages that render markdown content fetched from GitHub.

Methods:¤
get_context_data(**kwargs) ¤

Add rendered markdown content and page metadata to the context.

Source code in main/views/page_views.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add rendered markdown content and page metadata to the context."""
    context = super().get_context_data(**kwargs)
    context["page_heading"] = self.page_heading

    try:
        context["markdown_content"] = mark_safe(
            nh3.clean(self.get_markdown_content())
        )
    except requests.RequestException:
        logger.exception("Failed to load markdown from %s", self.github_raw_url)
        context["markdown_content"] = mark_safe(
            f"<p>{self.unavailable_message}</p>"
        )

    return context
get_markdown_content() ¤

Fetch and convert remote markdown content to HTML.

Source code in main/views/page_views.py
266
267
268
269
270
271
272
273
274
275
276
277
def get_markdown_content(self) -> str:
    """Fetch and convert remote markdown content to HTML."""
    if not self.github_raw_url:
        raise ValueError("github_raw_url must be set on GitHubMarkdownPageView")

    response = requests.get(self.github_raw_url, timeout=5)
    response.raise_for_status()
    markdown_text = self._strip_duplicate_heading(response.text)
    return markdown.markdown(
        markdown_text,
        extensions=self.markdown_extensions,
    )

GovernancePageView ¤

Bases: GitHubMarkdownPageView

View that renders the governance page from GitHub Markdown.

IndexPageView ¤

Bases: TemplateView

View that renders the index/home page.

Methods:¤
get_context_data(**kwargs) ¤

Add skill levels and sample profile data to the template context.

Source code in main/views/page_views.py
56
57
58
59
60
61
62
63
64
65
66
67
68
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add skill levels and sample profile data to the template context."""
    context = super().get_context_data(**kwargs)
    logger.info("Rendering index page.")

    sample_data = _extract_and_combine_roles(
        ["main/static/assets/sample_data/sample_profile_1.json"]
    )
    context["chart_data"] = dumps(sample_data)
    context["skill_levels"] = dumps(
        list(SkillLevel.objects.values("level", "name"))
    )
    return context

LearningResourcesPageView ¤

Bases: SingleTableView

View that renders the page with all learning resources.

LicensingPageView ¤

Bases: GitHubMarkdownPageView

View that renders the licensing page from GitHub Markdown.

PrivacyPageView ¤

Bases: TemplateView

View that renders the privacy page.

RolesPageView ¤

Bases: TemplateView

View that renders the role profiles page.

Methods:¤
get_context_data(**kwargs) ¤

Add sample profile data to the template context.

Source code in main/views/page_views.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add sample profile data to the template context."""
    context = super().get_context_data(**kwargs)

    sample_data = _extract_and_combine_roles(
        [
            "main/static/assets/sample_data/sample_profile_1.json",
            "main/static/assets/sample_data/sample_profile_41.json",
            "main/static/assets/sample_data/sample_profile_59.json",
        ]
    )
    context["chart_data"] = sample_data
    context["skill_levels"] = dumps(
        list(SkillLevel.objects.values("level", "name"))
    )
    return context

SkillLevelsPageView ¤

Bases: TemplateView

View that renders the skill levels page.

Methods:¤
get_context_data(**kwargs) ¤

Add skill levels to the template context.

Source code in main/views/page_views.py
94
95
96
97
98
99
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add skill levels to the template context."""
    context = super().get_context_data(**kwargs)
    skill_levels = SkillLevel.objects.all().order_by("level")
    context["skill_levels"] = skill_levels
    return context

SkillPageView ¤

Bases: TemplateView

View that renders a single skill page.

Methods:¤
get_context_data(**kwargs) ¤

Add the selected skill and related data to the template context.

Source code in main/views/page_views.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add the selected skill and related data to the template context."""
    context = super().get_context_data(**kwargs)

    slug = self.kwargs["slug"]
    skill = get_object_or_404(
        Skill.objects.select_related(
            "competency",
            "competency__competency_domain",
        ).prefetch_related(
            "related_skills",
            "learning_resources__provider",
            "tools",
        ),
        slug=slug,
    )

    tools_qs = skill.tools.all().order_by("name")
    context["skill"] = skill
    context["related_skills"] = skill.related_skills.all().order_by("name")
    context["learning_resources"] = skill.learning_resources.all().order_by("name")
    context["tools"] = tools_qs.filter(kind=ToolLanguageMethodology.Kind.TOOL)
    context["languages"] = tools_qs.filter(
        kind=ToolLanguageMethodology.Kind.LANGUAGE
    )
    context["methodologies"] = tools_qs.filter(
        kind=ToolLanguageMethodology.Kind.METHODOLOGY
    )

    return context

SkillsAndCompetenciesPageView ¤

Bases: TemplateView

View that renders the competencies page.

Methods:¤
get_context_data(**kwargs) ¤

Add the competencies framework data to the template context.

Source code in main/views/page_views.py
186
187
188
189
190
191
192
193
194
195
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add the competencies framework data to the template context."""
    context = super().get_context_data(**kwargs)

    domains = CompetencyDomain.objects.prefetch_related(
        "competency_set__skill_set"
    ).all()

    context["domains"] = domains
    return context

TermsPageView ¤

Bases: TemplateView

View that renders the terms and conditions page.

ToolsLanguagesMethodologiesPageView ¤

Bases: SingleTableView

View that renders the page with all tools, languages and methodologies.

ViewSkillProfilePageView ¤

Bases: TemplateView

View that renders a shared skill profile based on query parameters.

Methods:¤
get_context_data(**kwargs) ¤

Add skill profile data from query parameters to the context.

Source code in main/views/page_views.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
def get_context_data(self, **kwargs: Mapping[str, Any]) -> dict[str, Any]:
    """Add skill profile data from query parameters to the context."""
    context = super().get_context_data(**kwargs)

    chart_data_json = nh3.clean(self.request.GET.get("chart_data", "[]"))
    skill_levels_json = nh3.clean(self.request.GET.get("skill_levels", "[]"))

    try:
        context["chart_data"] = json.loads(chart_data_json)
        context["skill_levels"] = json.loads(skill_levels_json)
    except json.JSONDecodeError:
        context["chart_data"] = []
        context["skill_levels"] = []
        context["error_message"] = "Invalid data provided in query parameters."

    return context