Exemplo n.º 1
0
    def clean(self):
        '''
        checking is post subject and body contains not only space characters
        '''
        errmsg = _('Can\'t be empty nor contain only whitespace characters')
        cleaned_data = self.cleaned_data
        body = cleaned_data.get('body')
        subject = cleaned_data.get('name')
        if subject:
            if not subject.strip():
                self._errors['name'] = self.error_class([errmsg])
                del cleaned_data['name']
            cleaned_data['name'] = filter_language(subject)
        if BaseComment.user_is_muted(self.user):
            self._errors['body'] = self.error_class([_("Hmm, the filterbot is pretty sure your recent comments weren't ok for Scratch, so your account has been muted for the rest of the day. :/")])
        if self.is_ip_banned:
            error = """Sorry, the Scratch Team had to prevent your network from
            sharing comments or projects because it was used to break our
            community guidelines too many times. You can still share comments
            and projects from another network. If you'd like to appeal this
            block, you can contact {appeal_email}.
            """.format(appeal_email=settings.BAN_APPEAL_EMAIL)
            self._errors['body'] = self.error_class([_(error)])
        if body:
            if not body.strip():
                self._errors['body'] = self.error_class([errmsg])
                del cleaned_data['body']
            try:
                convert_text_to_html(body, self.user.forum_profile)
            except UnapprovedImageError as e:
                self._errors['body'] = self.error_class([e.user_error()])
                del cleaned_data['body']

            cleaned_data['body'] = filter_language(body)

            try:
                recent_post = Post.objects.filter(user=self.user).latest()
                lastpost_diff = now() - recent_post.created
            except Post.DoesNotExist:
                lastpost_diff = timedelta(1) # one day if first post
            if forum_settings.POST_FLOOD and not self.user.has_perm('djangobb_forum.fast_post'):
                if self.user.has_perm('djangobb_forum.med_post'):
                    if lastpost_diff.total_seconds() < forum_settings.POST_FLOOD_MED:
                        self._errors['body'] = self.error_class([_("Sorry, you have to wait %d seconds between posts." % forum_settings.POST_FLOOD_MED)])

                else:
                    if lastpost_diff.total_seconds() < forum_settings.POST_FLOOD_SLOW:
                        self._errors['body'] = self.error_class([_("Sorry, you have to wait %d seconds between posts." % forum_settings.POST_FLOOD_SLOW)])


        return cleaned_data
Exemplo n.º 2
0
 def clean(self):
     cleaned_data = self.cleaned_data
     subject = cleaned_data.get('name')
     if subject:
         cleaned_data['name'] = filter_language(subject)
     body = cleaned_data.get('body')
     if body:
         try:
             convert_text_to_html(body, self.instance)
         except UnapprovedImageError as e:
             self._errors['body'] = self.error_class([e.user_error()])
             del cleaned_data['body']
         cleaned_data['body'] = filter_language(body)
     return cleaned_data
Exemplo n.º 3
0
 def clean(self):
     cleaned_data = self.cleaned_data
     subject = cleaned_data.get('name')
     if subject:
         cleaned_data['name'] = filter_language(subject)
     body = cleaned_data.get('body')
     if body:
         try:
             convert_text_to_html(body, self.instance)
         except UnapprovedImageError as e:
             self._errors['body'] = self.error_class([e.user_error()])
             del cleaned_data['body']
         cleaned_data['body'] = filter_language(body)
     return cleaned_data
Exemplo n.º 4
0
 def clean(self):
     cleaned_data = self.cleaned_data
     signature = cleaned_data.get('signature')
     if signature:
         try:
             convert_text_to_html(signature, self.profile)
         except UnapprovedImageError as e:
             self._errors['signature'] = self.error_class([e.user_error()])
             del cleaned_data['signature']
         cleaned_data['signature'] = filter_language(signature)
     return cleaned_data
Exemplo n.º 5
0
 def clean(self):
     cleaned_data = self.cleaned_data
     signature = cleaned_data.get('signature')
     if signature:
         try:
             convert_text_to_html(signature, self.profile)
         except UnapprovedImageError as e:
             self._errors['signature'] = self.error_class([e.user_error()])
             del cleaned_data['signature']
         cleaned_data['signature'] = filter_language(signature)
     return cleaned_data
Exemplo n.º 6
0
    def clean(self):
        '''
        checking is post subject and body contains not only space characters
        '''
        errmsg = _('Can\'t be empty nor contain only whitespace characters')
        cleaned_data = self.cleaned_data
        body = cleaned_data.get('body')
        subject = cleaned_data.get('name')
        if subject:
            if not subject.strip():
                self._errors['name'] = self.error_class([errmsg])
                del cleaned_data['name']
            cleaned_data['name'] = filter_language(subject)
        if body:
            if not body.strip():
                self._errors['body'] = self.error_class([errmsg])
                del cleaned_data['body']
            try:
                convert_text_to_html(body, self.user.forum_profile)
            except UnapprovedImageError as e:
                self._errors['body'] = self.error_class([e.user_error()])
                del cleaned_data['body']
            cleaned_data['body'] = filter_language(body)

            try:
                recent_post = Post.objects.filter(user=self.user).latest()
                lastpost_diff = now() - recent_post.created
            except Post.DoesNotExist:
                lastpost_diff = timedelta(1) # one day if first post
            if forum_settings.POST_FLOOD and not self.user.has_perm('djangobb_forum.fast_post'):
                if self.user.has_perm('djangobb_forum.med_post'):
                    if lastpost_diff.total_seconds() < forum_settings.POST_FLOOD_MED:
                        self._errors['body'] = self.error_class([_("Sorry, you have to wait %d seconds between posts." % forum_settings.POST_FLOOD_MED)])

                else:
                    if lastpost_diff.total_seconds() < forum_settings.POST_FLOOD_SLOW:
                        self._errors['body'] = self.error_class([_("Sorry, you have to wait %d seconds between posts." % forum_settings.POST_FLOOD_SLOW)])


        return cleaned_data
Exemplo n.º 7
0
    def clean(self):
        '''
        checking is post subject and body contains not only space characters
        '''
        errmsg = _('Can\'t be empty nor contain only whitespace characters')
        cleaned_data = self.cleaned_data
        body = cleaned_data.get('body')
        subject = cleaned_data.get('name')
        if subject:
            if not subject.strip():
                self._errors['name'] = self.error_class([errmsg])
                del cleaned_data['name']
            cleaned_data['name'] = filter_language(subject)
        if BaseComment.user_is_muted(self.user):
            self._errors['body'] = self.error_class([
                _("Hmm, the filterbot is pretty sure your recent comments weren't ok for Scratch, so your account has been muted for the rest of the day. :/"
                  )
            ])
        if self.is_ip_banned:
            error = """Sorry, the Scratch Team had to prevent your network from
            sharing comments or projects because it was used to break our
            community guidelines too many times. You can still share comments
            and projects from another network. If you'd like to appeal this
            block, you can contact {appeal_email}.
            """.format(appeal_email=settings.BAN_APPEAL_EMAIL)
            self._errors['body'] = self.error_class([_(error)])
        if body:
            if not body.strip():
                self._errors['body'] = self.error_class([errmsg])
                del cleaned_data['body']
            try:
                convert_text_to_html(body, self.user.forum_profile)
            except UnapprovedImageError as e:
                self._errors['body'] = self.error_class([e.user_error()])
                del cleaned_data['body']

            cleaned_data['body'] = filter_language(body)

            try:
                recent_post = Post.objects.filter(user=self.user).latest()
                lastpost_diff = now() - recent_post.created
            except Post.DoesNotExist:
                lastpost_diff = timedelta(1)  # one day if first post
            if forum_settings.POST_FLOOD and not self.user.has_perm(
                    'djangobb_forum.fast_post'):
                if self.user.has_perm('djangobb_forum.med_post'):
                    if lastpost_diff.total_seconds(
                    ) < forum_settings.POST_FLOOD_MED:
                        self._errors['body'] = self.error_class([
                            _("Sorry, you have to wait %d seconds between posts."
                              % forum_settings.POST_FLOOD_MED)
                        ])

                else:
                    if lastpost_diff.total_seconds(
                    ) < forum_settings.POST_FLOOD_SLOW:
                        self._errors['body'] = self.error_class([
                            _("Sorry, you have to wait %d seconds between posts."
                              % forum_settings.POST_FLOOD_SLOW)
                        ])

        return cleaned_data