From 40b88097d11f0809ed6bd33a1ea3e1a51af529e4 Mon Sep 17 00:00:00 2001
From: Drew Larson
Date: Mon, 30 May 2016 21:32:45 -0600
Subject: [PATCH] Add membership to member.
---
bikeshop_project/core/forms.py | 37 +++++++++++++++----
bikeshop_project/core/static/scss/screen.scss | 1 +
.../core/templates/membership_form.html | 12 ++++--
bikeshop_project/core/views.py | 25 ++++++++-----
4 files changed, 55 insertions(+), 20 deletions(-)
diff --git a/bikeshop_project/core/forms.py b/bikeshop_project/core/forms.py
index 59dde4f..859a48c 100644
--- a/bikeshop_project/core/forms.py
+++ b/bikeshop_project/core/forms.py
@@ -1,9 +1,15 @@
-from django.forms import ModelForm, TextInput, DateInput, CheckboxSelectMultiple, CharField, BooleanField, CheckboxInput
+import logging
+from django.forms import BooleanField, CharField, CheckboxInput, RadioSelect, ModelForm, TextInput, HiddenInput
-from core.models import Membership
+from registration.models import Member
+
+from .models import Membership
+
+logger = logging.getLogger('bikeshop')
class MembershipForm(ModelForm):
+ member = CharField(required=True, widget=HiddenInput())
self_ident_other = CharField(required=False, label='Self identification', widget=TextInput(attrs={'class': 'mdl-textfield__input'}))
gender_other = CharField(required=False, label='Other', widget=TextInput(attrs={'class': 'mdl-textfield__input'}))
safe_space = BooleanField(required=True, widget=CheckboxInput(
@@ -27,18 +33,35 @@ class MembershipForm(ModelForm):
('First Nations; Métis; or Inuit', 'First Nations; Métis; or Inuit'),
('visible minority', 'Visible Minority'),
('caucasian', 'Caucasian'),
- ('Other', 'Other')
+ ('other', 'Other')
)
gender_choices = (
('male', 'Male'),
('female', 'Female'),
- ('other', 'other')
+ ('other', 'Other')
)
widgets = {
- 'self_identification': CheckboxSelectMultiple(choices=self_ident_choices,
- attrs={'class': 'mdl-checkbox__input'}),
- 'gender': CheckboxSelectMultiple(choices=gender_choices, attrs={'class': 'mdl-checkbox__input'}),
+ 'self_identification': RadioSelect(choices=self_ident_choices, attrs={'class': 'mdl-radio__button'}),
+ 'gender': RadioSelect(choices=gender_choices, attrs={'class': 'mdl-radio__button'}),
'renewed_at': TextInput(attrs={'class': 'mdl-textfield__input'}),
}
+
+ def save(self, commit=True):
+ instance = super(MembershipForm, self).save(commit=False)
+ member = Member.objects.get(id=self.cleaned_data['member'])
+ instance.member = member
+ logger.debug(self.cleaned_data['self_identification'])
+ logger.debug(self.cleaned_data['gender'])
+
+ if self.cleaned_data['gender_other']:
+ instance.gender = self.cleaned_data['gender_other']
+
+ if self.cleaned_data['self_ident_other']:
+ instance.self_identification = self.cleaned_data['self_ident_other']
+
+ if commit:
+ instance.save()
+
+ return instance
diff --git a/bikeshop_project/core/static/scss/screen.scss b/bikeshop_project/core/static/scss/screen.scss
index 1bd2db5..3c91d7b 100644
--- a/bikeshop_project/core/static/scss/screen.scss
+++ b/bikeshop_project/core/static/scss/screen.scss
@@ -7,6 +7,7 @@
@import "vendor/material-design-lite/src/layout/layout";
@import "vendor/material-design-lite/src/footer/mega_footer";
@import "vendor/material-design-lite/src/checkbox/checkbox";
+@import "vendor/material-design-lite/src/radio/radio";
@import "vendor/material-design-lite/src/button/button";
@import "vendor/material-design-lite/src/palette/palette";
@import "vendor/material-design-lite/src/menu/menu";
diff --git a/bikeshop_project/core/templates/membership_form.html b/bikeshop_project/core/templates/membership_form.html
index 530119b..3028d45 100644
--- a/bikeshop_project/core/templates/membership_form.html
+++ b/bikeshop_project/core/templates/membership_form.html
@@ -10,6 +10,7 @@
New Membership
{% for checkbox in form.self_identification %}
-