Exemple #1
0
def user_register(request):
	registered = False
	page = ''
	try:
		page = Page.objects.get(ptype = 'register')
	except:
		raise Http404
	if request.method == 'POST':
		user_form = UserForm(data = request.POST)
		member_form = MemberForm(data = request.POST)
		if user_form.is_valid() and member_form.is_valid():
			user = user_form.save()

			user.set_password(user.password)
			user.save()
			member = member_form.save(commit = False)
			member.user = user
			member.save()
			u = authenticate(username = request.POST['username'], password = request.POST['password'])
			login(request,u)
			registered = True
			return HttpResponseRedirect('/')

		else:
			return render_to_response('register.html',{'user_form':user_form, 'member_form':member_form, 'registered':registered, 'page':page },context_instance=RequestContext(request))

	else :
		user_form = UserForm()
		member_form = MemberForm()

	return render_to_response('register.html',{'user_form':user_form, 'member_form':member_form, 'registered':registered,'page':page },context_instance=RequestContext(request))
Exemple #2
0
def member_create(request):
 #   import pdb; pdb.set_trace()
    if request.method == 'POST':
        form = MemberForm(request.POST,request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('member_random')
    else:
        form = MemberForm()

    return render(request, 'member/create_member.html',{'form':form})
Exemple #3
0
def add(request):

    if request.method == 'POST':
        form = MemberForm(request.POST)

        if form.is_valid():
            member = form.save()
            return HttpResponseRedirect('/member/view/%s' % member.ssn)

    else:
        form = MemberForm()

    return render_to_response('member/add.html', { 'form': form }, context_instance=RequestContext(request))
Exemple #4
0
def edit(request, ssn):

    member = get_object_or_404(Member, ssn=ssn)

    if request.method == 'POST':
        member.groups = request.POST.getlist('groups')
        form = MemberForm(request.POST, instance=member)

        if form.is_valid():
            member = form.save()
            return HttpResponseRedirect('/member/view/%s/' % member.ssn)

    else:
        form = MemberForm(instance=member)

    return render_to_response('member/edit.html', { 'form': form, 'member': member }, context_instance=RequestContext(request))
Exemple #5
0
def home(request):
    if request.method == 'POST':
        form = MemberForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Thank you for registering')
            return redirect('home')
    else:
        form = MemberForm()
    return render(request, 'home.html', {'form': form})
Exemple #6
0
def signup_view(request):
    if request.method == 'POST':
        form = MemberForm(data=request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect("home")
        else:
            context = {"form": form}
            return render(request, 'signup.html', context)
    elif request.method == 'GET':
        form = MemberForm()
    else:
        return HttpResponse(status=405)
    context = {"form": form}
    return render(request, "signup.html", context)
Exemple #7
0
def member_edit(request, member_id=None):
    if member_id:
        member = get_object_or_404(Member, pk=member_id)
        title = "顧客編集"
    else:
        member = Member()
        title = "顧客追加"

    if request.method == 'POST':
        form = MemberForm(request.POST, instance=member)
        if form.is_valid():
            member = form.save(commit=False)
            member.save()
            return redirect('member:member_list')
    else:
        form = MemberForm(instance=member)

    return render(request, 'member/edit.html',
                  dict(form=form, member_id=member_id, title=title))
Exemple #8
0
def member_register(request):

    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = MemberForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:

            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = MemberForm()

    return render(
        request, 'member/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #9
0
def index(request):
    mform = MemberForm()
    miform = MemberInfoForm()
    return render(request,'home/index.html',{'user_form':mform,'profile_form':miform})