import datetime
-from django.conf import settings
+from forum import settings
from django.core.exceptions import ObjectDoesNotExist
from django.utils import simplejson
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from django.utils.translation import ungettext, ugettext as _
from django.template import RequestContext
from forum.models import *
-from forum.forms import CloseForm
from forum.actions import *
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from forum.utils.decorators import ajax_method, ajax_login_required
+from forum.modules.decorators import decoratable
from decorators import command, CommandException
from forum import settings
import logging
class NotEnoughRepPointsException(CommandException):
def __init__(self, action):
super(NotEnoughRepPointsException, self).__init__(
- _("""
- Sorry, but you don't have enough reputation points to %(action)s.<br />
- Please check the <a href'%(faq_url)s'>faq</a>
- """ % {'action': action, 'faq_url': reverse('faq')})
+ _("""Sorry, but you don't have enough reputation points to %(action)s.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
)
class CannotDoOnOwnException(CommandException):
def __init__(self, action):
super(CannotDoOnOwnException, self).__init__(
- _("""
- Sorry but you cannot %(action)s your own post.<br />
- Please check the <a href'%(faq_url)s'>faq</a>
- """ % {'action': action, 'faq_url': reverse('faq')})
+ _("""Sorry but you cannot %(action)s your own post.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
)
class AnonymousNotAllowedException(CommandException):
def __init__(self, action):
super(AnonymousNotAllowedException, self).__init__(
- _("""
- Sorry but anonymous users cannot %(action)s.<br />
- Please login or create an account <a href'%(signin_url)s'>here</a>.
- """ % {'action': action, 'signin_url': reverse('auth_signin')})
- )
-
-class SpamNotAllowedException(CommandException):
- def __init__(self, action = "comment"):
- super(SpamNotAllowedException, self).__init__(
- _("""Your %s has been marked as spam.""" % action)
+ _("""Sorry but anonymous users cannot %(action)s.<br />Please login or create an account <a href='%(signin_url)s'>here</a>.""" % {'action': action, 'signin_url': reverse('auth_signin')})
)
class NotEnoughLeftException(CommandException):
def __init__(self, action, limit):
super(NotEnoughLeftException, self).__init__(
- _("""
- Sorry, but you don't have enough %(action)s left for today..<br />
- The limit is %(limit)s per day..<br />
- Please check the <a href'%(faq_url)s'>faq</a>
- """ % {'action': action, 'limit': limit, 'faq_url': reverse('faq')})
+ _("""Sorry, but you don't have enough %(action)s left for today..<br />The limit is %(limit)s per day..<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'limit': limit, 'faq_url': reverse('faq')})
)
class CannotDoubleActionException(CommandException):
def __init__(self, action):
super(CannotDoubleActionException, self).__init__(
- _("""
- Sorry, but you cannot %(action)s twice the same post.<br />
- Please check the <a href'%(faq_url)s'>faq</a>
- """ % {'action': action, 'faq_url': reverse('faq')})
+ _("""Sorry, but you cannot %(action)s twice the same post.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
)
}
}
+@decoratable
@command
def comment(request, id):
post = get_object_or_404(Node, id=id)
if len(comment_text) > settings.FORM_MAX_COMMENT_BODY:
raise CommandException(_("No more than %d characters on comment body.") % settings.FORM_MAX_COMMENT_BODY)
- data = {
- "user_ip":request.META["REMOTE_ADDR"],
- "user_agent":request.environ['HTTP_USER_AGENT'],
- "comment_author":request.user.username,
- "comment_author_email":request.user.email,
- "comment_author_url":request.user.website,
- "comment":comment_text
- }
- if Node.isSpam(comment_text, data):
- raise SpamNotAllowedException()
-
if 'id' in request.POST:
comment = get_object_or_404(Comment, id=request.POST['id'])