Browse Source

Saner member sign-up!

feature/python-error-tracking
Drew Larson 9 years ago
parent
commit
f22f39f67f
  1. 2
      bikeshop_project/registration/forms.py
  2. 6
      bikeshop_project/registration/templates/edit_member_form.html
  3. 14
      bikeshop_project/registration/templates/member_form.html
  4. 26
      bikeshop_project/registration/views.py

2
bikeshop_project/registration/forms.py

@ -4,7 +4,7 @@ from registration.models import Member
class MemberForm(ModelForm): class MemberForm(ModelForm):
waiver_substitute = BooleanField(label='I have read and agree to the above terms & conditions.', widget=CheckboxInput(attrs={'class': 'mdl-checkbox__input'})) waiver_substitute = BooleanField(required=False, label='I have read and agree to the above terms & conditions.', widget=CheckboxInput(attrs={'class': 'mdl-checkbox__input'}))
class Meta: class Meta:
model = Member model = Member

6
bikeshop_project/registration/templates/edit_member_form.html

@ -2,16 +2,16 @@
{% load staticfiles %} {% load staticfiles %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'vendor/md-date-time-picker/dist/css/md-date-time-picker.min.css' %}"> <link rel="stylesheet" href="{% static 'vendor/md-date-time-picker/dist/css/mdDateTimePicker.min.css' %}">
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{% static 'vendor/moment/min/moment.min.js' %}"></script> <script src="{% static 'vendor/moment/min/moment.min.js' %}"></script>
<script src="{% static 'vendor/object.observe/dist/object-observe-lite.min.js' %}"></script> <script src="{% static 'vendor/object.observe/dist/object-observe-lite.min.js' %}"></script>
<script src="{% static 'vendor/draggabilly/dist/draggabilly.pkgd.min.js' %}"></script> <script src="{% static 'vendor/draggabilly/dist/draggabilly.pkgd.min.js' %}"></script>
<script src="{% static 'vendor/md-date-time-picker/dist/js/md-date-time-picker.js' %}"></script> <script src="{% static 'vendor/md-date-time-picker/dist/js/mdDateTimePicker.min.js' %}"></script>
<script> <script>
var dateOfBirth = new mdDateTimePicker({ var dateOfBirth = new mdDateTimePicker.default({
type: 'date', type: 'date',
past: moment().subtract(100, 'years') past: moment().subtract(100, 'years')
}); });

14
bikeshop_project/registration/templates/member_form.html

@ -2,16 +2,16 @@
{% load staticfiles %} {% load staticfiles %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'vendor/md-date-time-picker/dist/css/md-date-time-picker.min.css' %}"> <link rel="stylesheet" href="{% static 'vendor/md-date-time-picker/dist/css/mdDateTimePicker.min.css' %}">
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{% static 'vendor/moment/min/moment.min.js' %}"></script> <script src="{% static 'vendor/moment/min/moment.min.js' %}"></script>
<script src="{% static 'vendor/object.observe/dist/object-observe-lite.min.js' %}"></script> <script src="{% static 'vendor/object.observe/dist/object-observe-lite.min.js' %}"></script>
<script src="{% static 'vendor/draggabilly/dist/draggabilly.pkgd.min.js' %}"></script> <script src="{% static 'vendor/draggabilly/dist/draggabilly.pkgd.min.js' %}"></script>
<script src="{% static 'vendor/md-date-time-picker/dist/js/md-date-time-picker.js' %}"></script> <script src="{% static 'vendor/md-date-time-picker/dist/js/mdDateTimePicker.min.js' %}"></script>
<script> <script>
var dateOfBirth = new mdDateTimePicker({ var dateOfBirth = new mdDateTimePicker.default({
type: 'date', type: 'date',
past: moment().subtract(100, 'years') past: moment().subtract(100, 'years')
}); });
@ -20,11 +20,11 @@
}); });
Object.observe(dateOfBirth, function(changes) { Object.observe(dateOfBirth, function(changes) {
var input = document.getElementById('{{ form.date_of_birth.id_for_label }}'); var input = document.getElementById('{{ form.date_of_birth.id_for_label }}');
input.value = dateOfBirth.time().format('YYYY-MM-DD'); input.value = dateOfBirth.time.format('YYYY-MM-DD');
input.parentNode.classList.add('is-dirty'); input.parentNode.classList.add('is-dirty');
var threshold = moment.duration(18, 'years'); var threshold = moment.duration(18, 'years');
var dob = dateOfBirth.time().clone(); var dob = dateOfBirth.time.clone();
if (dob.add(threshold).isAfter(moment())) { if (dob.add(threshold).isAfter(moment())) {
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false; document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;
@ -75,7 +75,9 @@
{% if form.non_field_errors %} {% if form.non_field_errors %}
<div> <div>
<span class="error">{{ form.errors }}</span> {% for errors in form.non_field_errors %}
<span class="mdl-textfield__error">{{ error }}</span>
{% endfor %}
</div> </div>
{% endif %} {% endif %}
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label {% if form.email.errors %}is-invalid{% endif %}"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label {% if form.email.errors %}is-invalid{% endif %}">

26
bikeshop_project/registration/views.py

@ -1,12 +1,13 @@
from django.shortcuts import get_object_or_404 from django.contrib import messages
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils import timezone
from django.views.generic import View from django.views.generic import View
from django.core.urlresolvers import reverse
from .forms import MemberForm from .forms import MemberForm
from .models import Member from .models import Member
import logging import logging
logger = logging.getLogger(__file__) logger = logging.getLogger('bikeshop')
class MemberFormView(View): class MemberFormView(View):
@ -17,18 +18,27 @@ class MemberFormView(View):
form = MemberForm(instance=member) form = MemberForm(instance=member)
except Member.DoesNotExist: except Member.DoesNotExist:
form = MemberForm() form = MemberForm()
member = None
context = dict(form=form) context = dict(form=form)
if form.instance: if member:
return TemplateResponse(request, 'edit_member_form.html', context=context) return TemplateResponse(request, 'edit_member_form.html', context=context)
return TemplateResponse(request, 'member_form.html', context=context) return TemplateResponse(request, 'member_form.html', context=context)
def post(self, request): def post(self, request, member_id=None):
try:
logger.debug(member_id)
member = Member.objects.get(id=member_id)
form = MemberForm(request.POST, instance=member)
except Member.DoesNotExist:
form = MemberForm(request.POST) form = MemberForm(request.POST)
logger.debug(form)
if form.is_valid(): if form.is_valid():
form.save() member_instance = form.save()
return TemplateResponse(request, 'member_created.html') logger.debug(member_instance)
return HttpResponseRedirect(reverse('member_edit', kwargs=dict(member_id=member_instance.id)))
logger.debug(form)
context = {'form': form} context = {'form': form}
return TemplateResponse(request, 'member_form.html', context=context) return TemplateResponse(request, 'member_form.html', context=context)

Loading…
Cancel
Save