Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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())
Exemplo n.º 3
0
def reply(request, forum_slug, topic_id, quote_id=False):
    topic = get_object_or_404(Topic, pk=topic_id)

    posts = topic.post_set.order_by('-created')[:POSTS_PER_PAGE]

    if topic.locked:
        return render_response(request, "forum/forum_error.html",
                               {"message": "Başlık kilitli."})

    if request.method == 'POST':
        form = PostForm(request.POST.copy())

        flood, timeout = flood_control(request)

        if form.is_valid() and not flood:
            post = Post(topic=topic,
                        author=request.user,
                        text=form.cleaned_data['text'])
            post.save()

            # generate post url
            post_url = WEB_URL + post.get_absolute_url()
            # generate In-Reply-To header. If we get quote that should be quote's message id
            if request.POST.has_key('quote_id'):
                quote = get_object_or_404(Post, id=request.POST['quote_id'])
                in_reply_to = quote.get_email_id()
            else:
                in_reply_to = topic.get_email_id()

            # sorry, we have to send <style> to be able to display quotation correctly. Hardcode for now and I know, It's really UGLY!
            # FIXME: Give postmarkup.py's QuoteTag e-mail rendering support

            css = """<style type="text/css">
.quote {
    border: 1px solid #CCCCCC;
    padding: 10px;
    margin-bottom: 8px;
    background-color: #E1E3FF;
    color: #51615D;
}

.quote p {
    padding-left: 12px;
    font-style: italic;
}
</style>"""

            # send email to everyone who follows this topic.
            watchlists = WatchList.objects.filter(topic__id=topic_id)
            for watchlist in watchlists:
                send_mail_with_header(
                    '[Ozgurlukicin-forum] Re: %s' % topic.title,
                    '%s\n%s<br /><br /><a href="%s">%s</a>' %
                    (css, render_bbcode(
                        form.cleaned_data['text']), post_url, post_url),
                    '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
                    [watchlist.user.email],
                    headers={
                        'Message-ID': post.get_email_id(),
                        'In-Reply-To': in_reply_to
                    },
                    fail_silently=True)

            # send mailing list also.
            # send_mail_with_header('Re: %s' % topic.title,
            #                       '%s\n%s<br /><br /><a href="%s">%s</a>' % (css, render_bbcode(form.cleaned_data['text']), post_url, post_url),
            #                       '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
            #                       [FORUM_MESSAGE_LIST],
            #                       headers = {'Message-ID': post.get_email_id(),
            #                                  'In-Reply-To': in_reply_to},
            #                       fail_silently = True
            #                       )

            return HttpResponseRedirect(post.get_absolute_url())
    else:
        if quote_id:
            post = get_object_or_404(Post, pk=quote_id)

            if post in topic.post_set.all():
                form = PostForm(
                    auto_id=True,
                    initial={
                        'text':
                        '[quote <b>%s</b>, %s tarihinde:]%s[/quote]' %
                        (post.author, post.edited.strftime("%d/%m/%Y %H:%M"),
                         post.text)
                    })
            # if quote doesn't belong to this topic, just redirect to what user gets :)
            else:
                return HttpResponseRedirect(post.get_absolute_url())
        else:
            form = PostForm(auto_id=True)

    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return render_response(request, 'forum/reply.html', locals())
Exemplo n.º 4
0
def reply(request, forum_slug, topic_id, quote_id=False):
    topic = get_object_or_404(Topic, pk=topic_id)

    posts = topic.post_set.order_by('-created')[:POSTS_PER_PAGE]

    if topic.locked:
        return render_response(request, "forum/forum_error.html", {"message": "Başlık kilitli."})

    if request.method == 'POST':
        form = PostForm(request.POST.copy())

        flood,timeout = flood_control(request)

        if form.is_valid() and not flood:
            post = Post(topic=topic,
                        author=request.user,
                        text=form.cleaned_data['text']
                       )
            post.save()

            # generate post url
            post_url = WEB_URL + post.get_absolute_url()
            # generate In-Reply-To header. If we get quote that should be quote's message id
            if request.POST.has_key('quote_id'):
                quote = get_object_or_404(Post, id=request.POST['quote_id'])
                in_reply_to = quote.get_email_id()
            else:
                in_reply_to = topic.get_email_id()

            # sorry, we have to send <style> to be able to display quotation correctly. Hardcode for now and I know, It's really UGLY!
            # FIXME: Give postmarkup.py's QuoteTag e-mail rendering support

            css = """<style type="text/css">
.quote {
    border: 1px solid #CCCCCC;
    padding: 10px;
    margin-bottom: 8px;
    background-color: #E1E3FF;
    color: #51615D;
}

.quote p {
    padding-left: 12px;
    font-style: italic;
}
</style>"""

            # send email to everyone who follows this topic.
            watchlists = WatchList.objects.filter(topic__id=topic_id)
            for watchlist in watchlists:
                send_mail_with_header('[Ozgurlukicin-forum] Re: %s' % topic.title,
                                      '%s\n%s<br /><br /><a href="%s">%s</a>' % (css, render_bbcode(form.cleaned_data['text']), post_url, post_url),
                                      '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
                                      [watchlist.user.email],
                                      headers = {'Message-ID': post.get_email_id(),
                                                 'In-Reply-To': in_reply_to},
                                      fail_silently = True
                                      )

            # send mailing list also.
            # send_mail_with_header('Re: %s' % topic.title,
            #                       '%s\n%s<br /><br /><a href="%s">%s</a>' % (css, render_bbcode(form.cleaned_data['text']), post_url, post_url),
            #                       '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
            #                       [FORUM_MESSAGE_LIST],
            #                       headers = {'Message-ID': post.get_email_id(),
            #                                  'In-Reply-To': in_reply_to},
            #                       fail_silently = True
            #                       )

            return HttpResponseRedirect(post.get_absolute_url())
    else:
        if quote_id:
            post = get_object_or_404(Post, pk=quote_id)

            if post in topic.post_set.all():
                form = PostForm(auto_id=True, initial={'text': '[quote <b>%s</b>, %s tarihinde:]%s[/quote]' % (post.author, post.edited.strftime("%d/%m/%Y %H:%M"), post.text)})
            # if quote doesn't belong to this topic, just redirect to what user gets :)
            else:
                return HttpResponseRedirect(post.get_absolute_url())
        else:
            form = PostForm(auto_id=True)

    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return render_response(request, 'forum/reply.html', locals())