Exemplo n.º 1
0
 def post(self, request, username):
     if not request.user.is_anonymous():
         active_user_id = request.user.id
         active_user = User.objects.filter(id=active_user_id)[0]
         if User.objects.filter(username=username):
             profiled_user = User.objects.filter(username=username)[0]
             viewed_user_profile = UserProfile.objects.filter(user=profiled_user)[0]
             if active_user_id == profiled_user.id:
                 updated_form = UserProfileForm(request.POST)
                 updated_extended_form = UserExtendedProfileForm(request.POST,request.FILES)
                 if updated_form.is_valid() and updated_extended_form.is_valid():
                     profiled_user.first_name = updated_form.cleaned_data.get('first_name')
                     profiled_user.last_name = updated_form.cleaned_data.get('last_name')
                     profiled_user.email = updated_form.cleaned_data.get('email')
                     profiled_user.save()
                     viewed_user_profile.about = updated_extended_form.cleaned_data.get('about')
                     if updated_extended_form.cleaned_data.get('picture') is not None:
                         viewed_user_profile.picture = updated_extended_form.cleaned_data.get('picture')
                     viewed_user_profile.save()
                     return redirect('interface:profile', username = profiled_user.username)
         return redirect('interface:profile', username = profiled_user.username)
     return redirect('interface:login')
Exemplo n.º 2
0
 def post(self, request, username):
     empty_profile_form = UserProfileForm
     empty_extended_form = UserExtendedProfileForm
     if request.session.get('_auth_user_id'):
         active_user_id = int(request.session.get('_auth_user_id'))
         active_user = User.objects.filter(id=active_user_id)[0]
         if User.objects.filter(username=username):
             profiled_user = User.objects.filter(username=username)[0]
             viewed_user_profile = UserProfile.objects.filter(user=profiled_user)[0]
             if active_user_id == profiled_user.id:
                 updated_form = UserProfileForm(request.POST)
                 updated_extended_form = UserExtendedProfileForm(request.POST,request.FILES)
                 if updated_form.is_valid() and updated_extended_form.is_valid():
                     profiled_user.first_name = updated_form.cleaned_data.get('first_name')
                     profiled_user.last_name = updated_form.cleaned_data.get('last_name')
                     profiled_user.save()
                     viewed_user_profile.about = updated_extended_form.cleaned_data.get('about')
                     viewed_user_profile.picture = updated_extended_form.cleaned_data.get('picture')
                     viewed_user_profile.save()
                 return redirect('/users/{}/'.format(profiled_user))
             return render(request, self.template, {'error':'Invalid input; please try again','user':profiled_user,'profile_form':empty_profile_form,'extended_profile_form':empty_extended_form})
     return redirect('/game/index/')