コード例 #1
0
    def apply(self):
        if not self.state.is_VOTING:
            raise exceptions.ApplyBillInWrongStateError(bill_id=self.id)

        if not self.approved_by_moderator:
            raise exceptions.ApplyUnapprovedBillError(bill_id=self.id)

        if self.time_before_voting_end != datetime.timedelta(seconds=0):
            raise exceptions.ApplyBillBeforeVoteWasEndedError(bill_id=self.id)

        self.recalculate_votes()

        self._model.min_votes_percents_required = bills_settings.MIN_VOTES_PERCENT

        results_text = 'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % (self.votes_for,
                                                                                                            self.votes_against,
                                                                                                            round(self.votes_for_percents, 3)*100,
                                                                                                            self.votes_refrained)

        self._model.voting_end_at = datetime.datetime.now()

        self.applyed_at_turn = TimePrototype.get_current_turn_number()

        with transaction.atomic():

            if self.is_percents_barier_not_passed:
                self.state = BILL_STATE.REJECTED
                self.save()

                PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                                     get_system_user(),
                                     'Законопроект отклонён.\n\n%s' % results_text,
                                     technical=True)

                signals.bill_processed.send(self.__class__, bill=self)
                return False

            self.data.apply(self)

            self.state = BILL_STATE.ACCEPTED

            with achievements_storage.verify(type=ACHIEVEMENT_TYPE.POLITICS_ACCEPTED_BILLS, object=self.owner):
                self.save()

            PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                                 get_system_user(),
                                 'Законопроект принят. Изменения вступят в силу в ближайшее время.\n\n%s' % results_text,
                                 technical=True)


            for actor in self.data.actors:
                if isinstance(actor, places_objects.Place):
                    actor.effects.add(effects.Effect(name='закон №{}'.format(self.id),
                                                     attribute=places_relations.ATTRIBUTE.STABILITY,
                                                     value=-self.type.stability))

        logic.initiate_actual_bills_update(self._model.owner_id)

        signals.bill_processed.send(self.__class__, bill=self)
        return True
コード例 #2
0
ファイル: test_might.py プロジェクト: he1mdallr/the-tale
    def test_forum_post_might(self):
        thread = ThreadPrototype.create(self.bills_subcategory, 'caption',
                                        self.account_2, 'text')
        PostPrototype.create(thread, self.account, 'text')

        self.assertTrue(calculate_might(self.account) > 0)
        self.assertTrue(calculate_might(self.account_2) > 0)
コード例 #3
0
ファイル: test_requests.py プロジェクト: pavetok/the-tale
    def test_get_thread_with_pagination(self):

        texts = []

        for i in xrange(forum_settings.POSTS_ON_PAGE - 1):
            text = 'subcat3-post%d-text' % i
            PostPrototype.create(self.thread3, self.account, text)
            texts.append(text)

        response = self.request_html(
            url('forum:threads:show', self.thread3.id) + '?page=2')
        self.assertRedirects(response,
                             url('forum:threads:show', self.thread3.id) +
                             '?page=1',
                             status_code=302,
                             target_status_code=200)

        self.check_html_ok(self.request_html(
            url('forum:threads:show', self.thread3.id)),
                           texts=texts)

        text = 'subcat3-post%d-text' % (forum_settings.POSTS_ON_PAGE)
        PostPrototype.create(self.thread3, self.account, text)
        texts.append((text, 0))

        self.check_html_ok(self.request_html(
            url('forum:threads:show', self.thread3.id) + '?page=1'),
                           texts=texts)
        self.check_html_ok(self.request_html(
            url('forum:threads:show', self.thread3.id) + '?page=2'),
                           texts=[text])
コード例 #4
0
ファイル: prototypes.py プロジェクト: Alkalit/the-tale
    def update(self, form):

        Vote.objects.filter(bill_id=self.id).delete()

        VotePrototype.create(self.owner, self, VOTE_TYPE.FOR)

        self.data.initialize_with_user_data(form)

        self._model.updated_at = datetime.datetime.now()
        self._model.caption = form.c.caption
        self._model.rationale = form.c.rationale
        self._model.approved_by_moderator = False
        self._model.chronicle_on_accepted = form.c.chronicle_on_accepted

        self.recalculate_votes()

        self.save()

        ActorPrototype.update_actors(self, self.data.actors)

        thread = ThreadPrototype(self._model.forum_thread)
        thread.caption = form.c.caption
        thread.save()

        text = u'[url="%s%s"]Законопроект[/url] был отредактирован, все голоса сброшены.' % (project_settings.SITE_URL,
                                                                                             reverse('game:bills:show', args=[self.id]) )

        PostPrototype.create(thread,
                             get_system_user(),
                             self.bill_info_text(text),
                             technical=True)

        signals.bill_edited.send(self.__class__, bill=self)
コード例 #5
0
ファイル: test_moderation.py プロジェクト: Alkalit/the-tale
    def setUp(self):
        super(TestModeration, self).setUp()
        create_test_map()
        register_user('main_user', '*****@*****.**', '111111')
        register_user('moderator', '*****@*****.**', '111111')
        register_user('second_user', '*****@*****.**', '111111')

        self.main_account = AccountPrototype.get_by_nick('main_user')
        self.moderator = AccountPrototype.get_by_nick('moderator')
        self.second_account = AccountPrototype.get_by_nick('second_user')

        group = sync_group(forum_settings.MODERATOR_GROUP_NAME, ['forum.moderate_post', 'forum.moderate_thread'])

        group.user_set.add(self.moderator._model)

        self.client = client.Client()

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0)
        self.subcategory2 = SubCategoryPrototype.create(category=self.category, caption='subcat2-caption', order=1, closed=True)
        self.thread = ThreadPrototype.create(self.subcategory, 'thread-caption', self.main_account, 'thread-text')
        self.post = PostPrototype.create(self.thread, self.main_account, 'post-text')
        self.post2 = PostPrototype.create(self.thread, self.main_account, 'post2-text')
        self.post5 = PostPrototype.create(self.thread, self.main_account, 'post5-text', technical=True)

        self.thread2 = ThreadPrototype.create(self.subcategory, 'thread2-caption', self.main_account, 'thread2-text')
        self.post3 = PostPrototype.create(self.thread2, self.main_account, 'post3-text')
        self.post4 = PostPrototype.create(self.thread2, self.second_account, 'post4-text')

        self.thread3 = ThreadPrototype.create(self.subcategory, 'thread3-caption', self.second_account, 'thread3-text')
コード例 #6
0
ファイル: prototypes.py プロジェクト: serhii73/the-tale
    def update(self, form):

        Vote.objects.filter(bill_id=self.id).delete()

        VotePrototype.create(self.owner, self, VOTE_TYPE.FOR)

        self._initialize_with_form(form)

        self.recalculate_votes()

        self.save()

        ActorPrototype.update_actors(self, self.actors)

        thread = ThreadPrototype(self._model.forum_thread)
        thread.caption = form.c.caption
        thread.save()

        text = '[url="%s%s"]Запись[/url] была отредактирована, все голоса сброшены.' % (
            project_settings.SITE_URL,
            reverse('game:bills:show', args=[self.id]))

        PostPrototype.create(thread,
                             get_system_user(),
                             self.bill_info_text(text),
                             technical=True)

        signals.bill_edited.send(self.__class__, bill=self)
コード例 #7
0
    def apply(self):
        if not self.state.is_VOTING:
            raise exceptions.ApplyBillInWrongStateError(bill_id=self.id)

        if not self.approved_by_moderator:
            raise exceptions.ApplyUnapprovedBillError(bill_id=self.id)

        if self.time_before_voting_end != datetime.timedelta(seconds=0):
            raise exceptions.ApplyBillBeforeVoteWasEndedError(bill_id=self.id)

        self.recalculate_votes()

        self._model.min_votes_percents_required = bills_settings.MIN_VOTES_PERCENT

        results_text = u'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % (
            self.votes_for, self.votes_against,
            round(self.votes_for_percents, 3) * 100, self.votes_refrained)

        self._model.voting_end_at = datetime.datetime.now()

        self.applyed_at_turn = TimePrototype.get_current_turn_number()

        if self.is_percents_barier_not_passed:
            self.state = BILL_STATE.REJECTED
            self.save()

            PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                                 get_system_user(),
                                 u'Законопроект отклонён.\n\n%s' %
                                 results_text,
                                 technical=True)

            signals.bill_processed.send(self.__class__, bill=self)
            return False

        self.data.apply(self)

        self.state = BILL_STATE.ACCEPTED

        with achievements_storage.verify(
                type=ACHIEVEMENT_TYPE.POLITICS_ACCEPTED_BILLS,
                object=self.owner):
            self.save()

        PostPrototype.create(
            ThreadPrototype(self._model.forum_thread),
            get_system_user(),
            u'Законопроект принят. Изменения вступят в силу в ближайшее время.\n\n%s'
            % results_text,
            technical=True)

        for actor in self.data.actors:
            if isinstance(actor, PlacePrototype):
                actor.stability_modifiers.append(
                    (u'закон №%d' % self.id, -self.type.stability))

        logic.initiate_actual_bills_update(self._model.owner_id)

        signals.bill_processed.send(self.__class__, bill=self)
        return True
コード例 #8
0
    def update(self, form):

        Vote.objects.filter(bill_id=self.id).delete()

        VotePrototype.create(self.owner, self, VOTE_TYPE.FOR)

        self.data.initialize_with_user_data(form)

        self._model.updated_at = datetime.datetime.now()
        self._model.caption = form.c.caption
        self._model.rationale = form.c.rationale
        self._model.approved_by_moderator = False
        self._model.chronicle_on_accepted = form.c.chronicle_on_accepted

        self.recalculate_votes()

        self.save()

        ActorPrototype.update_actors(self, self.data.actors)

        thread = ThreadPrototype(self._model.forum_thread)
        thread.caption = form.c.caption
        thread.save()

        text = u'[url="%s%s"]Законопроект[/url] был отредактирован, все голоса сброшены.' % (
            project_settings.SITE_URL,
            reverse('game:bills:show', args=[self.id]))

        PostPrototype.create(thread,
                             get_system_user(),
                             self.bill_info_text(text),
                             technical=True)

        signals.bill_edited.send(self.__class__, bill=self)
コード例 #9
0
ファイル: test_might.py プロジェクト: he1mdallr/the-tale
    def test_forum_post_might__restricted(self):
        thread = ThreadPrototype.create(self.restricted_subcategory, 'caption',
                                        self.account_2, 'text')
        PostPrototype.create(thread, self.account, 'text')

        self.assertEqual(calculate_might(self.account), 0)
        self.assertEqual(calculate_might(self.account_2), 0)
コード例 #10
0
 def test_get_new_post_delay__has_old_post(self):
     PostPrototype.create(thread=self.thread,
                          author=self.account,
                          text='post-1-text')
     PostPrototype._db_all().update(created_at=datetime.datetime.now() -
                                    datetime.timedelta(days=30))
     self.assertEqual(PostPrototype.get_new_post_delay(self.account), 0)
コード例 #11
0
ファイル: test_read_state.py プロジェクト: serhii73/the-tale
 def test_subcategory_has_new_messages__new_post(self):
     SubCategoryReadInfoPrototype.read_all_in_subcategory(
         subcategory=self.subcategory, account=self.account)
     self.assertFalse(self.get_read_state().subcategory_has_new_messages(
         self.subcategory))
     PostPrototype.create(self.thread, self.account_2, 'post-new-text')
     self.assertTrue(self.get_read_state().subcategory_has_new_messages(
         self.subcategory))
コード例 #12
0
    def test_update_thread_on_create(self):
        with mock.patch('the_tale.forum.prototypes.ThreadPrototype.update'
                        ) as thread_update:
            PostPrototype.create(thread=self.thread,
                                 author=self.checked_account,
                                 text='post-1-text')

        self.assertEqual(thread_update.call_count, 1)
コード例 #13
0
    def test_get_new_post_delay__a_lot_of_posts(self):
        for i in xrange(100):
            PostPrototype.create(thread=self.thread,
                                 author=self.account,
                                 text='post-1-text')

        self.assertTrue(
            PostPrototype.get_new_post_delay(self.account) <
            forum_settings.POST_DELAY)
コード例 #14
0
    def test_get_new_post_delay__more_then_one_post(self):
        PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')
        delay_1 = PostPrototype.get_new_post_delay(self.account)

        PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')

        delay_2 = PostPrototype.get_new_post_delay(self.account)

        self.assertTrue(delay_1 - delay_2 > 1)
コード例 #15
0
    def test_get_new_post_delay__more_then_one_post(self):
        PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')
        delay_1 = PostPrototype.get_new_post_delay(self.account)

        PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')

        delay_2 = PostPrototype.get_new_post_delay(self.account)

        self.assertTrue(delay_1 - delay_2 > 1)
コード例 #16
0
ファイル: test_requests.py プロジェクト: pavetok/the-tale
    def test_get_thread__complaint_button(self):
        PostPrototype.create(self.thread1, self.account, 'post1-text')
        self.check_html_ok(self.request_html(
            url('forum:threads:show', self.thread1.id)),
                           texts=(('pgf-complaint-button', 0), ))

        PostPrototype.create(self.thread1, self.account_2, 'post2-text')
        self.check_html_ok(self.request_html(
            url('forum:threads:show', self.thread1.id)),
                           texts=(('pgf-complaint-button', 1), ))
コード例 #17
0
    def test_automatic_update_on_post_creating(self):

        old_time = datetime.datetime.now()

        PostPrototype.create(thread=self.thread, author=self.checked_account, text='post-1-text')

        self.thread.reload()

        self.assertEqual(self.thread.posts_count, 1)
        self.assertEqual(self.thread.last_poster.id, self.checked_account.id)
        self.assertTrue(self.thread.updated_at > old_time)
コード例 #18
0
    def test_automatic_update_on_post_creating(self):

        old_time = datetime.datetime.now()

        PostPrototype.create(thread=self.thread, author=self.checked_account, text='post-1-text')

        self.thread.reload()

        self.assertEqual(self.thread.posts_count, 1)
        self.assertEqual(self.thread.last_poster.id, self.checked_account.id)
        self.assertTrue(self.thread.updated_at > old_time)
コード例 #19
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_posts_count(self):
        for i in xrange(4):
            PostPrototype.create(self.thread1, self.account, 'subcat1-thread1-post%d-text' % i)

        for i in xrange(7):
            PostPrototype.create(self.thread2, self.account, 'subcat1-thread2-post%d-text' % i)

        # first post in thread does not count
        self.assertEqual(SubCategory.objects.get(id=self.subcat1.id).posts_count, 12)
        self.assertEqual(Thread.objects.get(id=self.thread1.id).posts_count, 5)
        self.assertEqual(Thread.objects.get(id=self.thread2.id).posts_count, 7)
コード例 #20
0
    def test_posts_count(self):
        for i in range(4):
            PostPrototype.create(self.thread1, self.account, 'subcat1-thread1-post%d-text' % i)

        for i in range(7):
            PostPrototype.create(self.thread2, self.account, 'subcat1-thread2-post%d-text' % i)

        # first post in thread does not count
        self.assertEqual(SubCategory.objects.get(id=self.subcat1.id).posts_count, 12)
        self.assertEqual(Thread.objects.get(id=self.thread1.id).posts_count, 5)
        self.assertEqual(Thread.objects.get(id=self.thread2.id).posts_count, 7)
コード例 #21
0
ファイル: prototypes.py プロジェクト: lshestov/the-tale
    def remove(self, initiator):
        self.set_remove_initiator(initiator)
        self.state = BILL_STATE.REMOVED
        self.save()

        thread = ThreadPrototype(self._model.forum_thread)
        thread.caption = thread.caption + u" [удалён]"
        thread.save()

        PostPrototype.create(thread, get_system_user(), u"Законопроект был удалён", technical=True)

        signals.bill_removed.send(self.__class__, bill=self)
コード例 #22
0
    def setUp(self):
        super(TestModeration, self).setUp()
        create_test_map()
        register_user('main_user', '*****@*****.**', '111111')
        register_user('moderator', '*****@*****.**', '111111')
        register_user('second_user', '*****@*****.**', '111111')

        self.main_account = AccountPrototype.get_by_nick('main_user')
        self.moderator = AccountPrototype.get_by_nick('moderator')
        self.second_account = AccountPrototype.get_by_nick('second_user')

        group = sync_group(forum_settings.MODERATOR_GROUP_NAME,
                           ['forum.moderate_post', 'forum.moderate_thread'])

        group.user_set.add(self.moderator._model)

        self.client = client.Client()

        self.category = CategoryPrototype.create(caption='cat-caption',
                                                 slug='cat-slug',
                                                 order=0)
        self.subcategory = SubCategoryPrototype.create(
            category=self.category, caption='subcat-caption', order=0)
        self.subcategory2 = SubCategoryPrototype.create(
            category=self.category,
            caption='subcat2-caption',
            order=1,
            closed=True)
        self.thread = ThreadPrototype.create(self.subcategory,
                                             'thread-caption',
                                             self.main_account, 'thread-text')
        self.post = PostPrototype.create(self.thread, self.main_account,
                                         'post-text')
        self.post2 = PostPrototype.create(self.thread, self.main_account,
                                          'post2-text')
        self.post5 = PostPrototype.create(self.thread,
                                          self.main_account,
                                          'post5-text',
                                          technical=True)

        self.thread2 = ThreadPrototype.create(self.subcategory,
                                              'thread2-caption',
                                              self.main_account,
                                              'thread2-text')
        self.post3 = PostPrototype.create(self.thread2, self.main_account,
                                          'post3-text')
        self.post4 = PostPrototype.create(self.thread2, self.second_account,
                                          'post4-text')

        self.thread3 = ThreadPrototype.create(self.subcategory,
                                              'thread3-caption',
                                              self.second_account,
                                              'thread3-text')
コード例 #23
0
ファイル: prototypes.py プロジェクト: ruckysolis/the-tale
    def decline(self, moderator):
        self.state = relations.POST_STATE.DECLINED
        self.moderator_id = moderator.id
        self.save()

        thread = ForumThreadPrototype(self._model.forum_thread)
        thread.caption = thread.caption + u' [удалён]'
        thread.save()

        ForumPostPrototype.create(thread,
                                  get_system_user(),
                                  u'Произведение было удалено',
                                  technical=True)
コード例 #24
0
ファイル: prototypes.py プロジェクト: pavetok/the-tale
    def decline(self, moderator):
        self.state = relations.POST_STATE.DECLINED
        self.moderator_id = moderator.id
        self.save()

        thread = ForumThreadPrototype(self._model.forum_thread)
        thread.caption = thread.caption + u' [удалён]'
        thread.save()

        ForumPostPrototype.create(thread,
                                  get_system_user(),
                                  u'Произведение было удалено',
                                  technical=True)
コード例 #25
0
    def remove(self, initiator):
        self.set_remove_initiator(initiator)
        self.state = BILL_STATE.REMOVED
        self.save()

        thread = ThreadPrototype(self._model.forum_thread)
        thread.caption = thread.caption + u' [удалён]'
        thread.save()

        PostPrototype.create(thread,
                             get_system_user(),
                             u'Законопроект был удалён',
                             technical=True)

        signals.bill_removed.send(self.__class__, bill=self)
コード例 #26
0
ファイル: views.py プロジェクト: angru/the-tale
    def create_post(self):

        new_post_delay = PostPrototype.get_new_post_delay(self.account)

        if new_post_delay > 0:
            error_message = (
                u'Создавать новые сообщения можно не чаще раза в %d секунд. <br/>Задержка увеличивается для игроков, только начинающих общаться на форуме.<br/> Вы сможете создать новое сообщение через %d сек.'
                % (forum_settings.POST_DELAY, int(new_post_delay)))
            return self.json_error('forum.create_post.delay', error_message)

        new_post_form = forms.NewPostForm(self.request.POST)

        if not new_post_form.is_valid():
            return self.json_error('forum.create_post.form_errors',
                                   new_post_form.errors)

        post = PostPrototype.create(self.thread, self.account,
                                    new_post_form.c.text)

        if self.account.is_authenticated():
            ThreadReadInfoPrototype.read_thread(self.thread, self.account)

        return self.json_ok(
            data={
                'next_url':
                url('forum:threads:show',
                    self.thread.id,
                    page=self.thread.paginator.pages_count) +
                ('#m%d' % post.id)
            })
コード例 #27
0
    def __init__(self, accounts_factory):
        self.account_1 = accounts_factory.create_account()
        self.account_2 = accounts_factory.create_account()

        # cat1
        # |-subcat1
        # | |-thread1
        # | | |-post1
        # | |-thread2
        # |-subcat2
        # cat2
        # | subcat3
        # | |- thread3
        # cat3

        self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0)
        # to test, that subcat.id not correlate with order
        self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True)
        self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0)
        self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0)
        self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0)
        self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0)

        self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text')
        self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text')
        self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text')

        self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text')

        # create test clan and clean it's forum artifacts
        self.clan_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0)
        self.clan_1 = ClanPrototype.create(self.account_1, abbr='abbr1', name='name1', motto='motto', description='description')
コード例 #28
0
ファイル: helpers.py プロジェクト: pavetok/the-tale
    def __init__(self):
        register_user('forum_user', '*****@*****.**', '111111')
        register_user('forum_user_2', '*****@*****.**', '111111')

        self.account_1 = AccountPrototype.get_by_nick('forum_user')
        self.account_2 = AccountPrototype.get_by_nick('forum_user_2')

        # cat1
        # |-subcat1
        # | |-thread1
        # | | |-post1
        # | |-thread2
        # |-subcat2
        # cat2
        # | subcat3
        # | |- thread3
        # cat3

        self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0)
        # to test, that subcat.id not correlate with order
        self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True)
        self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0)
        self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0)
        self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0)
        self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0)

        self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text')
        self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text')
        self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text')

        self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text')

        # create test clan and clean it's forum artifacts
        self.clan_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0)
        self.clan_1 = ClanPrototype.create(self.account_1, abbr=u'abbr1', name=u'name1', motto=u'motto', description=u'description')
コード例 #29
0
    def test_created_at_turn(self):
        turn.increment()
        turn.increment()

        post = PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')

        self.assertEqual(post.created_at_turn, turn.number())
コード例 #30
0
ファイル: helpers.py プロジェクト: serhii73/the-tale
    def __init__(self, accounts_factory):
        self.account_1 = accounts_factory.create_account()
        self.account_2 = accounts_factory.create_account()

        # cat1
        # |-subcat1
        # | |-thread1
        # | | |-post1
        # | |-thread2
        # |-subcat2
        # cat2
        # | subcat3
        # | |- thread3
        # cat3

        self.cat_1 = CategoryPrototype.create(caption='cat1-caption',
                                              slug='cat1-slug',
                                              order=0)
        # to test, that subcat.id not correlate with order
        self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1,
                                                    caption='subcat2-caption',
                                                    order=1,
                                                    closed=True)
        self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1,
                                                    caption='subcat1-caption',
                                                    order=0)
        self.cat_2 = CategoryPrototype.create(caption='cat2-caption',
                                              slug='cat2-slug',
                                              order=0)
        self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2,
                                                    caption='subcat3-caption',
                                                    order=0)
        self.cat_3 = CategoryPrototype.create(caption='cat3-caption',
                                              slug='cat3-slug',
                                              order=0)

        self.thread_1 = ThreadPrototype.create(self.subcat_1,
                                               'thread1-caption',
                                               self.account_1, 'thread1-text')
        self.thread_2 = ThreadPrototype.create(self.subcat_1,
                                               'thread2-caption',
                                               self.account_1, 'thread2-text')
        self.thread_3 = ThreadPrototype.create(self.subcat_3,
                                               'thread3-caption',
                                               self.account_1, 'thread3-text')

        self.post_1 = PostPrototype.create(self.thread_1, self.account_1,
                                           'post1-text')

        # create test clan and clean it's forum artifacts
        self.clan_category = CategoryPrototype.create(
            caption='category-1',
            slug=clans_settings.FORUM_CATEGORY_SLUG,
            order=0)
        self.clan_1 = ClanPrototype.create(self.account_1,
                                           abbr='abbr1',
                                           name='name1',
                                           motto='motto',
                                           description='description')
コード例 #31
0
 def test_main_user_remove_moderators_post(self):
     post = PostPrototype.create(self.thread, self.moderator,
                                 'moderator-post-text')
     self.request_login('*****@*****.**')
     self.check_ajax_error(
         self.client.post(url('forum:posts:delete', post.id)),
         'forum.delete_post.remove_moderator_post')
     self.assertEqual(Post.objects.all().count(), 9)
コード例 #32
0
    def test_created_at_turn(self):
        current_turn = TimePrototype.get_current_time()

        current_turn.increment_turn()
        current_turn.increment_turn()

        post = PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')

        self.assertEqual(post.created_at_turn, current_turn.turn_number)
コード例 #33
0
    def stop(self):
        if not self.state.is_VOTING:
            raise exceptions.StopBillInWrongStateError(bill_id=self.id)

        results_text = u'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % (self.votes_for,
                                                                                                             self.votes_against,
                                                                                                             round(self.votes_for_percents, 3)*100,
                                                                                                             self.votes_refrained)

        with transaction.atomic():
            self.state = BILL_STATE.STOPPED
            self.save()

            PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                                 get_system_user(),
                                 u'Законопроект потерял смысл, голосование остановлено. %s' % results_text,
                                 technical=True)

            signals.bill_stopped.send(self.__class__, bill=self)
コード例 #34
0
    def stop(self):
        if not self.state.is_VOTING:
            raise exceptions.StopBillInWrongStateError(bill_id=self.id)

        results_text = 'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % (self.votes_for,
                                                                                                             self.votes_against,
                                                                                                             round(self.votes_for_percents, 3)*100,
                                                                                                             self.votes_refrained)

        with transaction.atomic():
            self._model.voting_end_at = datetime.datetime.now()
            self.state = BILL_STATE.STOPPED
            self.save()

            PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                                 get_system_user(),
                                 'Законопроект потерял смысл, голосование остановлено. %s' % results_text,
                                 technical=True)

            signals.bill_stopped.send(self.__class__, bill=self)
コード例 #35
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_get_thread_with_pagination(self):

        texts = []

        for i in xrange(forum_settings.POSTS_ON_PAGE-1):
            text = 'subcat3-post%d-text' % i
            PostPrototype.create(self.thread3, self.account, text)
            texts.append(text)

        response = self.request_html(url('forum:threads:show', self.thread3.id)+'?page=2')
        self.assertRedirects(response, url('forum:threads:show', self.thread3.id)+'?page=1', status_code=302, target_status_code=200)

        self.check_html_ok(self.request_html(url('forum:threads:show', self.thread3.id)), texts=texts)

        text = 'subcat3-post%d-text' % (forum_settings.POSTS_ON_PAGE)
        PostPrototype.create(self.thread3, self.account, text)
        texts.append((text, 0))

        self.check_html_ok(self.request_html(url('forum:threads:show', self.thread3.id)+'?page=1'), texts=texts)
        self.check_html_ok(self.request_html(url('forum:threads:show', self.thread3.id)+'?page=2'), texts=[text])
コード例 #36
0
    def test_created_at_turn(self):
        current_turn = TimePrototype.get_current_time()

        current_turn.increment_turn()
        current_turn.increment_turn()

        post = PostPrototype.create(thread=self.thread,
                                    author=self.account,
                                    text='post-1-text')

        self.assertEqual(post.created_at_turn, current_turn.turn_number)
コード例 #37
0
ファイル: prototypes.py プロジェクト: lshestov/the-tale
    def end(self):
        if not self.state.is_ACCEPTED:
            raise exceptions.EndBillInWrongStateError(bill_id=self.id)

        if self.ended_at is not None:
            raise exceptions.EndBillAlreadyEndedError(bill_id=self.id)

        results_text = u'Срок действия [url="%s%s"]закона[/url] истёк.' % (
            project_settings.SITE_URL,
            reverse("game:bills:show", args=[self.id]),
        )

        self._model.ended_at = datetime.datetime.now()

        self.data.end(self)

        self.save()

        PostPrototype.create(ThreadPrototype(self._model.forum_thread), get_system_user(), results_text, technical=True)

        signals.bill_ended.send(self.__class__, bill=self)
        return True
コード例 #38
0
    def end(self):
        if not self.state.is_ACCEPTED:
            raise exceptions.EndBillInWrongStateError(bill_id=self.id)

        if self.ended_at is not None:
            raise exceptions.EndBillAlreadyEndedError(bill_id=self.id)

        results_text = u'Срок действия [url="%s%s"]закона[/url] истёк.' % (project_settings.SITE_URL,
                                                                           reverse('game:bills:show', args=[self.id]) )

        self._model.ended_at = datetime.datetime.now()

        self.data.end(self)

        self.save()

        PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                             get_system_user(),
                             results_text,
                             technical=True)

        signals.bill_ended.send(self.__class__, bill=self)
        return True
コード例 #39
0
    def setUp(self):
        super(NewForumPostTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0)
        self.thread = ThreadPrototype.create(self.subcategory, 'thread_1-caption', self.account_1, 'thread-text')

        Message.objects.all().delete()

        self.post = PostPrototype.create(self.thread, self.account_1, 'post-text')

        self.message = MessagePrototype.get_priority_message()
コード例 #40
0
    def setUp(self):
        super(NewForumPostTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0)
        self.thread = ThreadPrototype.create(self.subcategory, 'thread_1-caption', self.account_1, 'thread-text')

        Message.objects.all().delete()

        self.post = PostPrototype.create(self.thread, self.account_1, 'post-text')

        self.message = MessagePrototype.get_priority_message()
コード例 #41
0
    def setUp(self):
        super(NewForumPostTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        self.category = CategoryPrototype.create(caption='cat-caption',
                                                 slug='cat-slug',
                                                 order=0)
        self.subcategory = SubCategoryPrototype.create(
            category=self.category, caption='subcat-caption', order=0)
        self.thread = ThreadPrototype.create(self.subcategory,
                                             'thread_1-caption',
                                             self.account_1, 'thread-text')

        Message.objects.all().delete()

        self.post = PostPrototype.create(self.thread, self.account_1,
                                         'post-text')

        self.message = MessagePrototype.get_priority_message()
コード例 #42
0
    def create_post(self):

        new_post_delay = PostPrototype.get_new_post_delay(self.account)

        if new_post_delay > 0:
            error_message = ('Создавать новые сообщения можно не чаще раза в %d секунд. <br/>Задержка увеличивается для игроков, только начинающих общаться на форуме.<br/> Вы сможете создать новое сообщение через %d сек.' %
                             ( forum_settings.POST_DELAY,
                               int(new_post_delay)))
            return self.json_error('forum.create_post.delay', error_message)


        new_post_form = forms.NewPostForm(self.request.POST)

        if not new_post_form.is_valid():
            return self.json_error('forum.create_post.form_errors', new_post_form.errors)

        post = PostPrototype.create(self.thread, self.account, new_post_form.c.text)

        if self.account.is_authenticated:
            ThreadReadInfoPrototype.read_thread(self.thread, self.account)

        return self.json_ok(data={'next_url': url('forum:threads:show', self.thread.id, page=self.thread.paginator.pages_count) + ('#m%d' % post.id)})
コード例 #43
0
 def test_get_new_post_delay__has_new_post(self):
     PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')
     self.assertTrue(PostPrototype.get_new_post_delay(self.account) > 0)
コード例 #44
0
 def test_subcategory_has_new_messages__new_post(self):
     SubCategoryReadInfoPrototype.read_all_in_subcategory(subcategory=self.subcategory, account=self.account)
     self.assertFalse(self.get_read_state().subcategory_has_new_messages(self.subcategory))
     PostPrototype.create(self.thread, self.account_2, 'post-new-text')
     self.assertTrue(self.get_read_state().subcategory_has_new_messages(self.subcategory))
コード例 #45
0
ファイル: test_might.py プロジェクト: Alkalit/the-tale
    def test_forum_post_might(self):
        thread = ThreadPrototype.create(self.bills_subcategory, 'caption', self.account_2, 'text')
        PostPrototype.create(thread, self.account, 'text')

        self.assertTrue(calculate_might(self.account) > 0)
        self.assertTrue(calculate_might(self.account_2) > 0)
コード例 #46
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_get_thread__complaint_button(self):
        PostPrototype.create(self.thread1, self.account, 'post1-text')
        self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=(('pgf-complaint-button', 0), ))

        PostPrototype.create(self.thread1, self.account_2, 'post2-text')
        self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=(('pgf-complaint-button', 1), ))
コード例 #47
0
    def test_update_thread_on_create(self):
        with mock.patch('the_tale.forum.prototypes.ThreadPrototype.update') as thread_update:
            PostPrototype.create(thread=self.thread, author=self.checked_account, text='post-1-text')

        self.assertEqual(thread_update.call_count, 1)
コード例 #48
0
    def test_forum_post_might__restricted(self):
        thread = ThreadPrototype.create(self.restricted_subcategory, 'caption', self.account_2, 'text')
        PostPrototype.create(thread, self.account, 'text')

        self.assertEqual(calculate_might(self.account), 0)
        self.assertEqual(calculate_might(self.account_2), 0)
コード例 #49
0
    def test_get_new_post_delay__a_lot_of_posts(self):
        for i in range(100):
            PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')

        self.assertTrue(PostPrototype.get_new_post_delay(self.account) < forum_settings.POST_DELAY)
コード例 #50
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_feed_page(self):

        self.thread1._model.created_at -= datetime.timedelta(seconds=forum_settings.FEED_ITEMS_DELAY+1)
        self.thread1.save()

        self.thread3._model.created_at -= datetime.timedelta(seconds=forum_settings.FEED_ITEMS_DELAY+1)
        self.thread3.save()

        PostPrototype.create(self.thread1, self.account, 'post2-text')
        PostPrototype.create(self.thread1, self.account, 'post3-text')
        PostPrototype.create(self.thread2, self.account, 'post4-text')
        PostPrototype.create(self.thread2, self.account, 'post5-text')
        PostPrototype.create(self.thread3, self.account, 'post6-text')

        # restricted
        self.subcat2._model.restricted = True
        self.subcat2.save()

        thread2_2 = ThreadPrototype.create(self.subcat2, 'thread2_2-caption', self.account, 'thread2_2-text')

        PostPrototype.create(thread2_2, self.account, 'post7-text')
        PostPrototype.create(thread2_2, self.account, 'post8-text')

        texts = [('thread1-caption', 1),
                 ('thread1-text', 1),

                 ('thread2-caption', 0), # not pass throught time limit
                 ('thread2-text', 0),

                 ('thread3-caption', 1),
                 ('thread3-text', 1),

                 ('thread2_2-caption', 0),
                 ('thread2_2-text', 0)]

        texts.extend([('post%d-text' % i, 0) for i in xrange(0, 9)])

        self.check_html_ok(self.request_html(url('forum:feed')), texts=texts, content_type='application/atom+xml')
コード例 #51
0
    def test_feed_page(self):

        self.thread1._model.created_at -= datetime.timedelta(seconds=forum_settings.FEED_ITEMS_DELAY+1)
        self.thread1.save()

        self.thread3._model.created_at -= datetime.timedelta(seconds=forum_settings.FEED_ITEMS_DELAY+1)
        self.thread3.save()

        PostPrototype.create(self.thread1, self.account, 'post2-text')
        PostPrototype.create(self.thread1, self.account, 'post3-text')
        PostPrototype.create(self.thread2, self.account, 'post4-text')
        PostPrototype.create(self.thread2, self.account, 'post5-text')
        PostPrototype.create(self.thread3, self.account, 'post6-text')

        # restricted
        self.subcat2._model.restricted = True
        self.subcat2.save()

        thread2_2 = ThreadPrototype.create(self.subcat2, 'thread2_2-caption', self.account, 'thread2_2-text')

        PostPrototype.create(thread2_2, self.account, 'post7-text')
        PostPrototype.create(thread2_2, self.account, 'post8-text')

        texts = [('thread1-caption', 1),
                 ('thread1-text', 1),

                 ('thread2-caption', 0), # not pass throught time limit
                 ('thread2-text', 0),

                 ('thread3-caption', 1),
                 ('thread3-text', 1),

                 ('thread2_2-caption', 0),
                 ('thread2_2-text', 0)]

        texts.extend([('post%d-text' % i, 0) for i in range(0, 9)])

        self.check_html_ok(self.request_html(url('forum:feed')), texts=texts, content_type='application/atom+xml')
コード例 #52
0
 def test_get_new_post_delay__has_new_post(self):
     PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')
     self.assertTrue(PostPrototype.get_new_post_delay(self.account) > 0)
コード例 #53
0
 def test_get_new_post_delay__has_old_post(self):
     PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')
     PostPrototype._db_all().update(created_at=datetime.datetime.now() - datetime.timedelta(days=30))
     self.assertEqual(PostPrototype.get_new_post_delay(self.account), 0)
コード例 #54
0
ファイル: prototypes.py プロジェクト: serhii73/the-tale
    def apply(self):
        if not self.state.is_VOTING:
            raise exceptions.ApplyBillInWrongStateError(bill_id=self.id)

        if not self.approved_by_moderator:
            raise exceptions.ApplyUnapprovedBillError(bill_id=self.id)

        if self.time_before_voting_end != datetime.timedelta(seconds=0):
            raise exceptions.ApplyBillBeforeVoteWasEndedError(bill_id=self.id)

        self.recalculate_votes()

        self._model.min_votes_percents_required = bills_settings.MIN_VOTES_PERCENT

        results_text = 'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % (
            self.votes_for, self.votes_against,
            round(self.votes_for_percents, 3) * 100, self.votes_refrained)

        self._model.voting_end_at = datetime.datetime.now()

        self.applyed_at_turn = turn.number()

        with transaction.atomic():

            if self.is_percents_barier_not_passed:
                self.state = BILL_STATE.REJECTED
                self.save()

                PostPrototype.create(ThreadPrototype(self._model.forum_thread),
                                     get_system_user(),
                                     'Запись отклонена.\n\n%s' % results_text,
                                     technical=True)

                signals.bill_processed.send(self.__class__, bill=self)
                return False

            self.data.apply(self)

            self.state = BILL_STATE.ACCEPTED

            with achievements_storage.verify(
                    type=ACHIEVEMENT_TYPE.POLITICS_ACCEPTED_BILLS,
                    object=self.owner):
                self.save()

            PostPrototype.create(
                ThreadPrototype(self._model.forum_thread),
                get_system_user(),
                'Запись одобрена. Изменения вступят в силу в ближайшее время.\n\n%s'
                % results_text,
                technical=True)

            for actor in self.actors:
                if isinstance(actor, places_objects.Place):
                    actor.effects.add(
                        effects.Effect(
                            name='запись №{}'.format(self.id),
                            attribute=places_relations.ATTRIBUTE.STABILITY,
                            value=-self.type.stability))

        logic.initiate_actual_bills_update(self._model.owner_id)

        signals.bill_processed.send(self.__class__, bill=self)
        return True
コード例 #55
0
ファイル: test_moderation.py プロジェクト: Alkalit/the-tale
 def test_main_user_remove_moderators_post(self):
     post = PostPrototype.create(self.thread, self.moderator, 'moderator-post-text')
     self.request_login('*****@*****.**')
     self.check_ajax_error(self.client.post(url('forum:posts:delete', post.id)), 'forum.delete_post.remove_moderator_post')
     self.assertEqual(Post.objects.all().count(), 9)