def profile_view(request): # TODO: Combine all profiles on this page hackathon = Hackathon.objects.first() try: profile = request.user.profile except: raise Http404("No profile") form = ProfileForm(instance=profile) notifications = [] if request.method == "POST": form = ProfileForm(request.POST, instance=profile) if form.is_valid(): form.save() notifications.append("Saved") # form.send_emails(self.request) when editable context = { "tab_title": "Profile", "hackathon": hackathon, "forms": [("", form)], "more_notifications": notifications, "show_subs": True, "show_email": True, } if hasattr(request.user, "iquhack_profile"): context.update({ "switch_to_label": "Edit iQuHACK Profile", "switch_to": reverse("iquhack:profile") }) return render(request, "members/profile.html", context)
def profile(request): if request.method == 'POST': form = ProfileForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() form = ProfileForm(instance=request.user) return render(request, 'members/profile.html', context={'form': form})
def edit_profile(request): profile=request.user.get_profile() if request.method=='POST': form=ProfileForm(request.POST, instance=profile) if form.is_valid(): form.save() return redirect('/member/home/') else: form=ProfileForm(instance=profile) return render(request,'members/edit_profile.html',{'form':form,'profile':profile})
def profile(request): profile = Profile.objects.get(user=request.user) if request.method == 'POST': # If the form has been submitted... if request.POST['submit'] == 'profileSubmit':#Si une reponse a ete envoyee form = ProfileForm(request.POST, request.FILES) # A form bound to the POST data if form.is_valid(): # All validation rules pass post = form.save(commit=False) if (post.avatar == ''): post.avatar = profile.avatar post.user = request.user post.email = profile.email post.points = profile.points post.status = profile.status post.views = profile.views post.nb_likes = profile.nb_likes post.nb_questions = profile.nb_questions profile.delete() post.save() profile = Profile.objects.get(user=request.user) request.session['profile_user'] = profile followedquestions = [] follows = FollowQuestion.objects.filter(user=request.user) for follow in follows: followedquestions.append ( get_object_or_404(Question, id=follow.question.id) ) if 'deltag' in request.GET: idtag = request.GET.get('deltag') tag = Tag.objects.filter(id=idtag) if tag.exists(): followTag = FollowTag.objects.filter(tag=tag) if followTag.exists(): FollowTag.objects.get(tag=tag, user=request.user).delete() tags = [] Ftags = FollowTag.objects.all().filter(user=request.user) for Ftag in Ftags: tags.append(Ftag.tag) profileform = ProfileForm(instance=profile) # An unbound form return render_to_response('members/profile.html', {'profileform': profileform, 'followedquestions':followedquestions, 'tags':tags }, context_instance=RequestContext(request))