Exemplo n.º 1
0
    def execute_taboo(self, post):
        violated_phrase = self.phrase
        ctx = {'phrase': violated_phrase}
        duration = iss_utils.get_ext_config(EXT, 'violation_duration')
        ban_reason = iss_utils.get_ext_config(EXT, 'ban_reason_tmpl') % ctx
        post_msg = iss_utils.get_ext_config(EXT, 'post_msg_tmpl') % ctx

        iss_models.Ban.objects.create(
            subject=post.author,
            given_by=iss_models.Poster.get_or_create_system_user(),
            end_date=timezone.now() + duration,
            reason=ban_reason)

        self.mark.custom_user_title = iss_utils.get_ext_config(
            EXT,
            'usertitle_punishment')
        self.mark.save()

        self.poster.custom_user_title = iss_utils.get_ext_config(
            EXT,
            'usertitle_reward')
        self.poster.save()

        TabooViolationRecord.objects.create(
            phrase=self.phrase,
            poster=self.poster,
            mark=self.mark,
            violating_post=post)

        self.mark = None
        self.save()

        post.content += post_msg
        post.save()
Exemplo n.º 2
0
    def test_usertitle_change(self):
        thread = iss_models.Thread.objects.all()[0]
        post_content = 'this is fOObar man'
        post = iss_models.Post.objects.create(
            author=self.mark,
            content=post_content,
            thread=thread)

        self.mark = iss_models.Poster.objects.get(pk=self.mark.pk)
        self.assassin = iss_models.Poster.objects.get(pk=self.assassin.pk)

        self.assertEqual(self.mark.custom_user_title,
                         iss_utils.get_ext_config(EXT, 'usertitle_punishment'))
        self.assertEqual(self.assassin.custom_user_title,
                         iss_utils.get_ext_config(EXT, 'usertitle_reward'))
Exemplo n.º 3
0
    def choose_mark_and_phrase(self):
        self.phrase = random.choice(
                iss_utils.get_ext_config(EXT, 'phrases'))
        candidates = self._get_candidate_marks()
        ccount = len(candidates)

        if ccount < 1:
            self.mark = None
        else:
            self.mark = candidates[random.randint(0, ccount-1)].poster
Exemplo n.º 4
0
    def choose_mark_and_phrase(self):
        self.phrase = random.choice(
                iss_utils.get_ext_config(EXT, 'phrases'))
        candidates = (TabooProfile.objects.all()
            .filter(active=True)
            .exclude(pk=self.pk))
        ccount = candidates.count()

        if ccount < 1:
            self.mark = None
        else:
            self.mark = candidates[random.randint(0, ccount-1)].poster
Exemplo n.º 5
0
    def _get_candidate_marks(self):
        candidates = TabooProfile.objects.raw(
            MARKABLE_PROFILES_QUERY,
            [
                self.poster.pk,
                iss_utils.get_ext_config(EXT, 'time_to_inactivity')
            ])

        # De-serialize the profiles as the DB has already done most the heavy
        # lifting and we need to call `len()` on them.
        candidates = [c for c in candidates]

        return candidates
Exemplo n.º 6
0
    def rectify_usertitles(self):
        title_period = iss_utils.get_ext_config(EXT, 'usertitle_duration')
        is_due = self.created < (timezone.now() - title_period)

        if is_due and not self.titles_rectified:
            self.poster.custom_user_title = self.victor_former_title
            self.poster.save()

            self.mark.custom_user_title = self.loser_former_title
            self.mark.save()

            self.titles_rectified = True
            self.save()
Exemplo n.º 7
0
import datetime

from django.test import TestCase, Client
from django.urls import reverse

from ISS import utils as iss_utils
from ISS import models as iss_models
from ISS.tests import test_utils
from ISS.contrib.taboo.models import *
from apps import TabooConfig

EXT = TabooConfig.name

iss_utils.get_ext_config(EXT)['min_posts_to_reg'] = 0
iss_utils.get_ext_config(EXT)['min_age_to_reg'] = datetime.timedelta(days=0)

class TabooModelsTest(TestCase):
    def setUp(self):
        test_utils.create_std_forums()

        self.mark = test_utils.create_user(thread_count=1)
        self.assassin = test_utils.create_user()

        self.profile = TabooProfile.objects.create(
            poster=self.assassin,
            mark=self.mark,
            phrase='foobar')

    def test_TabooProfile_dot_matches_post_wrong_author(self):
        post = iss_models.Post(
            author=self.assassin,
Exemplo n.º 8
0
    url(r'^pms/sent$', views.private_messages.sent, name='sent-pms'),
    url(r'^pms/compose$',
        views.private_messages.NewPrivateMessage.as_view(),
        name='compose-pm'),
    url(r'^pms/read/(?P<pm_id>\d+)$',
        views.private_messages.read_pm,
        name='read-pm'),
    url(r'^api/users/search$',
        views.user.user_fuzzy_search,
        name='api-user-serach'),
    url(r'^api/bbcode/render$',
        views.forum.RenderBBCode.as_view(),
        name='api-render-bbcode')
]

# Install urls for extensions.
for ext in utils.get_config('extensions'):
    base_path = utils.get_ext_config(ext, 'base_path')

    if base_path:
        urlpatterns.append(url(base_path, include(ext + '.urls')))

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    import debug_toolbar

    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]