- {{ 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))