def edit_user(request):
    if request.method == 'POST':
        form = UserEditForm(request.POST, request.FILES, instance=Profile.objects.get(user=request.user))       
        if form.is_valid():
            form.save()
            return redirect('index')
        else:
            return render_to_response('index.html', {'form': form, }, RequestContext(request))
    form = UserEditForm(instance=Profile.objects.get(user=request.user))
    return render_to_response('add_user.html', {'form': form, }, RequestContext(request))
Ejemplo n.º 2
0
def edit_user(request, pk):
    user = get_object_or_404(User, pk=pk)
    form = UserEditForm(instance=user)
    if request.method == 'POST':
        form = UserEditForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            return redirect('users')
    return render_to_response('add_user.html', {
        'form': form,
        }, RequestContext(request))
Ejemplo n.º 3
0
def edit_user(request):
    if request.method == 'POST':
        form = UserEditForm(request.POST, instance= request.user)
        if form.is_valid():
            form.save()
    else:
        form = UserEditForm(instance = request.user)
        
    return render_to_response('user_edit.html', 
                              {'edit_form': form}, 
                              context_instance = RequestContext(request))
Ejemplo n.º 4
0
def store_account(request):
    user_form = UserEditForm(instance=request.user)
    store_form = StoreForm(instance=request.user.store)

    if request.method == "POST":
        user_form = UserEditForm(request.POST, instance=request.user)
        store_form = StoreForm(request.POST, instance=request.user.store)
        if user_form.is_valid() and store_form.is_valid():
            user_form.save()
            store_form.save()
    return render(request, 'store/store_account.html', {
        'user_form': user_form,
        'store_form': store_form
    })
Ejemplo n.º 5
0
def delivery_boy_account(request):
    user_form = UserEditForm(instance=request.user)
    delivery_boy_form = DeliveryBoyForm(instance=request.user.delivery_boy)

    if request.method == "POST":
        user_form = UserEditForm(request.POST, instance=request.user)
        delivery_boy_form = DeliveryBoyForm(request.POST,
                                            instance=request.user.delivery_boy)
        if user_form.is_valid() and delivery_boy_form.is_valid():
            user_form.save()
            delivery_boy_form.save()
    return render(request, 'deliver/delivery_boy_account.html', {
        'user_form': user_form,
        'delivery_boy_form': delivery_boy_form
    })
Ejemplo n.º 6
0
def user_edit(request, pk):
    if request.user != CustomUser.objects.get(pk=pk):
        return HttpResponseRedirect('/invalid_user/')

    context = {}

    user = CustomUser.objects.get(pk=pk)

    form = UserEditForm(request.POST or None, request.FILES or None, instance=user)

    context['user'] = user
    context['form'] = form
    context['pk'] = pk

    if request.method == 'POST' and form.is_valid():
        form.save()
        print 'valid'
        return HttpResponseRedirect('/user_detail_view/%s' % (user.pk))
    else:
        print form.errors

    return render_to_response('user_edit.html', context, context_instance=RequestContext(request))