Browse Source

Add submit form.

feature/python-error-tracking
Drew Larson 9 years ago
parent
commit
40254d9df1
  1. 4
      bikeshop_project/core/urls.py
  2. 20
      bikeshop_project/core/views.py

4
bikeshop_project/core/urls.py

@ -2,6 +2,6 @@ from django.conf.urls import url
from .views import DashboardView, NewMembershipView
urlpatterns = [
url(r'^membership/new/$', NewMembershipView.as_view()),
url(r'^$', DashboardView.as_view()),
url(r'^membership/new/$', NewMembershipView.as_view(), name='new_membership'),
url(r'^$', DashboardView.as_view())
]

20
bikeshop_project/core/views.py

@ -1,5 +1,8 @@
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.views.generic import View
from django.views.generic import TemplateView, View
from django.core.urlresolvers import reverse
from core.forms import MembershipForm
@ -9,8 +12,19 @@ class DashboardView(View):
return TemplateResponse(request, 'dashboard.html')
class NewMembershipView(View):
class NewMembershipView(TemplateView):
template_name = 'membership_form.html'
def get(self, request):
form = MembershipForm()
return self.render_to_response(dict(form=form))
return TemplateResponse(request, 'membership_form.html', {'form': form})
def post(self, request):
form = MembershipForm(request.POST)
if form.is_valid():
member = form.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('new_membership'))
return self.render_to_response(dict(form=form))

Loading…
Cancel
Save