Пример #1
0
def account_update(request, account_id, *args, **kargs):
	"""
	Update an individual account.

	On GET, it will return a form to update the account.
	On POST, it will update information about the account.
	"""

	account = get_object_or_404(Account, pk=account_id)

	# Check that the user can access it, or 403
	if not authenticate_account(request.user, account):
		raise PermissionDenied()

	if request.method == 'POST':
		# Try to validate and update
		account_form = AccountForm(request.POST, instance=account)
		if account_form.is_valid():
			account = account_form.save()
			return HttpResponseRedirect('/account')
	else:
		# Populate the form with the current account's data
		account_form = AccountForm(instance=account)

	# Pass back the form we have, after updating CSRF
	kargs.update(csrf(request))
	context = RequestContext(request, dict(section="accounts",
		form=account_form, mode="update", account=account, **kargs))
	return render_to_response("accounts/form.html", context)
Пример #2
0
def account_update(request, account_id, *args, **kargs):
    """
	Update an individual account.

	On GET, it will return a form to update the account.
	On POST, it will update information about the account.
	"""

    account = get_object_or_404(Account, pk=account_id)

    # Check that the user can access it, or 403
    if not authenticate_account(request.user, account):
        raise PermissionDenied()

    if request.method == 'POST':
        # Try to validate and update
        account_form = AccountForm(request.POST, instance=account)
        if account_form.is_valid():
            account = account_form.save()
            return HttpResponseRedirect('/account')
    else:
        # Populate the form with the current account's data
        account_form = AccountForm(instance=account)

    # Pass back the form we have, after updating CSRF
    kargs.update(csrf(request))
    context = RequestContext(
        request,
        dict(section="accounts",
             form=account_form,
             mode="update",
             account=account,
             **kargs))
    return render_to_response("accounts/form.html", context)
Пример #3
0
def account_create(request, *args, **kargs):
    """
	Allow the user to create a new account.

	On GET, it will return a form to create a new account.
	On POST, it will use the post data to add an account to the database.
	"""

    if request.method == 'POST':
        # If a POST request, try to validate and save the new account
        # Failures fall through to returning the old form with errors
        account_form = AccountForm(request.POST)
        if account_form.is_valid():
            new_account = account_form.save()
            return HttpResponseRedirect('/account')
    else:
        # If GET request, return the form to make a new account
        account_form = AccountForm()

    # Update the CSRF token
    kargs.update(csrf(request))
    context = RequestContext(
        request,
        dict(section="accounts", mode="create", form=account_form, **kargs))
    return render_to_response("accounts/form.html", context)
Пример #4
0
def account_create(request, *args, **kargs):
	"""
	Allow the user to create a new account.

	On GET, it will return a form to create a new account.
	On POST, it will use the post data to add an account to the database.
	"""

	if request.method == 'POST':
		# If a POST request, try to validate and save the new account
		# Failures fall through to returning the old form with errors
		account_form = AccountForm(request.POST)
		if account_form.is_valid():
			new_account = account_form.save()
			return HttpResponseRedirect('/account')
	else:
		# If GET request, return the form to make a new account
		account_form = AccountForm()

	# Update the CSRF token
	kargs.update(csrf(request))
	context = RequestContext(request, dict(section="accounts", mode = "create",
		form=account_form, **kargs))
	return render_to_response("accounts/form.html", context)