def create_forum_topic(article, forum_name): if article.id == None: # forum topic not created, lets create user = get_object_or_404(User, username=threadlocals.get_current_user()) forum = Forum.objects.filter(name=forum_name).order_by("id")[0] topic = Topic( forum=forum, title=article.title, ) topic.save() post = Post( topic=topic, author=user, text=article.text, ip=threadlocals.get_current_ip(), hidden=not article.status, ) post.save() topic.topic_latest_post = post topic.posts = 1 topic.hidden = not article.status topic.topic_latest_post = post topic.forum.posts += 1 topic.forum.topics += 1 if article.status: topic.forum.forum_latest_post = post topic.forum.save() topic.save() article.topic = topic else: # this is modified, let's update the forum topic topic = article.topic topic.tags.clear() for tag in article.tags.all(): topic.tags.add(tag) topic.hidden = not article.status topic.locked = not article.status topic.title = article.title topic.save() post = topic.post_set.order_by("created")[0] post.text = article.text post.hidden = not article.status post.edited = article.update post.save() if article.status: try: ping_google() # we're catching SitemapNotFound exception # no need to import this exception class since there is only 1 exception in the function. except: pass
def create_forum_topic(article, forum_name): if article.id == None: # forum topic not created, lets create user = get_object_or_404(User, username=threadlocals.get_current_user()) forum = Forum.objects.filter(name=forum_name).order_by("id")[0] topic = Topic( forum = forum, title = article.title, ) topic.save() post = Post( topic=topic, author=user, text=article.text, ip=threadlocals.get_current_ip(), hidden=not article.status, ) post.save() topic.topic_latest_post = post topic.posts = 1 topic.hidden = not article.status topic.topic_latest_post = post topic.forum.posts += 1 topic.forum.topics += 1 if article.status: topic.forum.forum_latest_post = post topic.forum.save() topic.save() article.topic = topic else: # this is modified, let's update the forum topic topic = article.topic topic.tags.clear() for tag in article.tags.all(): topic.tags.add(tag) topic.hidden = not article.status topic.locked = not article.status topic.title = article.title topic.save() post = topic.post_set.order_by("created")[0] post.text = article.text post.hidden = not article.status post.edited = article.update post.save() if article.status: try: ping_google() # we're catching SitemapNotFound exception # no need to import this exception class since there is only 1 exception in the function. except: pass
def mark_duplicate(request, idea_id): if request.POST: idea = get_object_or_404(Idea, pk = idea_id) if request.POST['dupple_number']: idea_original = get_object_or_404(Idea, pk= int(request.POST['dupple_number'])) idea.duplicate = idea_original else: idea_original = get_object_or_404(Idea, pk = int(request.POST['dupple'])) idea.duplicate = idea_original idea.is_duplicate = True idea.save() #changes for forum #the duplicate topic = idea.topic post_text = "<h1> Bu fikir başka bir fikrin tekrarı olarak belirlenmiş </h1>" post_text += '<a href="'+ reverse('idea_detail', args =( idea_original.id,)) post_text += '">#' + str(idea_original.id) + ": " + idea_original.title + "</a>" post_text += "<p>" + idea_original.description + "</p><br />" for image in idea_original.screenshot_set.all(): if image.is_hidden == False: post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />' post_text += "<br /><a href='"+idea_original.topic.get_latest_post_url()+"'>Lütfen buradan devam ediniz...</a>" post = Post(topic=topic, author=request.user, text=post_text ) post.save() topic.topic_latest_post = post topic.posts += 1 topic.save() topic.forum.forum_latest_post = post topic.forum.posts += 1 topic.forum.save() #the original idea topic = idea_original.topic post_text = "<h1> Başka bir fikir bu fikrin tekrarı olarak belirlenmiş </h1>" post_text += "<p>#" + str(idea.id) + ": " post_text += idea.title + "</p>" post_text += "<p>" + idea.description + "</p><br />" for image in idea.screenshot_set.all(): if image.is_hidden == False: post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />' post_text += "<br /><a href='"+idea.topic.get_absolute_url()+"'>Daha önce şu başlık altında tartışılmış...</a>" post = Post(topic=topic, author=request.user, text=post_text ) post.save() post_text = '#' + str(idea.id) + ": " + idea.title post_text += "<p>" + idea.description + "</p><br />" for image in idea.screenshot_set.all(): if image.is_hidden == False: post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />' post = idea.topic.post_set.all().order_by('created')[0] post.text = post_text post.save() topic.topic_latest_post = post topic.posts += 1 topic.save() topic.forum.forum_latest_post = post topic.forum.posts += 1 topic.forum.save() votes_list = Vote.objects.filter( idea = idea) for vote in votes_list: if vote.vote == "U": idea_original.vote_value +=10 elif vote.vote == "D": idea_original.vote_value -=10 elif vote.vote == "N": idea_original.vote_value +=1 vote.idea = idea_original vote.save() all_votes = Vote.objects.filter( idea=idea_original ).count() all_votes = float(all_votes) u_votes = Vote.objects.filter( idea=idea_original, vote="U").count() n_votes = Vote.objects.filter( idea=idea_original, vote="N").count() d_votes = Vote.objects.filter( idea=idea_original, vote="D").count() if all_votes != 0: u_percent = int((u_votes/all_votes)*100) n_percent = int((n_votes/all_votes)*100) d_percent = int((d_votes/all_votes)*100) else: u_percent = n_percent = d_percent = 0 percent = (u_percent*1000000)+(n_percent*1000)+d_percent idea_original.vote_percent=percent idea_original.save() return HttpResponseRedirect(reverse('oi.beyin2.views.delete_idea', args=(idea.id,))) else: idea = get_object_or_404(Idea, pk = idea_id) idea_list = Idea.objects.exclude(pk=idea.id).filter(is_hidden=False) return render_response(request, 'beyin2/idea_duplicate.html', {'idea': idea,'idea_list': idea_list})
def mark_duplicate(request, idea_id): if request.POST: idea = get_object_or_404(Idea, pk=idea_id) if request.POST['dupple_number']: idea_original = get_object_or_404( Idea, pk=int(request.POST['dupple_number'])) idea.duplicate = idea_original else: idea_original = get_object_or_404(Idea, pk=int(request.POST['dupple'])) idea.duplicate = idea_original idea.is_duplicate = True idea.save() #changes for forum #the duplicate topic = idea.topic post_text = "<h1> Bu fikir başka bir fikrin tekrarı olarak belirlenmiş </h1>" post_text += '<a href="' + reverse('idea_detail', args=(idea_original.id, )) post_text += '">#' + str( idea_original.id) + ": " + idea_original.title + "</a>" post_text += "<p>" + idea_original.description + "</p><br />" for image in idea_original.screenshot_set.all(): if image.is_hidden == False: post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />' post_text += "<br /><a href='" + idea_original.topic.get_latest_post_url( ) + "'>Lütfen buradan devam ediniz...</a>" post = Post(topic=topic, author=request.user, text=post_text) post.save() topic.topic_latest_post = post topic.posts += 1 topic.save() topic.forum.forum_latest_post = post topic.forum.posts += 1 topic.forum.save() #the original idea topic = idea_original.topic post_text = "<h1> Başka bir fikir bu fikrin tekrarı olarak belirlenmiş </h1>" post_text += "<p>#" + str(idea.id) + ": " post_text += idea.title + "</p>" post_text += "<p>" + idea.description + "</p><br />" for image in idea.screenshot_set.all(): if image.is_hidden == False: post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />' post_text += "<br /><a href='" + idea.topic.get_absolute_url( ) + "'>Daha önce şu başlık altında tartışılmış...</a>" post = Post(topic=topic, author=request.user, text=post_text) post.save() post_text = '#' + str(idea.id) + ": " + idea.title post_text += "<p>" + idea.description + "</p><br />" for image in idea.screenshot_set.all(): if image.is_hidden == False: post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />' post = idea.topic.post_set.all().order_by('created')[0] post.text = post_text post.save() topic.topic_latest_post = post topic.posts += 1 topic.save() topic.forum.forum_latest_post = post topic.forum.posts += 1 topic.forum.save() votes_list = Vote.objects.filter(idea=idea) for vote in votes_list: if vote.vote == "U": idea_original.vote_value += 10 elif vote.vote == "D": idea_original.vote_value -= 10 elif vote.vote == "N": idea_original.vote_value += 1 vote.idea = idea_original vote.save() all_votes = Vote.objects.filter(idea=idea_original).count() all_votes = float(all_votes) u_votes = Vote.objects.filter(idea=idea_original, vote="U").count() n_votes = Vote.objects.filter(idea=idea_original, vote="N").count() d_votes = Vote.objects.filter(idea=idea_original, vote="D").count() if all_votes != 0: u_percent = int((u_votes / all_votes) * 100) n_percent = int((n_votes / all_votes) * 100) d_percent = int((d_votes / all_votes) * 100) else: u_percent = n_percent = d_percent = 0 percent = (u_percent * 1000000) + (n_percent * 1000) + d_percent idea_original.vote_percent = percent idea_original.save() return HttpResponseRedirect( reverse('oi.beyin2.views.delete_idea', args=(idea.id, ))) else: idea = get_object_or_404(Idea, pk=idea_id) idea_list = Idea.objects.exclude(pk=idea.id).filter(is_hidden=False) return render_response(request, 'beyin2/idea_duplicate.html', { 'idea': idea, 'idea_list': idea_list })