Пример #1
0
def register_retailer(request, template_name='account/retailer/register_retailer.html'):
    if request.method == 'POST':
        form = RetailerRegisterForm(request.POST)

        registration_code = RegistrationCode.objects.get(pk=request.POST['registration_code'])
        retailer = registration_code.retailer

        if form.is_valid():
            retailer_account = form.save()
            retailer_account.retailer = retailer
            retailer_account.save()

            credentials = authenticate(username=request.POST['email'], password=request.POST['password'])
            if credentials is not None:
                login(request, credentials)
                return HttpResponseRedirect('/')

        else:
            variables = RequestContext(request, {
                'form':form,
                'registration_code':registration_code.code,
                'retailer':retailer
            })

            return render_to_response(template_name, variables)

    else:
        if 'registration_code' in request.GET:
            code_form = RetailerRegistrationCodeForm(request.GET)
            if code_form.is_valid():
                reg_code = code_form.cleaned_data['registration_code']
                retailer = reg_code.retailer

                variables = RequestContext(request, {
                    'form':code_form,
                    'retailer':retailer
                })

                return render_to_response(template_name, variables)
            else:
                return HttpResponseRedirect('/retailer/code')
        else:
            return HttpResponseRedirect('/retailer/code')
Пример #2
0
def registration_code(request):
    if 'registration_code' in request.GET:
        code_form = RetailerRegistrationCodeForm(request.GET)
        if code_form.is_valid():
            reg_code = code_form.cleaned_data['registration_code']
            retailer = reg_code.retailer
            reg_form = RetailerRegisterForm()

            variables = RequestContext(request, {
                'form':reg_form,
                'retailer':retailer,
                'registration_code':reg_code.code
            })

            return render_to_response('account/retailer/register_retailer.html', variables)

    else:
        code_form = RetailerRegistrationCodeForm()

    variables = RequestContext(request, {
        'form':code_form
    })

    return render_to_response('account/registration_code.html', variables)