Esempio n. 1
0
 def post(self, request, *args, **kwargs):
     user_update_form = UserUpdateForm(request.POST)
     if user_update_form.is_valid():
         id = kwargs.get('id')
         user = User.objects.get(pk=id)
         user.username = user_update_form.cleaned_data.get('username')
         user.first_name = user_update_form.cleaned_data.get('first_name')
         user.last_name = user_update_form.cleaned_data.get('last_name')
         user.email = user_update_form.cleaned_data.get('email')
         user.is_superuser = True if request.POST.get(
             'is_superuser') == 1 else False
         user.is_staff = True if request.POST.get(
             'is_staff') == 1 else False
         user.save()
         group = request.POST.getlist('group')
         for g in user.groups.all():
             user.groups.remove(g)
             user.save()
         for g in group:
             user.groups.add(Group.objects.get(pk=g))
             user.save()
         return HttpResponseRedirect(reverse('user_list'))
     else:
         self.context = {
             'user_update_form': user_update_form,
             'errors': user_update_form.errors
         }
         return render(request, 'account/user/user_update.html',
                       self.context)
Esempio n. 2
0
def account_update_view(request):
    context = {}

    # code for update acount
    if not request.user.is_authenticated:
        return redirect("login")

    profile = get_object_or_404(Profile, user=request.user)

    if request.POST:
        form = UserUpdateForm(request.POST, instance=request.user)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.save()
            form.initial = {
                "name": request.POST['name'],
                "contact": request.POST['contact'],
                "date_of_birth": request.POST['date_of_birth'],
            }

            context['message'] = "Your Account is Updated"
    else:
        form = UserUpdateForm(
            initial={
                "name": profile.name,
                "contact": profile.contact,
                "date_of_birth": profile.date_of_birth,
                "image": profile.image,
            })
    context['update_form'] = form

    return render(request, 'account/acount.html', context)
Esempio n. 3
0
def account(request):
    if request.method == 'GET':
        form = UserUpdateForm(instance=request.user)
    else:
        form = UserUpdateForm(request.POST, instance=request.user)
        
        if form.is_valid():
            ins = request.user
            ins.first_name = form.cleaned_data['first_name']
            ins.last_name = form.cleaned_data['last_name']
            ins.username = form.cleaned_data['username']
            ins.email = form.cleaned_data['email']
            
            if form.cleaned_data['password']:
                ins.set_password(form.cleaned_data['password'])
                
            ins.save()
            
    return {'form': form}
Esempio n. 4
0
def barrister_account(request):
    form = UserUpdateForm(instance=request.user)

    if request.method == "POST":
        form = UserUpdateForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()

    context = {
        'form': form,
    }

    return render(request, 'barrister/barrister-account.html', context=context)
Esempio n. 5
0
 def get(self, request, *args, **kwargs):
     id = kwargs.get('id')
     user = User.objects.get(pk=id)
     user_update_form = UserUpdateForm(model_to_dict(user))
     group = Group.objects.all()
     self.context = {
         'user_update_form': user_update_form,
         'user': user,
         'group': [{
             'id': g.id,
             'text': g.name
         } for g in group],
         'group_id_list': [g.id for g in user.groups.all()]
     }
     return render(request, 'account/user/user_update.html', self.context)
Esempio n. 6
0
def myprofile_edit(request):
    user = request.user
    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance=request.user)
        try:
            if user.driverprofile:
                role = 'driver'
                dp = DriverProfile.objects.get(user=user)
                p_form = DriverProfileUpdateForm(request.POST, instance=dp)
        except:
            role = 'company'
            cp = CompanyProfile.objects.get(user=user)
            p_form = CompanyProfileUpdateForm(request.POST, instance=cp)

        if p_form.is_valid() and u_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, ('Profil Güncelleme Tamamlandı!'))
            return redirect('myprofile')

        messages.error(request, ('Hata! Boş alan bırakmayınız!'))
    else:
        u_form = UserUpdateForm(instance=request.user)
        try:
            if user.companyprofile:
                role = 'company'
                cp = CompanyProfile.objects.get(user=user)
                p_form = CompanyProfileUpdateForm(instance=cp)

            return render(request,
                          'account/myprofileC_edit.html',
                          context={
                              'p_form': p_form,
                              'u_form': u_form
                          })
        except:
            role = 'driver'
            dp = DriverProfile.objects.get(user=user)
            p_form = DriverProfileUpdateForm(instance=dp)

    return render(request,
                  'account/myprofileD_edit.html',
                  context={
                      'p_form': p_form,
                      'u_form': u_form
                  })
def JobseekerProfileUpdateView(request):
    if request.method == 'POST':
        profile_form = JobseekerProfileUpdateForm(
            request.POST,
            request.FILES,
            instance=request.user.jobseekerprofile)
        if profile_form.is_valid():
            request.user.username = request.POST['username']
            request.user.save()
            profile_form.save()

            messages.success(request, f'Your Accounted has been updated!')
            return redirect('/')

    else:
        username_form = UserUpdateForm(instance=request.user)
        profile_form = JobseekerProfileUpdateForm(
            instance=request.user.jobseekerprofile)

    contex = {'u_form': username_form, 'p_form': profile_form}
    return render(request, 'account/Jobseeker/add_profile_detail.html', contex)
Esempio n. 8
0
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)
Esempio n. 9
0
def profile(request):
    if request.method == 'POST':
        uuser = UserUpdateForm(request.POST, instance=request.user)
        uprofile = ProfileUpadteForms(request.POST,
                                      request.FILES,
                                      instance=request.user.profile)

        if uuser.is_valid() and uprofile.is_valid():
            uuser.save()
            uprofile.save()
            messages.success(request, f'Account has been updated.')
            return redirect('profile')
    else:
        uuser = UserUpdateForm(instance=request.user)
        uprofile = ProfileUpadteForms(instance=request.user.profile)

    return render(request, 'profile.html', {
        'uuser': uuser,
        'uprofile': uprofile
    })
Esempio n. 10
0
def EmployerProfileUpdateView(request):
    if request.method == 'POST':
        profile_form = EmployerProfileUpdateForm(
            request.POST,
            request.FILES,
            instance=request.user.employerrprofile)
        if profile_form.is_valid():
            request.user.username = request.POST['username']
            request.user.save()
            profile_form.save()

            messages.success(request, f'Your Accounted has been updated!')
            return redirect('employer:employer_dashboard',
                            username=request.user.username)

    else:
        username_form = UserUpdateForm(instance=request.user)
        profile_form = EmployerProfileUpdateForm(
            instance=request.user.employerrprofile)

    contex = {'u_form': username_form, 'p_form': profile_form}
    return render(request, 'account/Employer/update_profile_detail.html',
                  contex)
Esempio n. 11
0
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)
Esempio n. 12
0
def update_profile(request):
    updated = False

    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance=request.user)
        p_form = UserProfileInfoUpdateForm(
            request.POST, request.FILES, instance=request.user.userprofileinfo)

        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()

            # return HttpResponseRedirect(reverse('index'))

        updated = True

    else:
        u_form = UserUpdateForm(request.POST, instance=request.user)
        p_form = UserProfileInfoUpdateForm(
            request.POST, instance=request.user.userprofileinfo)

    context = {'u_form': u_form, 'p_form': p_form, "updated": updated}
    return render(request, 'account/profile_update.html', context)
Esempio n. 13
0
def profile_view(request, name):
    user = request.user
    board_announces = Announce.objects.all().filter(sender=user)
    inbox_announces = []
    chat_rooms = []
    for announcet in Announce.objects.all():
        if user in announcet.receiver.all() and announcet.general == False:
            inbox_announces.append(announcet)
    for room in Room.objects.all():
        if user == room.me or user == room.other:
            chat_rooms.append(room)

    update_form = UserUpdateForm(instance=user)
    pwd_form = PasswordChangeForm(request.user)

    _form = request.POST.get('form_name')
    if _form == 'logout_form':
        # Logging out user
        user = request.user
        logout(request)
        messages.success(request, f'User {user} is logged out')
        return redirect('home')
    if _form == 'update_form':
        # Updating user
        update_form = UserUpdateForm(request.POST,
                                     request.FILES,
                                     instance=user)
        if update_form.is_valid():
            user = update_form.save()
            user.category = request.POST.get('Catgy')
            user.student = request.POST.get('Std_cat')
            user.regNo = request.POST.get('Reg')
            user.lecturer = request.POST.get('Lect_cat')
            user.staffId = request.POST.get('Staff')
            user.college_council = request.POST.get('Col_council_cat')
            user.academic_council = request.POST.get('Acad_council_cat')
            user.school_council = request.POST.get('Skl_council_cat')
            user.department_council = request.POST.get('Dep_council_cat')
            user.school = request.POST.get('Skl')
            user.department = request.POST.get('Depart')
            user.level = request.POST.get('Lv')
            user.save()
            messages.success(request,
                             f'Account updated succesfully for {user} ')
            return redirect('home')
        else:
            messages.warning(
                request,
                f'Account not updated!...Correct the errors on the form')
    if _form == 'pwd_form':
        # Changing password
        pwd_form = PasswordChangeForm(request.user, request.POST)
        if pwd_form.is_valid():
            user = pwd_form.save()
            update_session_auth_hash(request, user)
            messages.success(request, f'Your password was . updated!')
            return redirect('change_password')
        else:
            messages.warning(request, f'Please correct the error!...')
    context = {
        'inbox': len(inbox_announces),
        'board': len(board_announces),
        'chats': len(chat_rooms),
        'categories': Category.objects.all(),
        'update_form': update_form,
        'pwd_form': pwd_form,
        'user': user,
        'profile': 1,
        'cat': user.category
    }

    student_cats = Student_category.objects.all()
    lecturer_cats = Lecturer_category.objects.all()
    col_council_cats = College_council.objects.all()
    skl_council_cats = School_council.objects.all()
    dep_council_cats = Department_council.objects.all()
    acad_council_cats = Academic_council.objects.all()
    schools = School.objects.all()
    ctx2 = {
        'student_cats': student_cats,
        'lecturer_cats': lecturer_cats,
        'col_council_cats': col_council_cats,
        'dep_council_cats': dep_council_cats,
        'skl_council_cats': skl_council_cats,
        'acad_council_cats': acad_council_cats,
        'schools': schools
    }
    context.update(ctx2)
    return render(request, 'profile.html', context)