def updateAthleteProfile(request, pk): perm = general_methods.control_access(request) if not perm: logout(request) return redirect('accounts:login') user = User.objects.get(pk=pk) directory_user = Athlete.objects.get(user=user) person = Person.objects.get(pk=directory_user.person.pk) communication = Communication.objects.get( pk=directory_user.communication.pk) user_form = DisabledUserForm(request.POST or None, instance=user) person_form = DisabledPersonForm(request.POST or None, request.FILES or None, instance=person) communication_form = DisabledCommunicationForm(request.POST or None, instance=communication) password_form = SetPasswordForm(request.user, request.POST) if request.method == 'POST': if user_form.is_valid() and communication_form.is_valid( ) and person_form.is_valid() and password_form.is_valid(): user.username = user_form.cleaned_data['email'] user.first_name = user_form.cleaned_data['first_name'] user.last_name = user_form.cleaned_data['last_name'] user.email = user_form.cleaned_data['email'] user.set_password(password_form.cleaned_data['new_password1']) user.save() person_form.save() communication_form.save() password_form.save() messages.success(request, 'Sporcu Başarıyla Güncellenmiştir.') return redirect('wushu:sporcu-profil-guncelle') else: messages.warning(request, 'Alanları Kontrol Ediniz ') return render( request, 'sporcu/sporcu-profil-guncelle.html', { 'user_form': user_form, 'communication_form': communication_form, 'person_form': person_form, 'password_form': password_form })
def updateProfile(request): perm = general_methods.control_access(request) if not perm: logout(request) return redirect('accounts:login') user = request.user user_form = DisabledUserForm(request.POST or None, instance=user) password_form = SetPasswordForm(request.user, request.POST) if request.method == 'POST': if password_form.is_valid(): user.set_password(password_form.cleaned_data['new_password1']) user.save() update_session_auth_hash(request, user) messages.success(request, 'Şifre Başarıyla Güncellenmiştir.') return redirect('wushu:admin-profil-guncelle') else: messages.warning(request, 'Alanları Kontrol Ediniz') return render(request, 'admin/admin-profil-guncelle.html', { 'user_form': user_form, 'password_form': password_form })
def updateClubPersonsProfile(request): perm = general_methods.control_access(request) if not perm: logout(request) return redirect('accounts:login') user = request.user club_user = SportClubUser.objects.get(user=user) person = Person.objects.get(pk=club_user.person.pk) communication = Communication.objects.get(pk=club_user.communication.pk) user_form = DisabledUserForm(request.POST or None, instance=user) person_form = DisabledPersonForm(request.POST or None, request.FILES or None, instance=person) communication_form = DisabledCommunicationForm(request.POST or None, instance=communication) club_form = DisabledSportClubUserForm(request.POST or None, instance=club_user) password_form = SetPasswordForm(request.user, request.POST) if request.method == 'POST': data = request.POST.copy() data['bloodType'] = "AB Rh+" data['gender'] = "Erkek" person_form = DisabledPersonForm(data) if person_form.is_valid() and password_form.is_valid(): if len(request.FILES) > 0: person.profileImage = request.FILES['profileImage'] person.save() messages.success( request, 'Profil Fotoğrafı Başarıyla Güncellenmiştir.') user.set_password(password_form.cleaned_data['new_password2']) user.save() update_session_auth_hash(request, user) messages.success(request, 'Şifre Başarıyla Güncellenmiştir.') return redirect('wushu:kulup-uyesi-profil-guncelle') elif person_form.is_valid() and not password_form.is_valid(): if len(request.FILES) > 0: person.profileImage = request.FILES['profileImage'] person.save() messages.success( request, 'Profil Fotoğrafı Başarıyla Güncellenmiştir.') else: messages.warning(request, 'Alanları Kontrol Ediniz') return redirect('wushu:kulup-uyesi-profil-guncelle') elif not person_form.is_valid() and password_form.is_valid(): user.set_password(password_form.cleaned_data['new_password2']) user.save() update_session_auth_hash(request, user) messages.success(request, 'Şifre Başarıyla Güncellenmiştir.') return redirect('wushu:kulup-uyesi-profil-guncelle') else: messages.warning(request, 'Alanları Kontrol Ediniz.') return redirect('wushu:kulup-uyesi-profil-guncelle') return render( request, 'kulup/kulup-uyesi-profil-guncelle.html', { 'user_form': user_form, 'communication_form': communication_form, 'person_form': person_form, 'password_form': password_form, 'club_form': club_form })