コード例 #1
0
def profile_update(request, **kwargs):

    if not request.user.is_authenticated():
        messages.error(request, "You must login to edit your profile")
        return redirect("login")

    template_name = "profile_update.html"

    try:
        user = User.objects.get(id=kwargs['user_id'])
    except ObjectDoesNotExist:
        messages.error(request, 'Sorry, this user is not in our database')
        return redirect("home")

    user_profile = UserProfile.objects.get(user=user)

    form = ProfileUpdateForm(instance=user_profile)

    if not request.method == "POST":
        return render(request, template_name, {'form': form})

    form = ProfileUpdateForm(request.POST,
                             request.FILES,
                             instance=user_profile)

    if not form.is_valid():
        return render(request, template_name, {'form': form})

    user_profile.full_name = form.cleaned_data['full_name']
    user_profile.address = form.cleaned_data['address']
    user_profile.phone = form.cleaned_data['phone']
    user_profile.avatar = form.cleaned_data['avatar']
    user_profile.save()

    return redirect("profile", user.id)
コード例 #2
0
def profile_update(request):
    user = request.user
    form = ProfileUpdateForm(request.POST or None, instance=user)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            print("POST sending you back HOME")
            return HttpResponseRedirect(reverse('articles:home'))
        else:
            print("error")
    else:
        print("GET profile.html")
    context = {
        "profile_updateform": form,
    }
    return render(request, 'account/profile_update.html', context)
コード例 #3
0
ファイル: manage.py プロジェクト: rafiulgits/mylocale
def update(request):
    context = {}
    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, user=request.user)
        if form.is_valid():
            request.user.name = form.cleaned_data['name']
            request.user.email = form.cleaned_data['email']
            request.user.gender = form.cleaned_data['gender']
            request.user.save()

            return redirect('/account/')

    form = ProfileUpdateForm(user=request.user)

    context['form'] = form

    return render(request, 'account/manage/update.html', context)
コード例 #4
0
def update_profile(request):
    instance = get_object_or_404(Account, id=request.user.id)
    user = ProfileUpdateForm(instance=request.user)
    account = AccountUpdateForm(instance=request.user)

    if request.method == 'POST':
        user = ProfileUpdateForm(request.POST or None, instance=instance)
        account = AccountUpdateForm(request.POST or None,
                                    request.FILES or None,
                                    instance=instance)

        if user.is_valid() and account.is_valid():
            user.save()
            account.save()
            messages.success(request, _('Edits Saved.'))
        else:
            messages.error(request, _('Please Correct any error down below'))
    context = {
        'forms': [
            {
                'form': user,
                'title': _('Personal Information')
            },
            {
                'form': account,
                'title': ''
            },
        ]
    }
    return render(request, 'settings/update_profile.html', context)
コード例 #5
0
ファイル: views.py プロジェクト: mmfnaja/baar
def myaccount(request):
    template_name = 'profile.html'
    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, instance=request.user.staff)
        if form.is_valid():
            form.save()
            return redirect('/myaccount')
    else:
        form = ProfileUpdateForm(instance=request.user.staff)
    context = {'form': form}
    return render(request, template_name, context)
コード例 #6
0
def edit_profile(request):
    user = request.user
    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            return redirect('account:profile')
        else:
            ProfileUpdateForm(instance=user)
            return redirect('account:edit_profile')

    form = ProfileUpdateForm(instance=user)

    context = {
        'form': form,
        'user': user,
    }
    return render(request, 'registration/edit_profile.html', context=context)
コード例 #7
0
def profile(request):
    if request.method == 'POST':
        p_form = ProfileUpdateForm(request.POST,
            request.FILES, instance=request.user)
        if p_form.is_valid():
            p_form.save()

            #Setup for deleting old image file.  TODO: Re-write this process.
            #Update profileimage field in the database
            request.user.profileimage = request.user.image.path
            p_form.save()
            messages.success(request, f'Your account has been updated!')
            return redirect('profile')
    else:
        p_form = ProfileUpdateForm(instance=request.user)
        fams = Family.objects.all()
        youts = Youth.objects.all()

        obj = None

        try:
            obj = CheckInQr.objects.filter(creatorid=request.user.id).latest('createddate')
        except Exception as e:
            print(e)
        
        if obj is None:
            obj = {
                'code':"newcode",
                'qr_code':"",
                'completed':"True"
            }        

    context = {
        'obj' : obj,
        'p_form': p_form,
        'fams': fams,
        'youts': youts
    }
    return render(request, 'checkin/profile.html', context)
コード例 #8
0
def profile_view(request):
    if request.method == 'POST':
        u_form = AccountUpdateForm(request.POST, instance=request.user)
        p_form = ProfileUpdateForm(request.POST,
                                   request.FILES,
                                   instance=request.user.profile)
        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            return redirect('profile')

    else:
        u_form = AccountUpdateForm(instance=request.user)
        p_form = ProfileUpdateForm(instance=request.user.profile)

    context = {'u_form': u_form, 'p_form': p_form}
    return render(request, 'account/profile.html', context)
コード例 #9
0
ファイル: views.py プロジェクト: xitiz112/blog
def profile(request):
    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance=request.user)
        p_form = ProfileUpdateForm(request.POST,
                                   request.FILES,
                                   instance=request.user.profile)
        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, f'your account has been updated')
            return redirect('profile')
    else:
        u_form = UserUpdateForm(instance=request.user)
        p_form = ProfileUpdateForm(instance=request.user.profile)

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

    templates_name = 'account/profile.html'
    return render(request, templates_name, context)
コード例 #10
0
def barrister_personal(request):
    profile, created = Profile.objects.get_or_create(user=request.user)
    form = ProfileUpdateForm(instance=profile)

    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, request.FILES, instance=profile)
        if form.is_valid():
            # if request.POST.get('image-clear'):
            #     print("clear image")
            #     form.image = None
            form.save()

    context = {
        'form': form,
    }

    return render(request,
                  'barrister/barrister-personal.html',
                  context=context)
コード例 #11
0
def update(request):
    context = {}
    user = request.user

    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, user=user)
        if form.is_valid():
            if form.is_new_email():
                user = form.save(commit=False)
                user.is_active = False
                user.save()
                verify_email(request, user)
                return render(request, 'account/auth/verify.html', {})

            user = form.save()
            return redirect('/account/')
    else:
        form = ProfileUpdateForm(user=request.user)

    token = get_api_token(request)
    context['token'] = token
    context['form'] = form

    return render(request, 'account/manage/update.html', context)
コード例 #12
0
ファイル: profile.py プロジェクト: lisianthuss116/Mindzzle
def profile(request, username):
    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance=request.user)
        p_form = ProfileUpdateForm(request.POST,
                                   request.FILES,
                                   instance=request.user.profile)

        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, f'Your Account Has Been Updated!')
            return redirect('account:profile', username=username)

    else:
        u_form = UserUpdateForm(instance=request.user)
        p_form = ProfileUpdateForm(instance=request.user.profile)

    context = {
        'profile': Profile.objects.get(user_account_name=request.user.id),
        'u_form': u_form,
        'p_form': p_form
    }
    return render(request, 'profile_page/profile.html', context)