From 9b9acfa291cdd02e77a8dc145b00e1c025c15bd9 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 23 Aug 2018 09:14:01 +0100 Subject: [PATCH] Select a branding with a link, not form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selecting a branding just takes you to a new page, it doesn’t change any state. Links are generally the way you go from one page to another on the web. --- app/main/forms.py | 14 ------------- app/main/views/email_branding.py | 15 ++----------- .../views/email-branding/select-branding.html | 21 +++++++++---------- tests/app/main/views/test_email_branding.py | 14 +++++++++---- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index fbc856b3b..b8d769a4a 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -713,20 +713,6 @@ class ServicePreviewBranding(StripWhitespaceForm): branding_style = HiddenField('branding_style') -class ServiceSelectEmailBranding(StripWhitespaceForm): - - def __init__(self, email_brandings=[], *args, **kwargs): - self.email_branding.choices = email_brandings - super(ServiceSelectEmailBranding, self).__init__(*args, **kwargs) - - email_branding = RadioField( - 'Email branding', - validators=[ - DataRequired() - ] - ) - - class ServiceUpdateEmailBranding(StripWhitespaceForm): name = StringField('Name of brand') diff --git a/app/main/views/email_branding.py b/app/main/views/email_branding.py index c6a3611d2..819a61ac7 100644 --- a/app/main/views/email_branding.py +++ b/app/main/views/email_branding.py @@ -3,11 +3,7 @@ from flask_login import login_required from app import email_branding_client from app.main import main -from app.main.forms import ( - SearchTemplatesForm, - ServiceSelectEmailBranding, - ServiceUpdateEmailBranding, -) +from app.main.forms import SearchTemplatesForm, ServiceUpdateEmailBranding from app.main.s3_client import ( TEMP_TAG, delete_temp_file, @@ -25,16 +21,9 @@ from app.utils import get_cdn_domain, user_is_platform_admin def email_branding(): brandings = email_branding_client.get_all_email_branding(sort_key='name') - form = ServiceSelectEmailBranding() - email_brandings = get_branding_as_value_and_label(brandings) - form.email_branding.choices = email_brandings - - if form.validate_on_submit(): - return redirect(url_for('.update_email_branding', branding_id=form.email_branding.data)) - return render_template( 'views/email-branding/select-branding.html', - form=form, + email_brandings=get_branding_as_value_and_label(brandings), search_form=SearchTemplatesForm(), show_search_box=len(brandings) > 9, ) diff --git a/app/templates/views/email-branding/select-branding.html b/app/templates/views/email-branding/select-branding.html index 16324b893..6fa134f57 100644 --- a/app/templates/views/email-branding/select-branding.html +++ b/app/templates/views/email-branding/select-branding.html @@ -17,16 +17,15 @@ Add new brand -
-
-
- {{ live_search(target_selector='.multiple-choice', show=show_search_box, form=search_form) }} - {{ radios(form.email_branding) }} - {{ page_footer( - 'Next' - ) }} -
-
-
+ {{ live_search(target_selector='.message-name', show=show_search_box, form=search_form) }} + {% endblock %} diff --git a/tests/app/main/views/test_email_branding.py b/tests/app/main/views/test_email_branding.py index 6e652611c..d9c3f5fe1 100644 --- a/tests/app/main/views/test_email_branding.py +++ b/tests/app/main/views/test_email_branding.py @@ -20,8 +20,9 @@ def test_email_branding_page_shows_full_branding_list( assert response.status_code == 200 page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') - radio_labels = page.select('div.multiple-choice > label') - brand_names = [element.get_text().strip() for idx, element in enumerate(radio_labels)] + links = page.select('.message-name a') + brand_names = [normalize_spaces(link.text) for link in links] + hrefs = [link['href'] for link in links] assert normalize_spaces( page.select_one('h1').text @@ -29,11 +30,16 @@ def test_email_branding_page_shows_full_branding_list( assert page.select_one('.column-three-quarters a')['href'] == url_for('main.create_email_branding') - first_label = radio_labels[0] - assert normalize_spaces(first_label.text) == 'org 1' assert brand_names == [ 'org 1', 'org 2', 'org 3', 'org 4', 'org 5' ] + assert hrefs == [ + url_for('.update_email_branding', branding_id=1), + url_for('.update_email_branding', branding_id=2), + url_for('.update_email_branding', branding_id=3), + url_for('.update_email_branding', branding_id=4), + url_for('.update_email_branding', branding_id=5), + ] def test_edit_email_branding_shows_the_correct_branding_info(