Browse Source

Add membership to member.

feature/python-error-tracking
Drew Larson 9 years ago
parent
commit
40b88097d1
  1. 37
      bikeshop_project/core/forms.py
  2. 1
      bikeshop_project/core/static/scss/screen.scss
  3. 12
      bikeshop_project/core/templates/membership_form.html
  4. 25
      bikeshop_project/core/views.py

37
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): 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'})) 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'})) gender_other = CharField(required=False, label='Other', widget=TextInput(attrs={'class': 'mdl-textfield__input'}))
safe_space = BooleanField(required=True, widget=CheckboxInput( 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'), ('First Nations; Métis; or Inuit', 'First Nations; Métis; or Inuit'),
('visible minority', 'Visible Minority'), ('visible minority', 'Visible Minority'),
('caucasian', 'Caucasian'), ('caucasian', 'Caucasian'),
('Other', 'Other') ('other', 'Other')
) )
gender_choices = ( gender_choices = (
('male', 'Male'), ('male', 'Male'),
('female', 'Female'), ('female', 'Female'),
('other', 'other') ('other', 'Other')
) )
widgets = { widgets = {
'self_identification': CheckboxSelectMultiple(choices=self_ident_choices, 'self_identification': RadioSelect(choices=self_ident_choices, attrs={'class': 'mdl-radio__button'}),
attrs={'class': 'mdl-checkbox__input'}), 'gender': RadioSelect(choices=gender_choices, attrs={'class': 'mdl-radio__button'}),
'gender': CheckboxSelectMultiple(choices=gender_choices, attrs={'class': 'mdl-checkbox__input'}),
'renewed_at': TextInput(attrs={'class': 'mdl-textfield__input'}), '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

1
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/layout/layout";
@import "vendor/material-design-lite/src/footer/mega_footer"; @import "vendor/material-design-lite/src/footer/mega_footer";
@import "vendor/material-design-lite/src/checkbox/checkbox"; @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/button/button";
@import "vendor/material-design-lite/src/palette/palette"; @import "vendor/material-design-lite/src/palette/palette";
@import "vendor/material-design-lite/src/menu/menu"; @import "vendor/material-design-lite/src/menu/menu";

12
bikeshop_project/core/templates/membership_form.html

@ -10,6 +10,7 @@
<h1>New Membership</h1> <h1>New Membership</h1>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.member }}
<p>The Bridge City Bicycle Co­operative aims to be a safe and respectful environment geared towards education, empowerment and community­building. In order to do so we need your input and support.</p> <p>The Bridge City Bicycle Co­operative aims to be a safe and respectful environment geared towards education, empowerment and community­building. In order to do so we need your input and support.</p>
<h4>Member Privileges</h4> <h4>Member Privileges</h4>
@ -85,9 +86,9 @@
barriers to certain groups’ participation. Thank you! Do you identify as: (In each category, check barriers to certain groups’ participation. Thank you! Do you identify as: (In each category, check
all that apply)</p> all that apply)</p>
{% for checkbox in form.self_identification %} {% for checkbox in form.self_identification %}
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="{{ checkbox.id_for_label }}"> <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="{{ checkbox.id_for_label }}">
{{ checkbox }} {{ checkbox }}
<span class="mdl-checkbox__label">{{ checkbox.label }}</span> <span class="mdl-radio__label">{{ checkbox.label }}</span>
</label> </label>
{% endfor %} {% endfor %}
{% if form.self_identification.errors %} {% if form.self_identification.errors %}
@ -106,9 +107,9 @@
<div class=""> <div class="">
<h3 class="template__header mdl-typography--body-2">Gender Identification</h3> <h3 class="template__header mdl-typography--body-2">Gender Identification</h3>
{% for checkbox in form.gender %} {% for checkbox in form.gender %}
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="{{ checkbox.id_for_label }}"> <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="{{ checkbox.id_for_label }}">
{{ checkbox }} {{ checkbox }}
<span class="mdl-checkbox__label">{{ checkbox.label }}</span> <span class="mdl-radio__label">{{ checkbox.label }}</span>
</label> </label>
{% endfor %} {% endfor %}
</div> </div>
@ -168,6 +169,9 @@
var submitButton = document.getElementById('submit'); var submitButton = document.getElementById('submit');
submitButton.disabled = !allAgreed; submitButton.disabled = !allAgreed;
}; };
document.addEventListener("DOMContentLoaded", checkResponsiblities);
responsibilities.forEach(function (checkbox) { responsibilities.forEach(function (checkbox) {
checkbox.addEventListener('click', checkResponsiblities) checkbox.addEventListener('click', checkResponsiblities)
}) })

25
bikeshop_project/core/views.py

@ -1,10 +1,16 @@
import logging
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.views.generic import TemplateView, View from django.views.generic import TemplateView, View
from django.core.urlresolvers import reverse
from core.forms import MembershipForm from registration.models import Member
from .forms import MembershipForm
logger = logging.getLogger(__name__)
class DashboardView(View): class DashboardView(View):
@ -14,17 +20,18 @@ class DashboardView(View):
class NewMembershipView(TemplateView): class NewMembershipView(TemplateView):
template_name = 'membership_form.html' template_name = 'membership_form.html'
def get(self, request):
form = MembershipForm() def get(self, request, member_id):
form = MembershipForm(initial=dict(member=member_id))
return self.render_to_response(dict(form=form)) return self.render_to_response(dict(form=form))
def post(self, request): def post(self, request, member_id):
form = MembershipForm(request.POST) form = MembershipForm(request.POST, initial=dict(member=member_id))
member = Member.objects.get(id=member_id)
if form.is_valid(): if form.is_valid():
member = form.save() form.save()
messages.add_message(request, messages.SUCCESS, 'Successfully created our newest member, {first} {last}' messages.add_message(request, messages.SUCCESS, 'Successfully created our newest member, {first} {last}'
.format(first=member.first_name, last=member.last_name)) .format(first=member.first_name, last=member.last_name))
return HttpResponseRedirect(reverse('new_membership')) 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(form=form))

Loading…
Cancel
Save