Beispiel #1
0
    def get(self, request):
        """Show the page that notifies that user is banned"""

        context = self.get_context_data(request=request)

        ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
        context['ban_reason'] = ban.reason
        return render(request, 'boards/staticpages/banned.html', context)
Beispiel #2
0
    def process_view(self, request, view_func, view_args, view_kwargs):

        if view_func != views.banned.BannedView.as_view:
            ip = utils.get_client_ip(request)
            bans = Ban.objects.filter(ip=ip)

            if bans.exists():
                ban = bans[0]
                if not ban.can_read:
                    return redirect('banned')
Beispiel #3
0
    def _ban_current_user(self, request):
        """
        Add current user to the IP ban list
        """

        ip = utils.get_client_ip(request)
        ban, created = Ban.objects.get_or_create(ip=ip)
        if created:
            ban.can_read = False
            ban.reason = BAN_REASON_SPAM
        ban.save()
Beispiel #4
0
    def _new_post(self, request, form, opening_post=None, html_response=True):
        """
        Add a new thread opening post.
        """

        ip = utils.get_client_ip(request)
        is_banned = Ban.objects.filter(ip=ip).exists()

        if is_banned:
            if html_response:
                return redirect(BannedView().as_view())
            else:
                return

        data = form.cleaned_data

        title = data['title']
        text = data['text']

        text = self._remove_invalid_links(text)

        if 'image' in data.keys():
            image = data['image']
        else:
            image = None

        tags = []

        tag_strings = data['tags']

        if tag_strings:
            tag_strings = tag_strings.split(' ')
            for tag_name in tag_strings:
                tag_name = string.lower(tag_name.strip())
                if len(tag_name) > 0:
                    tag, created = Tag.objects.get_or_create(name=tag_name)
                    tags.append(tag)

        post = Post.objects.create_post(title=title, text=text, ip=ip,
                                        image=image, tags=tags,
                                        user=self._get_user(request))

        thread_to_show = (opening_post.id if opening_post else post.id)

        if html_response:
            if opening_post:
                return redirect(
                    reverse('thread', kwargs={'post_id': thread_to_show}) +
                    '#' + str(post.id))
            else:
                return redirect('thread', post_id=thread_to_show)
Beispiel #5
0
    def new_post(self, request, form, opening_post=None, html_response=True):
        """Add a new post (in thread or as a reply)."""

        ip = utils.get_client_ip(request)
        is_banned = Ban.objects.filter(ip=ip).exists()

        if is_banned:
            if html_response:
                return redirect(BannedView().as_view())
            else:
                return

        data = form.cleaned_data

        title = data['title']
        text = data['text']

        text = self._remove_invalid_links(text)

        if 'image' in data.keys():
            image = data['image']
        else:
            image = None

        tags = []

        post_thread = opening_post.get_thread()

        post = Post.objects.create_post(title=title, text=text, ip=ip,
                                        thread=post_thread, image=image,
                                        tags=tags,
                                        user=self._get_user(request))

        thread_to_show = (opening_post.id if opening_post else post.id)

        if html_response:
            if opening_post:
                return redirect(reverse(
                    'thread',
                    kwargs={'post_id': thread_to_show}) + '#' + str(post.id))