Пример #1
0
def account(req):
    p = create_params(req)
    departments = OrgGroup.objects.filter(parent=None)
    if req.method == "POST":
        form = AccountForm(req.user, req.POST)
        if form.is_valid():
            u = update_user(req)
            return HttpResponseRedirect('/staff/person/%s/'
                                        % u.get_profile().stub)
        else:
            p['form'] = form
            p['u'] = req.user
            p['depts'] = departments
            return render_to_response('core/profile_settings.html', p,
                                      context_instance=RequestContext(req))
    else:
        u = req.user
        form_data = user_form_data(u)
        form = AccountForm(req.user, form_data)

    p['form'] = form
    p['u'] = req.user
    p['depts'] = departments
    return render_to_response('core/profile_settings.html', p,
                              context_instance=RequestContext(req))
Пример #2
0
def account(req):
    p = create_params(req)
    departments = OrgGroup.objects.filter(parent=None)
    if req.method == "POST":
        form = AccountForm(req.user, req.POST)
        if form.is_valid():
            u = update_user(req)
            return HttpResponseRedirect('/staff/person/%s/' %
                                        u.get_profile().stub)
        else:
            p['form'] = form
            p['u'] = req.user
            p['depts'] = departments
            return render_to_response('core/profile_settings.html',
                                      p,
                                      context_instance=RequestContext(req))
    else:
        u = req.user
        form_data = user_form_data(u)
        form = AccountForm(req.user, form_data)

    p['form'] = form
    p['u'] = req.user
    p['depts'] = departments
    return render_to_response('core/profile_settings.html',
                              p,
                              context_instance=RequestContext(req))
Пример #3
0
def account_edit(request, account_id=None):
    if account_id:
        account = Account.objects.get(id=account_id)
        if account.created_by != request.user:
            return HttpResponse(status=403)
        if request.POST:
            form = AccountForm(request.POST or None, instance=account)
            if form.is_valid():
                form.save()
        else:
            form = AccountForm(instance=account)
    else:
        if request.POST:
            form = AccountForm(request.POST or None)
            if form.is_valid():
                account_obj = form.save(commit=False)
                account_obj.created_by = request.user
                account_obj.save()
                return redirect('account_edit', account_obj.id)
        else:
            form = AccountForm()
    return render(request, 'account_edit.html', {'form': form})
Пример #4
0
def create_account(request):
	if request.POST:
		form = AccountForm(request.POST)
		if form.is_valid():
			form.save()
			user = Account.objects.get(id=form.instance.id)
			pw = user.password
			user.set_password(pw)
			user.save()
			url = reverse('home')
			return HttpResponseRedirect(url) 
		else:
			print form.errors
	else:
		form = AccountForm()
	
	return render_to_response('core/create_account.html', context_instance=RequestContext(request))
Пример #5
0
def account(request):
    user = request.user

    try:
        profile = UserProfile.objects.get(user=request.user)
    except:
        profile = UserProfile()
        profile.new(user, ip_address=get_remote_ip(request))
        profile.save()

    form = AccountForm({"phone": profile.phone, "email": user.email})
    error = ""

    if request.method == "POST":
        form = AccountForm(request.POST)
        if form.is_valid():
            # user.email = form.cleaned_data['email']
            user.save()
            profile.phone = form.cleaned_data["phone"]
            profile.save()
            return index(request, "Your account has successfully been edited.")
        else:
            error = form.errors
    return load_page(request, "account.html", {"form": form, "error": error})