def bookmarklet(request): posted = False if request.method == 'POST': #If something has been submitted if 'submit_idea' in request.POST: ideaForm = IdeaForm(request.POST) # A form bound to the POST data if ideaForm.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... clean = ideaForm.cleaned_data idea = Idea(idea=clean['idea_content'], user = request.user, private=clean['private']) idea.save() helpers.filter_tags(clean['tags'], idea) posted = True ideaForm = IdeaForm() return render_to_response("main/bookmarklet.html", locals(), context_instance=RequestContext(request))
def create(self, request, apikey, apisignature): """ Creates an Idea """ if not key_check( apikey, apisignature, '/idea/post/'): return {'error':'authentication failed'} else: tags = False try: ideaForm = IdeaForm({"idea_content":request.POST['idea_text'],"tags":request.POST['idea_tags']}) except: ideaForm = IdeaForm({"idea_content":request.POST['idea_text'],}) else: if request.POST['idea_tags'] != '': tags = True #set tags if the user submitted them if ideaForm.is_valid(): private = False try: if request.POST['private'] == '1': private = True except: pass clean = ideaForm.cleaned_data idea = Idea(idea=clean['idea_content'], user = User.objects.get(id = request.POST['user_id']), private = private ) idea.save() # if tags: helpers.filter_tags(clean['tags'], idea) # try: # if request.POST['slate'] != "": # print "slate problem" # slate = Slate.objects.get(id=request.POST['slate']) # slate.ideas.add(idea) # slate.save() # except Error as e: # print e return idea else: return {'error':'no idea'}
def add_idea(request, slate_id=None): print slate_id ideaForm = IdeaForm(request.POST) if ideaForm.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... clean = ideaForm.cleaned_data idea = Idea( idea=clean['idea_content'], user = request.user, private = clean['private'], ) idea.save() if slate_id: print "add to slate" slate = Slate.objects.get(id=slate_id) slate.ideas.add(idea) slate.save() filter_tags(clean['tags'], idea) print "returning idea" return idea
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))