From cf1f963e5d55602c4037069c8d921bce6627019e Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Wed, 28 Jun 2017 18:08:07 -0600 Subject: [PATCH] Issue61 (#62) * Check for api key before attempting to use api. * Change to read-only so we still send data on edit. --- bikeshop_project/registration/forms.py | 2 +- bikeshop_project/registration/handlers.py | 2 +- .../registration/templates/edit_member_form.html | 5 +++-- bikeshop_project/registration/templates/member_form.html | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bikeshop_project/registration/forms.py b/bikeshop_project/registration/forms.py index ebcbaee..a922e1d 100644 --- a/bikeshop_project/registration/forms.py +++ b/bikeshop_project/registration/forms.py @@ -27,7 +27,7 @@ class MemberForm(ModelForm): 'involvement': CheckboxSelectMultiple(choices=Member.involvement_choices, attrs={'class': 'mdl-checkbox__input'}), 'preferred_name': TextInput(attrs={'class': 'mdl-textfield__input'}), - 'guardian_name': DateInput(attrs={'class': 'mdl-textfield__input', 'disabled': 'disabled'}), + 'guardian_name': DateInput(attrs={'class': 'mdl-textfield__input', 'readonly': 'readonly'}), 'phone': TextInput(attrs={'class': 'mdl-textfield__input', 'pattern': '[0-9]*'}), 'street': TextInput(attrs={'class': 'mdl-textfield__input'}), 'city': TextInput(attrs={'class': 'mdl-textfield__input'}), diff --git a/bikeshop_project/registration/handlers.py b/bikeshop_project/registration/handlers.py index 01f087e..fe2883d 100644 --- a/bikeshop_project/registration/handlers.py +++ b/bikeshop_project/registration/handlers.py @@ -11,7 +11,7 @@ from registration.models import Member @receiver(post_save, sender=Member, dispatch_uid='member.save_member') def update_mailchimp(sender, instance, **kwargs): - if instance.email: + if instance.email and settings.MAILCHIMP_API_KEY: involvement = {id: True for id in instance.involvement} client = MailChimp(settings.MAILCHIMP_USERNAME, settings.MAILCHIMP_API_KEY) try: diff --git a/bikeshop_project/registration/templates/edit_member_form.html b/bikeshop_project/registration/templates/edit_member_form.html index 6c33255..32ec7eb 100644 --- a/bikeshop_project/registration/templates/edit_member_form.html +++ b/bikeshop_project/registration/templates/edit_member_form.html @@ -16,11 +16,12 @@ 'YYYY/MM/DD', 'YY/MM/DD', 'DD/MM/YY', 'DD/MM/YYYY']); if (dob.add(threshold).isAfter(moment())) { - document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false; + document.getElementById('{{ form.guardian_name.id_for_label }}').readOnly = false; document.getElementById('{{ form.guardian_name.id_for_label }}').required = true; document.getElementById('{{ form.guardian_name.id_for_label }}').parentNode.classList.remove('is-disabled'); + document.getElementById('{{ form.guardian_name.id_for_label }}').focus(); } else { - document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = true; + document.getElementById('{{ form.guardian_name.id_for_label }}').readOnly = true; document.getElementById('{{ form.guardian_name.id_for_label }}').parentNode.classList.add('is-disabled'); } }); diff --git a/bikeshop_project/registration/templates/member_form.html b/bikeshop_project/registration/templates/member_form.html index 41a1f07..d9e8cf0 100644 --- a/bikeshop_project/registration/templates/member_form.html +++ b/bikeshop_project/registration/templates/member_form.html @@ -15,11 +15,12 @@ 'YYYY/MM/DD', 'YY/MM/DD', 'DD/MM/YY', 'DD/MM/YYYY']); if (dob.add(threshold).isAfter(moment())) { - document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false; + document.getElementById('{{ form.guardian_name.id_for_label }}').readOnly = false; document.getElementById('{{ form.guardian_name.id_for_label }}').required = true; document.getElementById('{{ form.guardian_name.id_for_label }}').parentNode.classList.remove('is-disabled'); + document.getElementById('{{ form.guardian_name.id_for_label }}').focus(); } else { - document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = true; + document.getElementById('{{ form.guardian_name.id_for_label }}').readOnly = true; document.getElementById('{{ form.guardian_name.id_for_label }}').parentNode.classList.add('is-disabled'); } });