def profileGet(request): profiles = Profile.objects.filter(user=request.user) imageurl = 'forum/profiles/Profil.jpg' if profiles: profile = profiles[0] form = ProfileForm( initial={ 'pseudo': profile.pseudo, 'firstname': profile.firstname, 'lastname': profile.lastname, 'birthdate': profile.birthdate }) imageurl = profile.image.url if profile.image else 'forum/profiles/Profil.jpg' context = {'pagetitle': 'Profil'} else: form = ProfileForm() context = {'pagetitle': 'Première connexion', 'noprofile': True} context['imageurl'] = imageurl context['form'] = form context['background_color'] = 'white' return myRender(request, "profile.html", context)
def profilePost(request): user = request.user form = ProfileForm(request.POST, request.FILES) if form.is_valid(): profiles = Profile.objects.filter(user=user) context = { 'pagetitle': 'Profil', 'success': "Votre profil a bien été mis à jour !", 'form': form } if profiles.exists(): profile = profiles[0] profile.pseudo = form.cleaned_data['pseudo'] profile.firstname = form.cleaned_data['firstname'] profile.lastname = form.cleaned_data['lastname'] profile.birthdate = form.cleaned_data['birthdate'] if form.cleaned_data['image'] is not None: form.cleaned_data[ 'image'].name = profile.pseudo + '.' + form.cleaned_data[ 'image'].name.split('.')[1].lower() profile.image = form.cleaned_data['image'] logger.debug('Image uploaded : ' + str(profile.image)) profile.save() logger.debug(profile.pseudo + ' edited his/her profile') else: if Profile.objects.filter( pseudo=form.cleaned_data['pseudo']).exists(): context = { 'pagetitle': 'Première connexion', 'error': "Le pseudo est déjà utilisé", 'form': form } return myRender(request, "profile.html", context) else: profile = Profile.objects.create_profile( user, form.cleaned_data['pseudo'], form.cleaned_data['firstname'], form.cleaned_data['lastname'], form.cleaned_data['birthdate'], form.cleaned_data['image']) if profile.image: context['imageurl'] = '/' + profile.image.url else: context['imageurl'] = '/forum/profiles/Profil.jpg' return myRender(request, "profile.html", context) else: return redirect("profile")
def profile(request, pk): profile = UserProfile.objects.get(user=pk) img = None if request.method == "POST": form = ProfileForm(request.POST, request.FILES) if form.is_valid(): profile.avatar = request.FILES['avatar']; profile.save() else: form = ProfileForm() if profile.avatar: img = "/media/" + profile.avatar.name return render(request, 'profile.html',{ "form":form, 'img':img })
def profilePost(request): user = request.user form = ProfileForm(request.POST, request.FILES) if form.is_valid(): profiles = Profile.objects.filter(user=user) context = {'pagetitle': 'Profil', 'success': "Votre profil a bien été mis à jour !", 'form': form} if profiles.exists(): profile = profiles[0] profile.pseudo = form.cleaned_data['pseudo'] profile.firstname = form.cleaned_data['firstname'] profile.lastname = form.cleaned_data['lastname'] profile.birthdate = form.cleaned_data['birthdate'] if form.cleaned_data['image'] is not None: form.cleaned_data['image'].name = profile.pseudo + '.' + form.cleaned_data['image'].name.split('.')[1].lower() profile.image = form.cleaned_data['image'] logger.debug('Image uploaded : ' + str(profile.image)) profile.save() logger.debug(profile.pseudo + ' edited his/her profile') else: if Profile.objects.filter(pseudo=form.cleaned_data['pseudo']).exists(): context = {'pagetitle': 'Première connexion', 'error': "Le pseudo est déjà utilisé", 'form': form} return myRender(request, "profile.html", context) else: profile = Profile.objects.create_profile(user, form.cleaned_data['pseudo'], form.cleaned_data['firstname'], form.cleaned_data['lastname'], form.cleaned_data['birthdate'], form.cleaned_data['image']) if profile.image: context['imageurl'] = '/' + profile.image.url else: context['imageurl'] = '/forum/profiles/Profil.jpg' return myRender(request, "profile.html", context) else: return redirect("profile")