Skip to content

Commit

Permalink
Issue webcompat#3380 - simplifies PrefixedRadioField
Browse files Browse the repository at this point in the history
This optimizes a bit the code to make it easier to read. It doesn't change the global logic
  • Loading branch information
karlcow committed Jul 14, 2020
1 parent 23f2665 commit 09853fb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions webcompat/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,20 @@


class PrefixedRadioField(RadioField):
"""Prefix radio field label with an image."""
"""Prefix radio field label with an image.
This renders the radio elements with a specific html markup.
"""
def __init__(self, *args, **kwargs):
prefixed_choices = kwargs.pop('choices')
template = '<div class={css_class}><img src={src}/></div> {text}'
choices = []

css_class = 'icon-container'
for slug, img, text in prefixed_choices:
filename = 'img/svg/icons/{img}'.format(img=img)
filename = f'img/svg/icons/{img}'
src = url_for('static', filename=filename)
label = Markup(template.format(
src=src, css_class=css_class, text=text)
)
t = f'<div class="icon-container"><img src="{src}"/></div> {text}'
label = Markup(t)
choice = (slug, label)
choices.append(choice)

kwargs['choices'] = choices
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit 09853fb

Please sign in to comment.