Пример #1
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']
     return cleaned_data
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
0
 def process_preview(self, request,  form, context):
     context['newsitem'] = form.save(commit=False)
     context['newsitem'].body_html = convert_text_to_html(form.cleaned_data['body'], "bbcode") 
     context['newsitem'].body_html = smiles(context['newsitem'].body_html )
     context['newsitem'].submitter_username = request.user.username
     context['newsitem'].post_time = datetime.now()
     print "Form Valid?: ", form.is_valid()
Пример #7
0
 def save(self, commit=True):
     profile = super(PersonalityProfileForm, self).save(commit=False)
     profile.signature_html = convert_text_to_html(profile.signature,
                                                   self.profile.markup)
     if commit:
         profile.save()
     return profile
Пример #8
0
 def save(self, commit=True):
     profile = super(PersonalityProfileForm, self).save(commit=False)
     profile.signature_html = convert_text_to_html(profile.signature, self.profile)
     if forum_settings.SMILES_SUPPORT:
         profile.signature_html = smiles(profile.signature_html)
     if commit:
         profile.save()
     return profile
Пример #9
0
def post_preview(request):
    """Preview for markitup"""
    markup = request.user.forum_profile.markup
    data = request.POST.get("data", "")

    data = convert_text_to_html(data, markup)
    if forum_settings.SMILES_SUPPORT:
        data = smiles(data)
    return render(request, "djangobb_forum/post_preview.html", {"data": data})
Пример #10
0
def post_preview(request):
    '''Preview for markitup'''
    markup = request.user.forum_profile.markup
    data = request.POST.get('data', '')

    data = convert_text_to_html(data, markup)
    if forum_settings.SMILES_SUPPORT:
        data = smiles(data)
    return render(request, 'djangobb_forum/post_preview.html', {'data': data})
Пример #11
0
def post_preview(request):
    '''Preview for markitup'''
    markup = request.user.forum_profile.markup
    data = request.POST.get('data', '')

    data = convert_text_to_html(data, markup)
    if forum_settings.SMILES_SUPPORT:
        data = smiles(data)
    return render(request, 'djangobb_forum/post_preview.html', {'data': data})
Пример #12
0
 def save(self, commit=True):
     profile = super(PersonalityProfileForm, self).save(commit=False)
     profile.signature_html = convert_text_to_html(profile.signature,
                                                   self.profile)
     if forum_settings.SMILES_SUPPORT:
         profile.signature_html = smiles(profile.signature_html)
     if commit:
         profile.save()
     return profile
Пример #13
0
    def test_convert_text_to_html(self):
        class User(object):
            has_perm = lambda s, p: True

        class Profile(object):
            markup = 'bbcode'
            user = User()

        bb_data = convert_text_to_html(self.bbcode, Profile())
        self.assertEqual(bb_data, '<span class="bb-bold">Lorem</span> <div class="code"><pre>ipsum :)</pre></div>=)')
Пример #14
0
def post_preview(request):
    '''Preview for markitup'''
    data = request.POST.get('data', '')

    try:
        data = convert_text_to_html(data, request.user.forum_profile)
    except UnapprovedImageError as e:
        return render(request, 'djangobb_forum/post_preview.html',
                      {'data': e.user_error()})
    if forum_settings.SMILES_SUPPORT:
        data = smiles(data)
    return render(request, 'djangobb_forum/post_preview.html', {'data': data})
Пример #15
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
Пример #16
0
def post_preview(request):
    '''Preview for markitup'''
    data = request.POST.get('data', '')

    try:
        data = convert_text_to_html(data, request.user.forum_profile)
    except UnapprovedImageError as e:
        return render(request, 'djangobb_forum/post_preview.html', {
            'data': e.user_error()
        })
    if forum_settings.SMILES_SUPPORT:
        data = smiles(data)
    return render(request, 'djangobb_forum/post_preview.html', {'data': data})
Пример #17
0
    def test_convert_text_to_html(self):
        class User(object):
            has_perm = lambda s, p: True

        class Profile(object):
            markup = 'bbcode'
            user = User()

        bb_data = convert_text_to_html(self.bbcode, Profile())
        self.assertEqual(
            bb_data,
            '<span class="bb-bold">Lorem</span> <div class="code"><pre>ipsum :)</pre></div>=)'
        )
Пример #18
0
 def test_convert_text_to_html(self):
     bb_data = convert_text_to_html(self.bbcode, 'bbcode')
     self.assertEqual(bb_data, "<strong>Lorem</strong> <div class=\"code\"><pre>ipsum :)</pre></div>=)")
Пример #19
0
 def test_convert_text_to_html(self):
     bb_data = convert_text_to_html(self.bbcode, 'bbcode')
     self.assertEqual(
         bb_data,
         "<strong>Lorem</strong> <div class=\"code\"><pre>ipsum :)</pre></div><a href=\"http://djangobb.org/\" rel=\"nofollow\">http://djangobb.org/</a> =)"
     )
Пример #20
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
Пример #21
0
 def test_convert_text_to_html(self):
     bb_data = convert_text_to_html(self.bbcode, 'bbcode')
     self.assertEqual(
         bb_data,
         "<strong>Lorem</strong> <div class=\"code\"><pre>ipsum :)</pre></div>=)"
     )
Пример #22
0
 def save(self, *args, **kwargs):
     self.body_html = convert_text_to_html(self.body, self.markup) 
     if forum_settings.SMILES_SUPPORT and self.user.forum_profile.show_smilies:
         self.body_html = smiles(self.body_html)
     super(Post, self).save(*args, **kwargs)
Пример #23
0
def misc(request):
    if 'action' in request.GET:
        action = request.GET['action']
        if action == 'markread':
            user = request.user
            PostTracking.objects.filter(user__id=user.id).update(
                last_read=datetime.now(), topics=None)
            return HttpResponseRedirect(reverse('djangobb:index'))

        elif action == 'report':
            if request.GET.get('post_id', ''):
                post_id = request.GET['post_id']
                post = get_object_or_404(Post, id=post_id)
                form = build_form(ReportForm,
                                  request,
                                  reported_by=request.user,
                                  post=post_id)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(post.get_absolute_url())
                return render(request, 'djangobb_forum/report.html',
                              {'form': form})

    elif 'submit' in request.POST and 'mail_to' in request.GET:
        form = MailToForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            user = get_object_or_404(User, username=request.GET['mail_to'])
            subject = form.cleaned_data['subject']

            from_email = request.user.email or email

            if not from_email or '@' not in from_email:
                form.errors['email'] = 'Please enter a valid email address!'

                return render(request, 'djangobb_forum/mail_to.html',
                              {'form': form})

            if not request.user.email:
                request.user.email = from_email
                request.user.save()

            body_html = convert_text_to_html(form.cleaned_data['body'],
                                             'bbcode')

            from_player = request.user.forum_profile.player

            if from_player:
                sent_by = '<a href="https://%(website)s/player/%(username)s">%(username)s</a>' % \
                          {'username': request.user.username, 'website': Site.objects.get_current().domain}
            else:
                sent_by = user.username

            body = '%s<br><br><hr>Sent by <b>%s</b> on the Standard Survival Forum<br>%s' \
                   % (body_html, sent_by, Site.objects.get_current().domain)

            message = EmailMessage(
                subject,
                body,
                '%s <%s>' %
                (request.user.username, settings.DEFAULT_FROM_EMAIL),
                [user.email],
                bcc=[settings.DEFAULT_FROM_EMAIL],
                headers={'Reply-To': from_email})
            message.content_subtype = 'html'
            message.send()

            h.flash_success(request,
                            'Email sent to <b>%s</b>!' % user.username)

            return HttpResponseRedirect(reverse('djangobb:index'))

    elif 'mail_to' in request.GET:
        mailto = get_object_or_404(User, username=request.GET['mail_to'])
        form = MailToForm()
        return render(request, 'djangobb_forum/mail_to.html', {
            'form': form,
            'mailto': mailto
        })
Пример #24
0
 def save(self, *args, **kwargs):
     self.body_html = convert_text_to_html(self.body, self.markup)
     if forum_settings.SMILES_SUPPORT and self.user.forum_profile.show_smilies:
         self.body_html = smiles(self.body_html)
     super(Post, self).save(*args, **kwargs)
Пример #25
0
def misc(request):
    if 'action' in request.GET:
        action = request.GET['action']
        if action =='markread':
            user = request.user
            PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None)
            return HttpResponseRedirect(reverse('djangobb:index'))

        elif action == 'report':
            if request.GET.get('post_id', ''):
                post_id = request.GET['post_id']
                post = get_object_or_404(Post, id=post_id)
                form = build_form(ReportForm, request, reported_by=request.user, post=post_id)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(post.get_absolute_url())
                return render(request, 'djangobb_forum/report.html', {'form':form})

    elif 'submit' in request.POST and 'mail_to' in request.GET:
        form = MailToForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            user = get_object_or_404(User, username=request.GET['mail_to'])
            subject = form.cleaned_data['subject']
            
            from_email = request.user.email or email
            
            if not from_email or '@' not in from_email:
                form.errors['email'] = 'Please enter a valid email address!'
                
                return render(request, 'djangobb_forum/mail_to.html', {
                    'form': form
                })
            
            if not request.user.email:
                request.user.email = from_email
                request.user.save()
            
            body_html = convert_text_to_html(form.cleaned_data['body'], 'bbcode')

            from_player = request.user.forum_profile.player

            if from_player:
                sent_by = '<a href="https://%(website)s/player/%(username)s">%(username)s</a>' % \
                          {'username': request.user.username, 'website': Site.objects.get_current().domain}
            else:
                sent_by = user.username
            
            body = '%s<br><br><hr>Sent by <b>%s</b> on the Standard Survival Forum<br>%s' \
                   % (body_html, sent_by, Site.objects.get_current().domain)
            
            message = EmailMessage(subject, body,
                '%s <%s>' % (request.user.username, settings.DEFAULT_FROM_EMAIL),
                [user.email], bcc=[settings.DEFAULT_FROM_EMAIL],
                headers={'Reply-To': from_email})
            message.content_subtype = 'html'
            message.send()

            h.flash_success(request, 'Email sent to <b>%s</b>!' % user.username)
            
            return HttpResponseRedirect(reverse('djangobb:index'))

    elif 'mail_to' in request.GET:
        mailto = get_object_or_404(User, username=request.GET['mail_to'])
        form = MailToForm()
        return render(request, 'djangobb_forum/mail_to.html', {'form':form,
                'mailto': mailto}
                )
Пример #26
0
 def save(self, commit=True):
     profile = super(PersonalityProfileForm, self).save(commit=False)
     profile.signature_html = convert_text_to_html(profile.signature, self.profile.markup)
     if commit:
         profile.save()
     return profile
Пример #27
0
 def render_text(self):
     self.rendered_text = convert_text_to_html(self.text, 'bbcode')
Пример #28
0
 def test_convert_text_to_html(self):
     bb_data = convert_text_to_html(self.bbcode, "bbcode")
     self.assertEqual(bb_data, '<strong>Lorem</strong> <div class="code"><pre>ipsum :)</pre></div>=)')
Пример #29
0
 def test_convert_text_to_html(self):
     bb_data = convert_text_to_html(self.bbcode, 'bbcode')
     self.assertEqual(bb_data, "<strong>Lorem</strong> <div class=\"code\"><pre>ipsum :)</pre></div><a href=\"http://djangobb.org/\" rel=\"nofollow\">http://djangobb.org/</a> =)")
Пример #30
0
 def save(self, *args, **kwargs):
     self.body_html = convert_text_to_html(self.body, "bbcode") 
     self.body_html = smiles(self.body_html)
     super(NewsItem, self).save(*args, **kwargs)