Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: remove icon/media item view models #1542

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions benefits/core/templates/core/includes/icon--direct-args.html

This file was deleted.

5 changes: 0 additions & 5 deletions benefits/core/templates/core/includes/icon-title.html

This file was deleted.

10 changes: 5 additions & 5 deletions benefits/core/templates/core/includes/icon.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

{% if not icon.src %}
{% if not name %}
<p class="bg-grey-lightest color-standout">
Missing <strong><code>icon.src</code></strong> argument
Missing <strong><code>name</code></strong> argument
</p>
{% elif not icon.alt %}
{% elif not alt %}
<p class="bg-grey-lightest color-standout">
Missing <strong><code>icon.alt</code></strong> argument
Missing <strong><code>alt</code></strong> argument
</p>
{% else %}
{% load static %}
<img class="icon" width="150" height="150" src="{% static icon.src %}" alt="{{ icon.alt }}" />
<img class="icon" width="150" height="150" src="{% get_static_prefix %}img/icon/{{ name }}.svg" alt="{{ alt }}" />
{% endif %}
15 changes: 0 additions & 15 deletions benefits/core/templates/core/includes/media-list.html

This file was deleted.

17 changes: 9 additions & 8 deletions benefits/core/templates/core/logged-out.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
{% load i18n %}

{% block main-content %}
<div class="container">
<div class="row justify-content-lg-center">
<h1 class="pb-lg-8 pb-5">
<span class="h2 d-block d-lg-inline mb-4">{% translate "core.pages.logged_out.headline[0]" %}</span>
<span class="h2">{% translate "core.pages.logged_out.headline[1]" %}</span>
</h1>
{% include "core/includes/icon.html" with icon=page.icon %}
</div>
<div class="container">
<div class="row justify-content-lg-center">
<h1 class="pb-lg-8 pb-5">
<span class="h2 d-block d-lg-inline mb-4">{% translate "core.pages.logged_out.headline[0]" %}</span>
<span class="h2">{% translate "core.pages.logged_out.headline[1]" %}</span>
</h1>
{% translate "core.icons.happybus" context "image alt text" as alt_i18n %}
{% include "core/includes/icon.html" with name="happybus" alt=alt_i18n %}
</div>
</div>
{% endblock main-content %}
27 changes: 0 additions & 27 deletions benefits/core/viewmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,6 @@ def previous_page(url):
return Button(text=_("core.buttons.previous_page"), url=url)


class Icon:
"""Represents an icon."""

def __init__(self, icon, alt):
self.src = f"img/icon/{icon}.svg"
self.alt = alt


class MediaItem:
"""
Represents a media item in a list of items:
* icon: core.viewmodels.Icon
* details: str, str[]
* heading: str
"""

def __init__(self, icon: Icon, details, heading=None):
self.icon = icon
if isinstance(details, str):
self.details = [details]
elif isinstance(details, list):
self.details = details
else:
self.details = [str(details)]
self.heading = heading


class Page:
"""
Represents a page of content:
Expand Down
8 changes: 2 additions & 6 deletions benefits/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.template import loader
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.translation import pgettext, gettext as _
from django.utils.translation import gettext as _

from . import session, viewmodels
from .middleware import pageview_decorator, index_or_agencyindex_origin_decorator
Expand Down Expand Up @@ -115,9 +115,5 @@ def server_error(request, template_name=TEMPLATE_SERVER_ERROR):

def logged_out(request):
"""View handler for the final log out confirmation message."""
page = viewmodels.Page(
title=_("core.pages.logged_out.title"),
icon=viewmodels.Icon("happybus", pgettext("image alt text", "core.icons.happybus")),
)

page = viewmodels.Page(title=_("core.pages.logged_out.title"))
return TemplateResponse(request, TEMPLATE_LOGGED_OUT, page.context_dict())
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block icon %}
{% translate "core.icons.bankcardcheck" context "image alt text" as icon_alt %}
{% include "core/includes/icon--direct-args.html" with name="bankcardcheck" alt=icon_alt %}
{% include "core/includes/icon.html" with name="bankcardcheck" alt=icon_alt %}
{% endblock icon %}

{% block heading %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

{% block icon %}
{% translate "core.icons.idcardcheck" context "image alt text" as icon_alt %}
{% include "core/includes/icon--direct-args.html" with name="idcardcheck" alt=icon_alt %}
{% include "core/includes/icon.html" with name="idcardcheck" alt=icon_alt %}
{% endblock icon %}
9 changes: 7 additions & 2 deletions benefits/eligibility/templates/eligibility/unverified.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
{% endif %}

<div class="container">
{% translate "eligibility.pages.unverified.headline" as headline %}
{% include "core/includes/icon-title.html" with title=headline icon=page.icon %}
<h1 class="h2 text-center">
<span class="icon d-block pb-5">
{% translate "core.icons.idcardquestion" context "image alt text" as alt_i18n %}
{% include "core/includes/icon.html" with name="idcardquestion" alt=alt_i18n %}
</span>
{% translate "eligibility.pages.unverified.headline" %}
</h1>

<div class="row justify-content-center">
<div class="col-lg-8 pt-4">
Expand Down
9 changes: 2 additions & 7 deletions benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.decorators import decorator_from_middleware
from django.utils.translation import pgettext, gettext as _
from django.utils.translation import gettext as _

from benefits.core import recaptcha, session, viewmodels
from benefits.core.middleware import AgencySessionRequired, LoginRequired, RecaptchaEnabled, VerifierSessionRequired
Expand Down Expand Up @@ -180,9 +180,4 @@ def unverified(request):

analytics.returned_fail(request, types_to_verify)

page = viewmodels.Page(
icon=viewmodels.Icon("idcardquestion", pgettext("image alt text", "core.icons.idcardquestion")),
)

ctx = page.context_dict()
return TemplateResponse(request, TEMPLATE_UNVERIFIED, ctx)
return TemplateResponse(request, TEMPLATE_UNVERIFIED)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block icon %}
{% translate "core.icons.bankcardcheck" context "image alt text" as icon_alt %}
{% include "core/includes/icon--direct-args.html" with name="bankcardcheck" alt=icon_alt %}
{% include "core/includes/icon.html" with name="bankcardcheck" alt=icon_alt %}
{% endblock icon %}

{% block heading %}
Expand Down
7 changes: 6 additions & 1 deletion benefits/enrollment/templates/enrollment/retry.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{% extends "core/base.html" %}
{% load i18n %}

{% block main-content %}
{% if authentication and authentication.sign_out_link_template %}
{% include authentication.sign_out_link_template %}
{% endif %}

<div class="container">
{% include "core/includes/icon-title.html" with title=page.headline icon=page.icon %}
<h1 class="h2 text-center">
{% translate "core.icons.bankcardquestion" context "image alt text" as alt_i18n %}
<span class="icon d-block pb-5">{% include "core/includes/icon.html" with name="bankcardquestion" alt=alt_i18n %}</span>
{% translate "enrollment.pages.retry.title" %}
</h1>

<div class="row justify-content-center">
<div class="col-lg-8 pt-4">
Expand Down
3 changes: 1 addition & 2 deletions benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.decorators import decorator_from_middleware
from django.utils.translation import pgettext, gettext as _
from django.utils.translation import gettext as _

from benefits.core import models, session, viewmodels
from benefits.core.middleware import EligibleSessionRequired, VerifierSessionRequired, pageview_decorator
Expand Down Expand Up @@ -98,7 +98,6 @@ def retry(request):
if form.is_valid():
page = viewmodels.Page(
title=_("enrollment.pages.retry.title"),
icon=viewmodels.Icon("bankcardquestion", pgettext("image alt text", "core.icons.bankcardquestion")),
headline=_("enrollment.pages.retry.title"),
paragraphs=[_("enrollment.pages.retry.p[0]")],
)
Expand Down
4 changes: 2 additions & 2 deletions benefits/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<div class="container">
<h1 class="icon-title h2 text-center">
<span class="icon d-block pb-5">
{% translate "core.icons.sadbus" as alt_i18n %}
{% include "core/includes/icon--direct-args.html" with name="sadbus" alt=alt_i18n %}
{% translate "core.icons.sadbus" context "image alt text" as alt_i18n %}
{% include "core/includes/icon.html" with name="sadbus" alt=alt_i18n %}
</span>
{% block headline %}
{% endblock headline %}
Expand Down