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