Exemplo n.º 1
0
def updateprofile(request):
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST)
        if profile_form.is_valid():
            try:
                userprofile_object = UserProfile.objects.get(user=request.user)
                userprofile_object.phone_number = profile_form.cleaned_data[
                    'phone_number']
                userprofile_object.save()
                user_object = User.objects.get(pk=request.user.id)
                user_object.first_name = profile_form.cleaned_data[
                    'first_name']
                user_object.last_name = profile_form.cleaned_data['last_name']
                user_object.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Your Profile Updated Successfully"
                )  # except IntegrityError as error:  # messages.add_message(request, messages.ERROR, error)
            except Exception as e:
                messages.add_message(request, messages.ERROR, e)
            return redirect("/accounts/dashboard/")
        else:
            messages.add_message(request, messages.ERROR, profile_form.errors)
        return redirect("/accounts/dashboard/")
    else:
        messages.add_message(request, messages.ERROR,
                             'You Should USE POST METHOD IN REQUEST')
        return redirect("/accounts/dashboard/")
Exemplo n.º 2
0
def setting(request):
    user = request.user
    username = user.username
    if request.method == 'POST':
        form = ProfileForm(request.POST)

        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            user.save()

            message = '修改成功'
            messages.add_message(request, messages.SUCCESS, message)

            new_user = authenticate(username=username, password=new_password)
            login(request, new_user)
    else:
        form = ProfileForm(instance=user)

    return render(request, 'web/setting.html', {'form': form})
Exemplo n.º 3
0
def myprofile(request):
    if request.POST:
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            profile_current = form.save(commit=False)
            profile_current.user = request.user
            profile_current.save()
    else:
        form = ProfileForm()
    user = request.user
    if Profile.objects.filter(user=user):
        profile = Profile.objects.get(user=user)
    else:
        profile = None
    object_list = Article.objects.filter(user=user)
    topic_list = list(set([x.topic for x in object_list.all()]))
    print(topic_list)
    return render(
        request, "myprofile.html", {
            "object": profile,
            "topic_list": topic_list,
            "object_list": object_list,
            "form": form
        })