You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

9 years ago
from django.shortcuts import get_object_or_404
9 years ago
from django.template.response import TemplateResponse
from django.utils import timezone
from django.views.generic import View
from .forms import MemberForm
9 years ago
from .models import Member
import logging
logger = logging.getLogger(__file__)
9 years ago
class MemberFormView(View):
9 years ago
def get(self, request, member_id=None):
try:
logger.debug(member_id)
member = Member.objects.get(id=member_id)
form = MemberForm(instance=member)
except Member.DoesNotExist:
form = MemberForm()
context = dict(form=form)
if form.instance:
return TemplateResponse(request, 'edit_member_form.html', context=context)
9 years ago
return TemplateResponse(request, 'member_form.html', context=context)
def post(self, request):
form = MemberForm(request.POST)
if form.is_valid():
form.save()
return TemplateResponse(request, 'member_created.html')
context = {'form': form}
return TemplateResponse(request, 'member_form.html', context=context)