def the_filler(instance, u): """ The actual filler""" if instance._meta.module_name == "howto": name = "Nasıl" elif instance._meta.module_name == "game": name = "Oyunlar" elif instance._meta.module_name == "package": name = "Paketler" elif instance._meta.module_name == "news": name = "Haberler" forum = Forum.objects.filter(name=name) if not forum: return t = Topic.objects.filter(title=instance.title) if not t: topic = Topic( forum=forum[0], title=instance.title #or any ) topic.save() post = Post(topic=topic, author=u, text=instance.text, ip="127.0.0.1") post.save() else: return return
def new_topic(request, forum_slug): forum = get_object_or_404(Forum, slug=forum_slug) if forum.locked and not request.user.has_perm("forum.add_topic"): return render_response( request, "forum/forum_error.html", { "message": "Bu forumda yeni başlık açamazsınız. Lütfen kilitli olmayan bir forumda başlık açınız." }) if request.method == 'POST': form = TopicForm(request.POST.copy()) flood, timeout = flood_control(request) if form.is_valid() and not flood: topic = Topic(forum=forum, title=form.cleaned_data['title']) topic.save() # add tags for tag in form.cleaned_data['tags']: t = Tag.objects.get(name=tag) topic.tags.add(t) post = Post(topic=topic, author=request.user, text=form.cleaned_data['text']) post.save() # generate post url post_url = WEB_URL + topic.get_absolute_url() # send e-mail to mailing list. We really rock, yeah! # send_mail_with_header('%s' % topic.title, # '%s<br /><br /><a href="%s">%s</a>' % (post.text, post_url, post_url), # '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL), # [FORUM_MESSAGE_LIST], # headers = {'Message-ID': topic.get_email_id()}, # fail_silently = True # ) return HttpResponseRedirect(post.get_absolute_url()) else: form = TopicForm(auto_id=True) if request.user.has_perm("forum.can_change_abusereport"): abuse_count = AbuseReport.objects.count() return render_response(request, 'forum/new_topic.html', locals())
def new_topic(request, forum_slug): forum = get_object_or_404(Forum, slug=forum_slug) if forum.locked and not request.user.has_perm("forum.add_topic"): return render_response(request, "forum/forum_error.html", { "message":"Bu forumda yeni başlık açamazsınız. Lütfen kilitli olmayan bir forumda başlık açınız." }) if request.method == 'POST': form = TopicForm(request.POST.copy()) flood,timeout = flood_control(request) if form.is_valid() and not flood: topic = Topic(forum=forum, title=form.cleaned_data['title']) topic.save() # add tags for tag in form.cleaned_data['tags']: t=Tag.objects.get(name=tag) topic.tags.add(t) post = Post(topic=topic, author=request.user, text=form.cleaned_data['text']) post.save() # generate post url post_url = WEB_URL + topic.get_absolute_url() # send e-mail to mailing list. We really rock, yeah! # send_mail_with_header('%s' % topic.title, # '%s<br /><br /><a href="%s">%s</a>' % (post.text, post_url, post_url), # '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL), # [FORUM_MESSAGE_LIST], # headers = {'Message-ID': topic.get_email_id()}, # fail_silently = True # ) return HttpResponseRedirect(post.get_absolute_url()) else: form = TopicForm(auto_id=True) if request.user.has_perm("forum.can_change_abusereport"): abuse_count = AbuseReport.objects.count() return render_response(request, 'forum/new_topic.html', locals())
def add(request): if request.method == 'POST': form = NewIdeaForm(request.POST, request.FILES) if form.is_valid(): forum = Forum.objects.get(name="Yeni Fikirler") topic = Topic(forum=forum, title=form.cleaned_data['title'], ) topic.save() newidea = Idea(title = form.cleaned_data['title'], description = form.cleaned_data['description'], submitter = request.user, category = form.cleaned_data['category'], related_to = form.cleaned_data['related_to'], forum_url = form.cleaned_data['forum_url'], bug_numbers = form.cleaned_data['bug_numbers'], status = Status.objects.get(name="Yeni Fikir"), topic = topic) newidea.save() for tag in form.cleaned_data['tags']: tag = Tag.objects.get(name=tag) newidea.tags.add(tag) topic.tags.add(tag) post_text = "<p>#" + str(newidea.id) + " " post_text += "<a href=" + newidea.get_absolute_url() + ">" + newidea.title + "</a></p>" post_text += "<p>" + newidea.description + "</p>" if form.cleaned_data['forum_url']: post_text += "<p>İlgili Forum Linki<br /><a href='" + newidea.forum_url + "'>" + newidea.forum_url + "</a></p>" if newidea.bug_numbers: post_text += "<p>İlgili hatalar<br />" for bug in newidea.bug_numbers.replace(" ", "").split(","): post_text += "<a href='http://bugs.pardus.org.tr/show_bug.cgi?id=" + bug + "'>" + bug + "</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.topics += 1 topic.forum.posts += 1 topic.forum.save() return HttpResponseRedirect(newidea.get_absolute_url()) else: form = NewIdeaForm(auto_id=True) page_title = "Yeni Fikir Ekle" categories = Category.objects.all() return render_response(request, "idea_add_form.html", locals())
def the_filler(instance,u): """ The actual filler""" if instance._meta.module_name=="howto": name="Nasıl" elif instance._meta.module_name=="game": name="Oyunlar" elif instance._meta.module_name=="package": name="Paketler" elif instance._meta.module_name=="news": name="Haberler" forum=Forum.objects.filter(name=name) if not forum : return t=Topic.objects.filter(title=instance.title) if not t: topic = Topic(forum=forum[0], title=instance.title #or any ) topic.save() post = Post(topic=topic, author=u, text=instance.text, ip="127.0.0.1" ) post.save() else: return return
def add_new(request,phase ): if phase == "1": ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3) ScreenShotFormSet = ScreenShotSet(prefix = 'imageform') form = TagsForm(request.POST) dummy_idea = form.save(commit = False) tags = form.cleaned_data['tags'] title = form.cleaned_data['title'] form = IdeaForm({'ideaform-title': title, 'ideaform-tags': [tag.id for tag in tags]}, prefix = 'ideaform') return render_response(request, 'beyin2/idea_new.html', {'form':form,'ScreenShotFormSet':ScreenShotFormSet}) if phase == "2": form = IdeaForm({'title': '', 'description': '', 'status': DefaultStatus, 'category': DefaultCategory}, prefix = 'ideaform') ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3) if request.POST: try: form = IdeaForm(request.POST, prefix = 'ideaform') ScreenShotFormSet = ScreenShotSet(request.POST, request.FILES, prefix = 'imageform') except: return render_response(request,'beyin2/idea_errorpage.html',{'error':'Form bulunamadı.',}) if form.is_valid(): forum = Forum.objects.get(name = ForumCategory) topic = Topic(forum = forum,title = form.cleaned_data['title']) topic.save() idea = form.save(commit = False) idea.submitter = request.user idea.description = form.cleaned_data['description'] idea.dateSubmitted = datetime.now() idea.topic = topic if not idea.status: def_stat = get_object_or_404(Status, pk = DefaultStatus ) idea.status = def_stat if not idea.category: def_cate = get_object_or_404(Category, pk = DefaultCategory ) idea.category = def_cate idea.save() try: for screenshotform in ScreenShotFormSet.forms: image = screenshotform.save(commit = False) if image.image: image.idea = idea image.save() except: pass for tag in form.cleaned_data['tags']: tag = Tag.objects.get(name=tag) idea.tags.add(tag) topic.tags.add(tag) post_text = '<a href="'+ reverse('idea_detail', args =( idea.id,)) post_text += '">#' + str(idea.id) + ": " post_text += idea.title + "</a>" post_text += "<p>" + idea.description + "</p>" for image in idea.screenshot_set.all(): post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />' 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.topics += 1 topic.forum.posts += 1 topic.forum.save() return HttpResponseRedirect(reverse('oi.beyin2.views.main')) else: return render_response(request, 'beyin2/idea_errorpage.html',{'error':form.errors,}) else: ScreenShotFormSet = ScreenShotSet(prefix = 'imageform') return render_response(request, 'beyin2/idea_new.html', {'form':form,'ScreenShotFormSet':ScreenShotFormSet})
def add_new(request, phase): if phase == "1": ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3) ScreenShotFormSet = ScreenShotSet(prefix='imageform') form = TagsForm(request.POST) dummy_idea = form.save(commit=False) tags = form.cleaned_data['tags'] title = form.cleaned_data['title'] form = IdeaForm( { 'ideaform-title': title, 'ideaform-tags': [tag.id for tag in tags] }, prefix='ideaform') return render_response(request, 'beyin2/idea_new.html', { 'form': form, 'ScreenShotFormSet': ScreenShotFormSet }) if phase == "2": form = IdeaForm( { 'title': '', 'description': '', 'status': DefaultStatus, 'category': DefaultCategory }, prefix='ideaform') ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3) if request.POST: try: form = IdeaForm(request.POST, prefix='ideaform') ScreenShotFormSet = ScreenShotSet(request.POST, request.FILES, prefix='imageform') except: return render_response(request, 'beyin2/idea_errorpage.html', { 'error': 'Form bulunamadı.', }) if form.is_valid(): forum = Forum.objects.get(name=ForumCategory) topic = Topic(forum=forum, title=form.cleaned_data['title']) topic.save() idea = form.save(commit=False) idea.submitter = request.user idea.description = form.cleaned_data['description'] idea.dateSubmitted = datetime.now() idea.topic = topic if not idea.status: def_stat = get_object_or_404(Status, pk=DefaultStatus) idea.status = def_stat if not idea.category: def_cate = get_object_or_404(Category, pk=DefaultCategory) idea.category = def_cate idea.save() try: for screenshotform in ScreenShotFormSet.forms: image = screenshotform.save(commit=False) if image.image: image.idea = idea image.save() except: pass for tag in form.cleaned_data['tags']: tag = Tag.objects.get(name=tag) idea.tags.add(tag) topic.tags.add(tag) post_text = '<a href="' + reverse('idea_detail', args=(idea.id, )) post_text += '">#' + str(idea.id) + ": " post_text += idea.title + "</a>" post_text += "<p>" + idea.description + "</p>" for image in idea.screenshot_set.all(): post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />' 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.topics += 1 topic.forum.posts += 1 topic.forum.save() return HttpResponseRedirect(reverse('oi.beyin2.views.main')) else: return render_response(request, 'beyin2/idea_errorpage.html', { 'error': form.errors, }) else: ScreenShotFormSet = ScreenShotSet(prefix='imageform') return render_response(request, 'beyin2/idea_new.html', { 'form': form, 'ScreenShotFormSet': ScreenShotFormSet })
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