Example #1
0
def edit(request):
    msg = None
    success = None
    try:
        if request.method == 'POST':
            form = EditForm(request.POST)
            u = User.objects.filter(email=request.session['session_id'])[0]

            if form.is_valid():
                u.name = form.cleaned_data['name']
                u.phone = form.cleaned_data['phone']
                u.organisation = form.cleaned_data['organisation']
                u.subscribe = form.cleaned_data['subscribe']
                u.save()
                request.session['name'] = u.name
                msg = 'Your changes were saved successfully'
                success = 1
            else:
                msg = 'There are errors in the form'
                success = 0
        else:
            u = User.objects.filter(email=request.session['session_id'])[0]
            form = EditForm({'name': u.name, 'phone': u.phone, 'organisation': u.organisation, 'subscribe': u.subscribe})

        return render_to_response('users/edit.html', {'name': 'Edit', 'list': menu, 'form': form, 'msg': msg, 'success': success}, context_instance=RequestContext(request))
    except KeyError:
        form = LoginForm()
        next = '/users/edit'
        return HttpResponseRedirect('/users/login/?next=%s' % next)
Example #2
0
def user_edit(request, pk):
    form = EditForm(request.POST or None, instance=User.objects.get(pk=pk))
    if form.is_valid():
        form.save()
        info(request, 'User details changed.')
        return HttpResponseRedirect(reverse("user-list"))
    return direct_to_template(request, "user_edit.html", extra_context={
        "form": form,
        "nav": {"selected": "users",},
    })