Exemple #1
0
def account_edit(request, pk):
    if not (request.user.account.pk == pk or request.user.account.role
            == 'admin') or request.user.account.demo:
        raise Http404

    account = get_object_or_404(Account, pk=pk)

    if request.method == 'POST':

        if not request.user.account.pk == pk:
            account_form = AccountForm(request.POST, instance=account)
            if account_form.is_valid():
                account_form.save()
                return redirect('account_detail', pk)

        elif not request.user.account.role == 'admin':
            user_form = EditUserForm(request.POST, instance=account.user)
            if user_form.is_valid():
                user_form.save()
                return redirect('account_detail', pk)
            else:
                messages.info(request, user_form.errors)
                return redirect('account_edit', pk)

        else:
            account_form = AccountForm(request.POST, instance=account)
            user_form = EditUserForm(request.POST, instance=account.user)
            if account_form.is_valid() and user_form.is_valid():
                account_form.save()
                user_form.save()
                return redirect('account_detail', pk)
            else:
                messages.info(request, user_form.errors)
                return redirect('account_edit', pk)

    account_form = AccountForm(instance=account)
    user_form = EditUserForm(instance=account.user)

    if not request.user.account.pk == pk:
        return render(request, 'accounts/account_edit_role.html', {
            'account': account,
            'form': account_form
        })

    elif not request.user.account.role == 'admin':
        return render(request, 'accounts/account_edit_user.html', {
            'account': account,
            'form': user_form
        })

    return render(request, 'accounts/account_edit_admin.html', {
        'account_form': account_form,
        'user_form': user_form
    })
def profile(request):
    # fetch user from db
    user = User.objects.get(pk=request.user.id)

    # save the forms
    if request.method == "POST":
        # create the form to edit the user
        uform = EditUserForm(data=request.POST, instance=user)
        # also edit the profile of this user
        pform = UserProfileForm(data=request.POST,
                                instance=request.user.get_profile())

        if uform.is_valid() and pform.is_valid():
            uform.save()
            pform.save()
            messages.success(request, 'User udated.')
        else:
            messages.success(request, 'There was an error.')

    else:
        # create the form to edit the user
        uform = EditUserForm(instance=user)
        # also edit the profile of this user
        pform = UserProfileForm(instance=request.user.get_profile())

    ctx = {
        'user_form': uform,
        'profile_form': pform,
    }

    return render(request, 'accounts/profile.html', ctx)
def profile(request):
    # fetch user from db
    user = User.objects.get(pk=request.user.id)
    
    # save the forms
    if request.method == "POST":
        # create the form to edit the user
        uform = EditUserForm(data=request.POST, instance=user)
        # also edit the profile of this user
        pform = UserProfileForm(data=request.POST, instance=request.user.get_profile())

        if uform.is_valid() and pform.is_valid():
            uform.save()
            pform.save()
            messages.success(request, 'User udated.')
        else:
            messages.success(request, 'There was an error.')

    else:
        # create the form to edit the user
        uform = EditUserForm(instance=user)
        # also edit the profile of this user
        pform = UserProfileForm(instance=request.user.get_profile())
        
    ctx = {
        'user_form':uform,
        'profile_form':pform,
    }
    
    return render(request, 'accounts/profile.html', ctx)    
def edit_profile(request):
    """
    Show form with fields to edit user info data.
    
    """
    title = _("Edit your profile")
    user = request.user
    user_profile = UserProfile.objects.get(user=user)
    if request.method == 'POST':
        form_profile = EditUserProfileForm(request.POST, instance=user_profile)
        form_user = EditUserForm(request.POST, instance=user)
        if form_profile.is_valid() and form_user.is_valid():
            form_profile.save()
            form_user.save()
            return redirect("accounts_show_profile", user.username)

            
            
    else:
        # Without POST. Just display form
        form_profile = EditUserProfileForm(instance=user_profile)
        form_user = EditUserForm(instance=user)
    
    return render_to_response('accounts/edit_profile_form.html',
                              locals(),
                              context_instance=RequestContext(request))
Exemple #5
0
def edit(request):
    teacher = is_teacher(request.user)

    if teacher:
        custom_form = TeacherForm(
            request.POST or None,
            instance=Teacher.objects.get(user=request.user))
    else:
        custom_form = StudentForm(
            request.POST or None,
            instance=Student.objects.get(user=request.user))

    user_form = EditUserForm(request.POST or None, instance=request.user)

    if request.method == 'POST':
        if custom_form.is_valid() and user_form.is_valid():
            user = user_form.save()
            custom_form.save()
            messages.success(request, 'Configurações editadas com sucesso')

    return render(request, 'accounts/edit.html', {
        'form': user_form,
        'custom_form': custom_form,
        'is_teacher': teacher
    })
Exemple #6
0
def edit(request):
    """
    edit: this view is seposnsible for editing the users profile page
    """
    # if the request method is equal to POST
    if request.method == 'POST':
        user_form = EditUserForm(instance=request.user, data=request.POST)
        profile_form = EditProfileForm(instance=request.user.profile,
                                       data=request.POST,
                                       files=request.FILES)
        # if the user form and the profile form are both valid
        if user_form.is_valid() and profile_form.is_valid():
            # save the user form
            user_form.save()
            # save the profile form
            profile_form.save()
            # give the user a message telling them their profile was updated successfully
            messages.success(request, 'Profile updated successfully')
            # return the user to their profile page
            return redirect('user_profile')
        else:
            # otherwise we throw the user an error message telling them we could not update
            # their profile page, and they need to fix the relevant field
            messages.error(
                request, 'Sorry, but there was an error updating your profile')
    else:
        user_form = EditUserForm(instance=request.user)
        profile_form = EditProfileForm(instance=request.user.profile)
    # render the user form and profile form
    return render(request, 'accounts/edit_profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Exemple #7
0
def edit_profile(request):
    '''
    function to populate the details of the car
    '''
    title = "Egesha | Profile Form "
    current_user = request.user
    try:
        if request.method == 'POST':

            driver_form = EditDriver(request.POST, request.FILES)
            user_form = EditUserForm(request.POST, request.FILES)
            if driver_form.is_valid() and user_form.is_valid():

                driverdetails = driver_form.save(commit=False)
                userdetails = user_form.save(commit=False)

                driverdetails.user = current_user
                userdetails.user = current_user

                driverdetails.save()
                userdetails.save()
                return redirect('/driver/car-details')

        else:
            driver_form = EditDriver
            user_form = EditUserForm

    except ValueError:
        Http404

    return render(request, 'user/profileform.html', {
        "title": title,
        "driver_form": driver_form,
        "user_form": user_form
    })
Exemple #8
0
def own_profile(request):
    if request.method == "POST":
        form = EditUserForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
    else:
        form = EditUserForm(instance=request.user)
    return render_to_response("accounts/own_profile.html", 
        {'form': form},
        context_instance=RequestContext(request)
    )
Exemple #9
0
def user_edit(request, ids):
    user = get_user_model().objects.get(id=ids)
    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = EditUserForm(instance=user)
    return render(request, 'accounts/user_edit.html', locals())
def edit_user_profile(request):
    if request.method == 'POST':
        user_form = EditUserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return redirect(reverse('twitter_index'))
    else:
        user_form = EditUserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'accounts/edit_profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Exemple #11
0
def edit_profil(request):

    context = {}
    user = request.user

    # Valeurs par défaut des formulaires.
    user_form_initial = {
        'first_name': user.first_name,
        'last_name': user.last_name,
        'email': user.email
    }

    # Formulaire d'édition de l'utilisateur.
    user_form = EditUserForm(request.POST or None, initial=user_form_initial)
    context['user_form'] = user_form

    if user_form.is_valid():

        first, last = user_form.cleaned_data[
            'first_name'], user_form.cleaned_data['last_name']
        email = user_form.cleaned_data['email']

        if len(first) != 0:
            user.first_name = first

        if len(last) != 0:
            user.last_name = last

        if len(email) != 0:
            user.email = email

        user.save()

    # Formulaire d'édition du profil
    profil = _g(Profile, user=user)
    profil_form = EditProfileForm(request.POST,
                                  request.FILES,
                                  initial={'avatar': profil.avatar})
    context['profil_form'] = profil_form

    if profil_form.is_valid():
        file_name = profil_form.cleaned_data['avatar']

        handle_upload_file('users', file_name, request.FILES)
        profil.avatar = file_name
        profil.save()

    return render(request, "edit_profil.html", context)
Exemple #12
0
def edit_profile(request):
    if request.method == 'POST':
        UserForm = EditUserForm(request.POST, instance=request.user)
        ProfileForm = EditProfileForm(request.POST,
                                      instance=request.user.userprofile)
        if UserForm.is_valid() and ProfileForm.is_valid():
            UserForm.save()
            ProfileForm.save()
            return redirect('/account/profile/?p=' + request.user.username)
        else:
            return redirect('/account/profile/edit')
    else:
        UserForm = EditUserForm(instance=request.user)
        ProfileForm = EditProfileForm(instance=request.user.userprofile)
        args = {'userform': UserForm, 'profileform': ProfileForm}
        return render(request, 'accounts/edit_profile.html', args)
Exemple #13
0
def edit_profile(request):
    if request.method == 'POST':
        user_form = EditUserForm(request.POST, instance=request.user)
        profile_form = EditProfileForm(request.POST,
                                       instance=request.user.profile)

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return redirect(reverse('profile'))
    else:
        user = request.user
        user_form = EditUserForm(instance=request.user)
        profile_form = EditProfileForm(instance=request.user.profile)
        args = {'user_form': user_form, 'profile_form': profile_form}
        return render(request, 'editprofile.html', args)
Exemple #14
0
def view_account(request, user_id):
    try:
        view_user = User.objects.get(pk=user_id)
    except ObjectDoesNotExist:
        raise Http404
    
    if request.method == "POST":
        form = EditUserForm(request.POST, instance=view_user)
        if form.is_valid():
            form.save()
    else:
        form = EditUserForm(instance=view_user)
    
    return render_to_response("accounts/view.html",
                                {"view_user": view_user, "form": form,},
                                context_instance=RequestContext(request))
Exemple #15
0
def edit(request):
    teacher = is_teacher(request.user)

    if teacher:
        custom_form = TeacherForm(request.POST or None, instance=Teacher.objects.get(user=request.user))
    else:
        custom_form = StudentForm(request.POST or None, instance=Student.objects.get(user=request.user))

    user_form = EditUserForm(request.POST or None, instance=request.user)

    if request.method == "POST":
        if custom_form.is_valid() and user_form.is_valid():
            user = user_form.save()
            custom_form.save()
            messages.success(request, "Configurações editadas com sucesso")

    return render(request, "accounts/edit.html", {"form": user_form, "custom_form": custom_form, "is_teacher": teacher})
Exemple #16
0
def edit_profile(request):
    if request.method == 'POST':
        user_form = EditUserForm(request.POST, instance = request.user)
        profile_form = EditProfileForm(request.POST, instance = request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, ('Your profile was successfully updated!'))
            return redirect('/account/userProfile.html')
        return HttpResponseRedirect('/')
    else:
        user_form = EditUserForm(request.POST, instance = request.user)
        profile_form = EditProfileForm(request.POST, instance = request.user.profile)
        return render(request, 'webapp/account/editProfile.html', {
            'user_edit_form': user_form,
            'profile_edit_form': profile_form, 
            'base_template': loginTemplate
        })
Exemple #17
0
def user_edit(request, ids):
    user = get_user_model().objects.get(id=ids)
    ldap_name = user.ldap_name
    request_user = UserInfo.objects.get(username=request.user.username)
    if str(request_user.role) not in ['ops'] and request_user.username != 'admin':
        if user.username != request_user.username:
            return HttpResponse(u"<font color=red>不能编辑此用户!</font>")

    if str(request_user.role) in ['ops'] and user.username == 'admin':
        return HttpResponse(u"<font color=red>不能编辑admin!</font>")

    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = EditUserForm(instance=user)
    return render(request, 'accounts/user_edit.html', locals())
Exemple #18
0
def profile_edit(request):
    if request.method == 'POST':
        u_form = EditUserForm(request.POST, instance=request.user)
        p_form = EditProfileForm(request.POST, request.FILES, instance=request.user.profileuser)

        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            profile = request.user.profileuser
            p_form.user = profile
            p_form.save()
            return redirect('user profile', pk=request.user.pk)
    else:
        u_form = EditUserForm(instance=request.user)
        p_form = EditProfileForm(instance=request.user.profileuser)

    context = {
        'u_form': u_form,
        'p_form': p_form,
    }

    return render(request, 'registration/edit_profile.html', context)
Exemple #19
0
def edit_profile(request):
    content = {}
    profile = request.user.get_username()
    if request.method == 'POST':
        form2 = EditUserForm(request.POST, instance=request.user)
        form = EditUserProfileForm(request.POST,
                                   request.FILES,
                                   instance=request.user.userprofile)
        content['form'] = form
        content['form2'] = form2

        if form.is_valid() and form2.is_valid():
            new_user = form.save()
            new_user2 = form2.save()
            return render(request, 'profile.html', content)

    else:
        form = EditUserProfileForm(instance=request.user)
        form2 = EditUserForm(instance=request.user)
        content['form'] = form
        content['form2'] = form2
        return render(request, 'edit_profile.html', content)
Exemple #20
0
def edit_profile(request):
    if request.user.is_authenticated:
        context_dict = {}
        if request.method == "POST":
            form_basic = EditUserForm(request.POST, instance=request.user)
            form_add = EditProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user.profile)
            if form_basic.is_valid() and form_add.is_valid():
                form_basic.save()
                form_add.save()
                context_dict["ep_success"] = "Profile changed successsfully"
            else:
                context_dict["ep_error"] = "Invalid data received"
        else:
            form_basic = EditUserForm(instance=request.user)
            form_add = EditProfileForm(instance=request.user.profile)
        context_dict["form_basic"] = form_basic
        context_dict["form_add"] = form_add
        return render(request, "accounts/edit_profile.html", context_dict)
    else:
        return HttpResponseRedirect('/login')
Exemple #21
0
def edit_profile(request):
    user_form = EditUserForm(instance=request.user)
    profile_form = ProfileForm(instance=request.user.userprofile)
    form_list = [user_form, profile_form]
    object_name = {'form_list': form_list}

    if request.method == 'POST':
        user_form = EditUserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST,
                                   instance=request.user.userprofile)

        if all([user_form.is_valid(), profile_form.is_valid()]):
            user_form.save()
            profile_form.save()
            request.session['updated'] = True

            return redirect('accounts:view_profile')

        form_list = [user_form, profile_form]
        object_name = {'form_list': form_list}

    return render(request, 'accounts/edit_profile.html', object_name)
Exemple #22
0
def update_profile(request):
    user = User.objects.get(email=request.user.email)
    if request.method == 'POST':
        edit_user_form = EditUserForm(request.POST, instance=request.user)
        user_profile_form = EditUserProfileForm(request.POST,
                                                instance=request.user.uprofile)
        if edit_user_form.is_valid() and user_profile_form.is_valid():
            edit_user_form.save()
            user_profile_form.save()
            if user.uprofile.have_paid is True and user.uprofile.want_to_rent is True:
                return redirect(reverse("profile"))
            elif user.uprofile.have_paid is False and user.uprofile.want_to_rent is True:
                return redirect('checkout')
            else:
                return redirect(reverse("profile"))
    else:
        edit_user_form = EditUserForm(instance=request.user)
        user_profile_form = EditUserProfileForm(instance=request.user.uprofile)
    args = {
        'form': edit_user_form,
        'formUserProfile': user_profile_form,
        'user': user
    }
    return render(request, 'update_profile.html', args)