예제 #1
0
파일: views.py 프로젝트: kwistbac/votune
def editAccount(request):
    accountEditForm = AccountEditForm(instance=request.user)
    usernameEditForm = UserNameEditForm(instance=request.user)
    usrAccount = Account.getByID(request.user)
    otherInfoEditForm = OtherInfoEditForm(instance=usrAccount)
    passwordChangeForm = PasswordChangeForm()

    if request.method == 'POST' and 'account_update' in request.POST:
        accountEditForm = AccountEditForm(request.POST, instance=request.user)
        if accountEditForm.is_valid():
            accountEditForm.firstName = MySQLdb.escape_string(request.POST['first_name'])
            accountEditForm.last_name = MySQLdb.escape_string(request.POST['last_name'])
            accountEditForm.email = MySQLdb.escape_string(request.POST['email'])
            accountEditForm.save()
            messages.add_message(request, messages.INFO, 'Account was successfully updated.')
            return HttpResponseRedirect('')

    elif request.method == 'POST' and 'username_update' in request.POST:
        usernameEditForm = UserNameEditForm(request.POST, instance=request.user)
        if usernameEditForm.is_valid():
            usernameEditForm.username = MySQLdb.escape_string(request.POST['username'])
            usernameEditForm.save()
            messages.add_message(request, messages.INFO, 'Username was successfully updated.')
            return HttpResponseRedirect('/establishment')

    elif request.method == 'POST' and 'other_info_update' in request.POST:
        otherInfoEditForm = OtherInfoEditForm(request.POST, instance=usrAccount)
        if otherInfoEditForm.is_valid():
            otherInfoEditForm.company = MySQLdb.escape_string(request.POST['company'])
            otherInfoEditForm.address = MySQLdb.escape_string(request.POST['address'])
            otherInfoEditForm.postal_code = MySQLdb.escape_string(request.POST['postal_code'])
            otherInfoEditForm.phone = MySQLdb.escape_string(request.POST['phone'])
            otherInfoEditForm.save()
            messages.add_message(request, messages.INFO, 'Username was successfully updated.')
            return HttpResponseRedirect('/establishment')

    elif request.method == 'POST' and 'password_update' in request.POST:
        password1 = request.POST.get('password', '')
        password2 = request.POST.get('confirm_password', '')

        if password1 != password2:
            messages.add_message(request, messages.ERROR, 'Password did not match.')
            return HttpResponseRedirect('')
        elif len(password1) < 4:
            messages.add_message(request, messages.ERROR, 'Password too short.')
            return HttpResponseRedirect('')
        else:
            u = User.objects.get(username=request.user)
            u.set_password(password1)
            u.save()
            messages.add_message(request, messages.INFO, 'Password successfully updated')
            return HttpResponseRedirect('/establishment')

    return render_to_response('establishment/edit_account.html',
                              {
                                  'accountEditForm': accountEditForm,
                                  'usernameEditForm': usernameEditForm,
                                  'otherInfoEditForm': otherInfoEditForm,
                                  'passwordChangeForm': passwordChangeForm},
                              context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: kwistbac/votune
def editOther(request):
    usrAccount = Account.getByID(request.user)
    form = OtherInfoEditForm(instance=usrAccount)

    if 'ok' in request.POST:
        print("Submitted")
        form = OtherInfoEditForm(request.POST, instance=usrAccount)
        if form.is_valid():
            form.company = MySQLdb.escape_string(request.POST['company'])
            form.address = MySQLdb.escape_string(request.POST['address'])
            form.postal_code = MySQLdb.escape_string(request.POST['postal_code'])
            form.phone = MySQLdb.escape_string(request.POST['phone'])
            form.save()
            return HttpResponse(status=201)
    return render_to_response("establishment/accounts/edit_other.html",
                              {'form': form},
                              context_instance=RequestContext(request))