From 967a9b8411422a6109071a3ac2edd63cbb8ff572 Mon Sep 17 00:00:00 2001
From: Drew Larson
Date: Tue, 31 May 2016 09:21:06 -0600
Subject: [PATCH] Add `Payment` to `Membership`.
---
bikeshop_project/core/forms.py | 13 ++-
.../core/templates/membership_form.html | 85 +++++++++++--------
bikeshop_project/core/views.py | 19 +++--
3 files changed, 72 insertions(+), 45 deletions(-)
diff --git a/bikeshop_project/core/forms.py b/bikeshop_project/core/forms.py
index de016a7..2fce3f8 100644
--- a/bikeshop_project/core/forms.py
+++ b/bikeshop_project/core/forms.py
@@ -1,9 +1,9 @@
import logging
-from django.forms import BooleanField, CharField, CheckboxInput, RadioSelect, ModelForm, TextInput, HiddenInput
+from django.forms import BooleanField, CharField, CheckboxInput, RadioSelect, ModelForm, TextInput, HiddenInput, ChoiceField
from registration.models import Member
-from .models import Membership
+from .models import Membership, Payment
logger = logging.getLogger('bikeshop')
@@ -66,3 +66,12 @@ class MembershipForm(ModelForm):
instance.save()
return instance
+
+
+class PaymentForm(ModelForm):
+ class Meta:
+ model = Payment
+ fields = ['type']
+ widgets = {
+ 'type': RadioSelect(attrs={'class': 'mdl-radio__button'})
+ }
diff --git a/bikeshop_project/core/templates/membership_form.html b/bikeshop_project/core/templates/membership_form.html
index 3028d45..df5d49a 100644
--- a/bikeshop_project/core/templates/membership_form.html
+++ b/bikeshop_project/core/templates/membership_form.html
@@ -9,8 +9,9 @@
@@ -56,8 +57,8 @@
Our services are free and Members are encouraged to contribute in any way they can. Our vibrancy comes from the volunteer work of a large community with diverse skills and passions. There are so many ways to be a part of this community, regardless of whether or not you know how to change a tire (yet!). Ask how you can help out or get in touch with our volunteer coordinator (volunteer@bridgecitybicyclecoop.com )
-
- {{ form.give_back }}
+
+ {{ membership_form.give_back }}
I acknowledge that giving back is important
@@ -73,8 +74,8 @@
Label your bike with your name, phone number, and the last date you worked on it.
Do not force tools and use them only for their intended use. If you need help or guidance, ask someone! It’s what we’re here for!
-
- {{ form.respect_shop }}
+
+ {{ membership_form.respect_shop }}
I will respect the shop.
@@ -85,50 +86,62 @@
ethnicity so that we can track how well we are including all communities and whether there may be
barriers to certain groups’ participation. Thank you! Do you identify as: (In each category, check
all that apply)
- {% for checkbox in form.self_identification %}
+ {% for checkbox in membership_form.self_identification %}
{{ checkbox }}
{{ checkbox.label }}
{% endfor %}
- {% if form.self_identification.errors %}
- {{ form.self_identification.errors }}
+ {% if membership_form.self_identification.errors %}
+ {{ membership_form.self_identification.errors }}
{% else %}
Hmm
{% endif %}
-
- {{ form.self_ident_other }}
-
{{ form.self_ident_other.label }}
- {% if form.self_ident_other.errors %}
-
{{ form.self_ident_other.errors }}
+
+ {{ membership_form.self_ident_other }}
+ {{ membership_form.self_ident_other.label }}
+ {% if membership_form.self_ident_other.errors %}
+ {{ membership_form.self_ident_other.errors }}
{% endif %}
Gender Identification
- {% for checkbox in form.gender %}
+ {% for checkbox in membership_form.gender %}
{{ checkbox }}
{{ checkbox.label }}
{% endfor %}
-
- {{ form.gender_other }}
-
{{ form.gender_other.label }}
- {% if form.gender_other.errors %}
-
{{ form.gender_other.errors }}
+
+ {{ membership_form.gender_other }}
+ {{ membership_form.gender_other.label }}
+ {% if membership_form.gender_other.errors %}
+ {{ membership_form.gender_other.errors }}
{% endif %}
-
- {{ form.renewed_at }}
-
{{ form.renewed_at.label }}
- {% if form.renewed_at %}
-
{{ form.renewed_at.errors }}
+
+ {{ membership_form.renewed_at }}
+ {{ membership_form.renewed_at.label }}
+ {% if membership_form.renewed_at %}
+ {{ membership_form.renewed_at.errors }}
{% else %}
Incorrect date.
{% endif %}
+
+
+
+
+ {% for checkbox in payment_form.type %}
+
+ {{ checkbox }}
+ {{ checkbox.label }}
+
+ {% endfor %}
+
+
Submit
@@ -146,21 +159,21 @@
past: moment().subtract(100, 'years'),
trigger: document.getElementById('{{ form.renewed_at.id_for_label }}')
});
- document.getElementById('{{ form.renewed_at.id_for_label }}').addEventListener('focus', function() {
+ document.getElementById('{{ membership_form.renewed_at.id_for_label }}').addEventListener('focus', function() {
console.log('Toggle!');
renewedAt.toggle();
});
- document.getElementById('{{ form.renewed_at.id_for_label }}').addEventListener('onOk', function () {
+ document.getElementById('{{ membership_form.renewed_at.id_for_label }}').addEventListener('onOk', function () {
console.log('onOk');
this.parentNode.classList.add('is-dirty');
this.value = renewedAt.time.format('YYYY-MM-DD');
})
var responsibilities = [
- document.getElementById('{{ form.safe_space.id_for_label }}'),
- document.getElementById('{{ form.respect_community.id_for_label }}'),
- document.getElementById('{{ form.give_back.id_for_label }}'),
- document.getElementById('{{ form.respect_shop.id_for_label }}')
+ document.getElementById('{{ membership_form.safe_space.id_for_label }}'),
+ document.getElementById('{{ membership_form.respect_community.id_for_label }}'),
+ document.getElementById('{{ membership_form.give_back.id_for_label }}'),
+ document.getElementById('{{ membership_form.respect_shop.id_for_label }}')
];
var checkResponsiblities = function () {
allAgreed = responsibilities.every(function (checkbox) {
diff --git a/bikeshop_project/core/views.py b/bikeshop_project/core/views.py
index f16d46c..4cd330d 100644
--- a/bikeshop_project/core/views.py
+++ b/bikeshop_project/core/views.py
@@ -8,7 +8,7 @@ from django.views.generic import TemplateView, View
from registration.models import Member
-from .forms import MembershipForm
+from .forms import MembershipForm, PaymentForm
logger = logging.getLogger(__name__)
@@ -22,16 +22,21 @@ class NewMembershipView(TemplateView):
template_name = 'membership_form.html'
def get(self, request, member_id):
- form = MembershipForm(initial=dict(member=member_id))
- return self.render_to_response(dict(form=form))
+ membership_form = MembershipForm(initial=dict(member=member_id))
+ payment_form = PaymentForm()
+ return self.render_to_response(dict(membership_form=membership_form, payment_form=payment_form))
def post(self, request, member_id):
- form = MembershipForm(request.POST, initial=dict(member=member_id))
+ membership_form = MembershipForm(request.POST, initial=dict(member=member_id))
+ payment_form = PaymentForm(request.POST)
member = Member.objects.get(id=member_id)
- if form.is_valid():
- form.save()
+ if membership_form.is_valid() and payment_form.is_valid():
+ new_payment = payment_form.save()
+ new_membership = membership_form.save()
+ new_membership.payment = new_payment
+ new_membership.save()
messages.add_message(request, messages.SUCCESS, 'Successfully created our newest member, {first} {last}'
.format(first=member.first_name, last=member.last_name))
return HttpResponseRedirect(reverse('member_edit', kwargs=dict(member_id=member_id)))
- return self.render_to_response(dict(form=form))
+ return self.render_to_response(dict(membership_form=membership_form, payment_form=payment_form))