def profile(request): user = request.user your_ideas = Idea.objects.filter(user = user).order_by('-date') ideas_len = len(your_ideas) your_slates = Slate.objects.filter(creator = user).order_by('-id') slates_len = len(your_slates) if request.method == 'POST': #If something has been submitted print "post" if 'vote' in request.POST: voteForm = VoteForm(request.POST) if voteForm.is_valid(): helpers.vote(voteForm,request.user) if 'profile' in request.POST: print "profile" profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.get_profile()) print profile_form if profile_form.is_valid(): print "valid" photo_string = hashlib.sha224( "profile_pic"+ CLIENT_SUB_DOMAIN+ str(user.id)).hexdigest() write_url = '%susers/%s.png' %(STATIC_DOC_ROOT,photo_string) print photo_string try: photo = request.FILES['photo'] except:#no image pass else: success, string = helpers.handle_uploaded_file(photo, write_url, "profile") if success: print success user.get_profile().photo = photo_string + ".png" user.get_profile().save() else: messages.error(request, "That file was too large.") user.save() return HttpResponseRedirect("/accounts/profile/") profile_form = ProfileForm() voted_on = Vote.objects.filter(user = user) voted_len = len(voted_on) commented_on = user.get_profile().get_ideas_commented_on() comments_len = len(commented_on) return render_to_response('main/profile.html', locals(), context_instance=RequestContext(request))
def user(request, user_id): try: profile_user = User.objects.get(id = user_id) except User.DoesNotExist: return HttpResponseRedirect("/") your_ideas = Idea.objects.filter(user = profile_user).filter(private=False).order_by('-date') ideas_len = len(your_ideas) your_slates = Slate.objects.filter(creator = profile_user).order_by('-id') slates_len = len(your_slates) if request.method == 'POST': #If something has been submitted print "post" if 'vote' in request.POST: voteForm = VoteForm(request.POST) if voteForm.is_valid(): helpers.vote(voteForm,request.user) voted_on = Vote.objects.filter(user = profile_user) voted_len = len(voted_on) commented_on = profile_user.get_profile().get_ideas_commented_on() comments_len = len(commented_on) return render_to_response('main/user_profile.html', locals(), context_instance=RequestContext(request))
def splash(request,show=''): is_splash = "splash" client_sub_domain = CLIENT_SUB_DOMAIN if not request.user.is_authenticated(): form = AuthenticationForm() registerForm = UserCreationForm() if request.method=="POST": register(request) return HttpResponseRedirect("/") else: recent_ideas = Idea.objects.exclude(private=True).order_by('?')[:6] return render_to_response("main/splash.html", locals(), context_instance=RequestContext(request)) # # else there is a user and we can just show the general page # else: user = request.user #if user.has_perm(app.idea.can_add): # post_idea = True #else: # post_idea = False if request.method == 'POST': #If something has been submitted if 'vote' in request.POST: voteForm = VoteForm(request.POST) if voteForm.is_valid(): helpers.vote(voteForm,request.user) if 'submit_email' in request.POST: emailForm = EmailForm(request.POST) if emailForm.is_valid(): clean = emailForm.cleaned_data exists = User.objects.filter(email=clean['email']) if len(exists) > 0: messages.error(request, ( "That e-mail address is " "already in use, have you signed up before " "using a different username?")) return HttpResponseRedirect("/") user.email = clean['email'] helpers.send_verify_email(clean['email'],user,request) user.save() if 'submit_idea' in request.POST: idea = helpers.add_idea(request) if 'submit_idea_elaborate' in request.POST: idea = helpers.add_idea(request) if idea: return HttpResponseRedirect(reverse('edit-idea', args=[idea.id])) voteUpForm = VoteForm({'vote':'+'}) voteDownForm = VoteForm({'vote':'-'}) ideaForm = IdeaForm() searchForm = SearchForm() emailForm = EmailForm({'email':user.email}) all_ideas = Idea.objects.exclude(private=True).annotate(votes=Count('vote_on')) if show == 'started': all_ideas = Idea.objects.filter(started=True).exclude(private=True).annotate(votes=Count('vote_on')) elif show == 'not-started': all_ideas = Idea.objects.exclude(started=True).exclude(private=True).annotate(votes=Count('vote_on')) if show == 'top': all_ideas = all_ideas.order_by('-votes') else: all_ideas = all_ideas.order_by('-date') all_ideas = helpers.process_ideas(user, all_ideas) return render_to_response("main/home.html",locals(), context_instance=RequestContext(request))
def idea(request,idea_id, edit=False): try: idea = Idea.objects.get(id =idea_id) except Idea.DoesNotExist: return HttpResponseRedirect("/") tags = Tag.objects.filter(idea = idea) try: voted_on = idea.vote_on.get(user = request.user) except: pass relevant_comments = Comment.objects.filter(idea = idea).order_by("date_posted") commentForm = CommentForm(request.POST or None) comments_num = len(relevant_comments) if request.method == 'POST': #If something has been submitted if 'vote' in request.POST: voteForm = VoteForm(request.POST) if voteForm.is_valid(): helpers.vote(voteForm,request.user) if 'edit_idea' in request.POST: ideaForm = IdeaForm(request.POST) if ideaForm.is_valid(): clean = ideaForm.cleaned_data idea.idea = clean['idea_content'] idea.elaborate = clean['elaborate'] helpers.filter_tags(clean['tags'], idea) idea.private = clean['private'] idea.save() edit = False return HttpResponseRedirect("/idea/"+str(idea.id)+"/") if 'submit_comment' in request.POST: print "submit" commentForm = CommentForm(request.POST) if commentForm.is_valid(): clean = commentForm.cleaned_data comment = Comment(text = clean['comment'],idea=idea,user = request.user) comment.save() all_comments_idea = Comment.objects.filter(idea = idea) #if the user posting the comment doesn't own the idea, send the email to the user who owns the idea if request.user != idea.user: helpers.send_comment_email(True, request, idea, idea.user.email, comment.text) #add the user who owns the idea to the list, because either they've already received it from above, or they're the ones posting the comment user_emails_sent = [idea.user,] #for every comment on the idea for comment_for_idea in all_comments_idea: #if the commenter is not the request user we want to send the email, but if comment_for_idea.user != request.user: #only if the comment hasn't already been sent an email. if not comment_for_idea.user in user_emails_sent: user_emails_sent.append(comment_for_idea.user) helpers.send_comment_email(False, request, idea, comment_for_idea.user.email, comment.text) return HttpResponseRedirect("/idea/"+str(idea.id)+"/") #encoded_email = user.email voteUpForm = VoteForm({'vote':'+'}) if edit and (idea.user == request.user): tagString = '' for tag in tags: tagString += tag.tag + "," tagString = tagString[0:(len(tagString)-1)] ideaForm = IdeaForm({ 'idea_content':idea.idea, 'elaborate':idea.elaborate, 'tags':tagString}) else: edit = False voteDownForm = VoteForm({'vote':'-'}) commentForm = CommentForm(None) return render_to_response('main/idea.html',locals(), context_instance=RequestContext(request))