コード例 #1
0
    def test_last_forum_posts_with_permissions(self):

        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')

        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        restricted_subcategory = SubCategoryPrototype.create(
            category=self.category,
            caption='subcat2-caption',
            order=1,
            restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        restricted_thread = ThreadPrototype.create(
            restricted_subcategory, 'thread-restricted-caption', self.account,
            'thread-text')

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(account=None,
                                                               limit=3)),
            set([self.thread.id]))

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(
                account=granted_account, limit=3)),
            set([self.thread.id, restricted_thread.id]))

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(
                account=wrong_account, limit=3)), set([self.thread.id]))
コード例 #2
0
    def test_update_subcategory_on_create(self):
        with mock.patch('the_tale.forum.prototypes.SubCategoryPrototype.update'
                        ) as subcategory_update:
            ThreadPrototype.create(self.subcategory, 'thread-2-caption',
                                   self.account, 'thread-2-text')

        self.assertEqual(subcategory_update.call_count, 1)
コード例 #3
0
    def setUp(self):
        super(SubscriptionPrototypeTests, self).setUp()
        create_test_map()

        self.account = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.category = CategoryPrototype.create(caption='cat-caption',
                                                 slug='cat-slug',
                                                 order=0)
        self.subcategory_1 = SubCategoryPrototype.create(
            category=self.category, caption='subcat-1-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(
            category=self.category, caption='subcat-2-caption', order=1)

        self.thread_1_1 = ThreadPrototype.create(self.subcategory_1,
                                                 'thread-1-1-caption',
                                                 self.account,
                                                 'thread-1-1-text')
        self.thread_1_2 = ThreadPrototype.create(self.subcategory_1,
                                                 'thread-1-2-caption',
                                                 self.account,
                                                 'thread-1-2-text')
        self.thread_1_3 = ThreadPrototype.create(self.subcategory_1,
                                                 'thread-1-3-caption',
                                                 self.account_2,
                                                 'thread-1-3-text')
        self.thread_2_1 = ThreadPrototype.create(self.subcategory_2,
                                                 'thread-2-1-caption',
                                                 self.account,
                                                 'thread-2-1-text')
        self.thread_2_2 = ThreadPrototype.create(self.subcategory_2,
                                                 'thread-2-2-caption',
                                                 self.account,
                                                 'thread-2-2-text')
コード例 #4
0
ファイル: test_read_state.py プロジェクト: serhii73/the-tale
    def setUp(self):
        super(ReadStateTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        category = CategoryPrototype.create(caption='cat-caption',
                                            slug='cat-slug',
                                            order=0)
        self.subcategory = SubCategoryPrototype.create(
            category=category, caption='subcat-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(
            category=category, caption='subcat-2-caption', order=0)

        self.thread = ThreadPrototype.create(self.subcategory,
                                             'thread1-caption', self.account_2,
                                             'thread-text')
        self.thread_2 = ThreadPrototype.create(self.subcategory,
                                               'thread2-caption',
                                               self.account_2, 'thread-2-text')
        self.thread_3 = ThreadPrototype.create(self.subcategory_2,
                                               'thread2-caption', self.account,
                                               'thread-2-text')
コード例 #5
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')
コード例 #6
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')
コード例 #7
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')
コード例 #8
0
ファイル: read_state.py プロジェクト: Alkalit/the-tale
    def threads_info(self):
        if not self._account.is_authenticated():
            return {}

        time_barrier = datetime.datetime.now() - datetime.timedelta(seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME)

        return {thread.id: thread for thread in ThreadPrototype.from_query(ThreadPrototype._db_filter(updated_at__gt=time_barrier))}
コード例 #9
0
    def test_last_forum_posts_with_permissions(self):
        granted_account = self.accounts_factory.create_account()
        wrong_account = self.accounts_factory.create_account()

        restricted_subcategory = SubCategoryPrototype.create(
            category=self.category,
            caption='subcat2-caption',
            order=1,
            restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        restricted_thread = ThreadPrototype.create(
            restricted_subcategory, 'thread-restricted-caption', self.account,
            'thread-text')

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(account=None,
                                                               limit=3)),
            set([self.thread.id]))

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(
                account=granted_account, limit=3)),
            set([self.thread.id, restricted_thread.id]))

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(
                account=wrong_account, limit=3)), set([self.thread.id]))
コード例 #10
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)
コード例 #11
0
ファイル: views.py プロジェクト: angru/the-tale
    def create_thread(self):

        if not can_create_thread(self.account, self.subcategory):
            return self.json_error(
                'forum.create_thread.no_permissions',
                u'Вы не можете создавать темы в данном разделе')

        new_thread_delay = ThreadPrototype.get_new_thread_delay(self.account)
        if new_thread_delay > 0:
            error_message = (
                u'Создавать новые обсуждения можно не чаще раза в %d минут.<br/> Вы сможете создать новое обсуждение через %d сек.'
                %
                (int(forum_settings.THREAD_DELAY / 60), int(new_thread_delay)))
            return self.json_error('forum.create_thread.delay', error_message)

        new_thread_form = forms.NewThreadForm(self.request.POST)

        if not new_thread_form.is_valid():
            return self.json_error('forum.create_thread.form_errors',
                                   new_thread_form.errors)

        thread = ThreadPrototype.create(self.subcategory,
                                        caption=new_thread_form.c.caption,
                                        author=self.account,
                                        text=new_thread_form.c.text)

        return self.json_ok(
            data={
                'thread_url': reverse('forum:threads:show', args=[thread.id]),
                'thread_id': thread.id
            })
コード例 #12
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)
コード例 #13
0
ファイル: test_requests.py プロジェクト: pavetok/the-tale
    def test_importans_threads_on_first_page(self):
        texts = [
            self.thread1.caption, (self.thread2.caption, 0),
            (self.thread3.caption, 0)
        ]

        self.thread2._model.important = True
        self.thread2.save()

        for i in xrange(forum_settings.THREADS_ON_PAGE):
            caption = 'thread-x-%d-caption' % i
            ThreadPrototype.create(self.subcat1, caption, self.account,
                                   'thread-text')
            if i != 0:
                texts.append((caption, 0))
            else:
                texts.append(caption)

        self.check_html_ok(self.request_html(
            url('forum:subcategories:show', self.subcat1.id, page=2)),
                           texts=texts)

        self.check_html_ok(self.request_html(
            url('forum:subcategories:show', self.subcat1.id, page=1)),
                           texts=[self.thread2.caption])
コード例 #14
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
コード例 #15
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)
コード例 #16
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')
コード例 #17
0
    def test_post_created_at_turn(self):
        turn.increment(2)

        ThreadPrototype.create(self.subcategory, 'thread-2-caption',
                               self.account, 'thread-2-text')

        self.assertEqual(PostPrototype._db_latest().created_at_turn,
                         turn.number())
コード例 #18
0
ファイル: test_moderation.py プロジェクト: Alkalit/the-tale
    def test_loggined_create_thread_page__banned(self):
        old_threads_number = ThreadPrototype._db_count()
        self.request_login('*****@*****.**')
        response = self.client.post(url('forum:subcategories:create-thread', self.subcategory.id),
                                    {'caption': 'thread5-caption', 'text': 'thread5-text'})
        self.check_ajax_error(response, 'common.ban_forum')

        self.assertEqual(old_threads_number, ThreadPrototype._db_count())
コード例 #19
0
ファイル: test_read_state.py プロジェクト: serhii73/the-tale
 def test_subcategory_has_new_messages__new_thread(self):
     SubCategoryReadInfoPrototype.read_all_in_subcategory(
         subcategory=self.subcategory, account=self.account)
     self.assertFalse(self.get_read_state().subcategory_has_new_messages(
         self.subcategory))
     ThreadPrototype.create(self.subcategory, 'new-threwad', self.account_2,
                            'thread-new-text')
     self.assertTrue(self.get_read_state().subcategory_has_new_messages(
         self.subcategory))
コード例 #20
0
    def test_post_created_at_turn(self):
        current_turn = TimePrototype.get_current_time()

        current_turn.increment_turn()
        current_turn.increment_turn()

        ThreadPrototype.create(self.subcategory, 'thread-2-caption', self.account, 'thread-2-text')

        self.assertEqual(PostPrototype._db_latest().created_at_turn, current_turn.turn_number)
コード例 #21
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_second_page(self):
        texts = [self.thread1.caption,
                 self.thread2.caption,
                 (self.thread3.caption, 0)]
        for i in xrange(forum_settings.THREADS_ON_PAGE):
            caption = 'thread-x-%d-caption' % i
            ThreadPrototype.create(self.subcat1, caption, self.account, 'thread-text')
            texts.append((caption, 0))

        self.check_html_ok(self.request_html(url('forum:subcategories:show', self.subcat1.id, page=2)), texts=texts)
コード例 #22
0
    def test_second_page(self):
        texts = [self.thread1.caption,
                 self.thread2.caption,
                 (self.thread3.caption, 0)]
        for i in range(forum_settings.THREADS_ON_PAGE):
            caption = 'thread-x-%d-caption' % i
            ThreadPrototype.create(self.subcat1, caption, self.account, 'thread-text')
            texts.append((caption, 0))

        self.check_html_ok(self.request_html(url('forum:subcategories:show', self.subcat1.id, page=2)), texts=texts)
コード例 #23
0
    def test_post_created_at_turn(self):
        current_turn = TimePrototype.get_current_time()

        current_turn.increment_turn()
        current_turn.increment_turn()

        ThreadPrototype.create(self.subcategory, 'thread-2-caption',
                               self.account, 'thread-2-text')

        self.assertEqual(PostPrototype._db_latest().created_at_turn,
                         current_turn.turn_number)
コード例 #24
0
    def test_loggined_create_thread_page__banned(self):
        old_threads_number = ThreadPrototype._db_count()
        self.request_login('*****@*****.**')
        response = self.client.post(
            url('forum:subcategories:create-thread', self.subcategory.id), {
                'caption': 'thread5-caption',
                'text': 'thread5-text'
            })
        self.check_ajax_error(response, 'common.ban_forum')

        self.assertEqual(old_threads_number, ThreadPrototype._db_count())
コード例 #25
0
ファイル: views.py プロジェクト: angru/the-tale
    def index(self, author=None, page=1, participant=None):

        threads_query = ThreadPrototype.threads_visible_to_account_query(
            self.account if self.account.is_authenticated(
            ) else None).order_by('-updated_at')

        is_filtering = False

        if author is not None:
            threads_query = threads_query.filter(author_id=author.id)
            is_filtering = True

        if participant is not None:
            threads_query = threads_query.filter(
                post__author__id=participant.id).distinct()
            is_filtering = True

        url_builder = UrlBuilder(reverse('forum:threads:'),
                                 arguments={
                                     'author':
                                     author.id if author else None,
                                     'participant':
                                     participant.id if participant else None,
                                     'page':
                                     page
                                 })

        page -= 1

        paginator = Paginator(page, threads_query.count(),
                              forum_settings.THREADS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        thread_from, thread_to = paginator.page_borders(page)

        threads = list(
            ThreadPrototype(thread_model)
            for thread_model in threads_query.select_related().order_by(
                '-updated_at')[thread_from:thread_to])

        return self.template(
            'forum/threads_list.html', {
                'is_filtering': is_filtering,
                'pages_count': range(paginator.pages_count),
                'current_page_number': page,
                'author_account': author,
                'participant_account': participant,
                'paginator': paginator,
                'threads': threads,
                'read_state': ReadState(account=self.account)
            })
コード例 #26
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')
コード例 #27
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)
コード例 #28
0
ファイル: read_state.py プロジェクト: serhii73/the-tale
    def threads_info(self):
        if not self._account.is_authenticated:
            return {}

        time_barrier = datetime.datetime.now() - datetime.timedelta(
            seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME)

        return {
            thread.id: thread
            for thread in ThreadPrototype.from_query(
                ThreadPrototype._db_filter(updated_at__gt=time_barrier))
        }
コード例 #29
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)
コード例 #30
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)
コード例 #31
0
    def setUp(self):
        super(SubcategoryPrototypeUpdateTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()
        self.checked_account = 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=2)

        self.thread_1 = ThreadPrototype.create(self.subcategory, 'thread-1-caption', self.account, 'thread-1-text')
        self.thread_2 = ThreadPrototype.create(self.subcategory, 'thread-2-caption', self.account, 'thread-2-text')
コード例 #32
0
    def setUp(self):
        super(SubcategoryPrototypeUpdateTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()
        self.checked_account = 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=2)

        self.thread_1 = ThreadPrototype.create(self.subcategory, 'thread-1-caption', self.account, 'thread-1-text')
        self.thread_2 = ThreadPrototype.create(self.subcategory, 'thread-2-caption', self.account, 'thread-2-text')
コード例 #33
0
    def setUp(self):
        super(ReadStateTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=category, caption='subcat-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(category=category, caption='subcat-2-caption', order=0)

        self.thread = ThreadPrototype.create(self.subcategory, 'thread1-caption', self.account_2, 'thread-text')
        self.thread_2 = ThreadPrototype.create(self.subcategory, 'thread2-caption', self.account_2, 'thread-2-text')
        self.thread_3 = ThreadPrototype.create(self.subcategory_2, 'thread2-caption', self.account, 'thread-2-text')
コード例 #34
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)
コード例 #35
0
    def create(cls, owner, caption, rationale, bill, chronicle_on_accepted):

        model = Bill.objects.create(owner=owner._model,
                                    type=bill.type,
                                    caption=caption,
                                    rationale=rationale,
                                    created_at_turn=TimePrototype.get_current_turn_number(),
                                    technical_data=s11n.to_json(bill.serialize()),
                                    state=BILL_STATE.VOTING,
                                    chronicle_on_accepted=chronicle_on_accepted,
                                    votes_for=1) # author always wote for bill

        bill_prototype = cls(model)

        text = u'Обсуждение [url="%s%s"]закона[/url]' % (project_settings.SITE_URL,
                                                         reverse('game:bills:show', args=[model.id]) )

        thread = ThreadPrototype.create(SubCategoryPrototype.get_by_uid(bills_settings.FORUM_CATEGORY_UID),
                                        caption=caption,
                                        author=get_system_user(),
                                        text=bill_prototype.bill_info_text(text),
                                        technical=True,
                                        markup_method=MARKUP_METHOD.POSTMARKUP)

        model.forum_thread = thread._model
        model.save()

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

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

        signals.bill_created.send(sender=cls, bill=bill_prototype)

        return bill_prototype
コード例 #36
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)
コード例 #37
0
ファイル: views.py プロジェクト: angru/the-tale
    def feed(self):
        feed = Atom1Feed(u'Сказка: Форум',
                         self.request.build_absolute_uri('/'),
                         u'Новые темы на форуме мморпг «Сказка»',
                         language=u'ru',
                         feed_url=self.request.build_absolute_uri(
                             reverse('forum:feed')))

        threads = [
            ThreadPrototype(model=thread)
            for thread in Thread.objects.filter(subcategory__restricted=False).
            order_by('-created_at')[:forum_settings.FEED_ITEMS_NUMBER]
        ]

        for thread in threads:

            if datetime.datetime.now(
            ) - thread.created_at < datetime.timedelta(
                    seconds=forum_settings.FEED_ITEMS_DELAY):
                continue

            post = PostPrototype(model=Post.objects.filter(
                thread_id=thread.id).order_by('created_at')[0])

            url = self.request.build_absolute_uri(
                reverse('forum:threads:show', args=[thread.id]))

            feed.add_item(title=thread.caption,
                          link=url,
                          description=post.safe_html,
                          pubdate=thread.created_at,
                          unique_id=url)

        return self.atom(feed.writeString('utf-8'))
コード例 #38
0
ファイル: prototypes.py プロジェクト: ruckysolis/the-tale
    def create(cls, author, caption, text):

        model = models.Post.objects.create(author=author._model,
                                    caption=caption,
                                    text=text,
                                    state=relations.POST_STATE.ACCEPTED,
                                    created_at_turn=game_prototypes.TimePrototype.get_current_turn_number(),
                                    votes=1)

        thread = ForumThreadPrototype.create(ForumSubCategoryPrototype.get_by_uid(conf.settings.FORUM_CATEGORY_UID),
                                             caption=caption,
                                             author=get_system_user(),
                                             text=u'обсуждение [url="%s%s"]произведения[/url]' % (project_settings.SITE_URL,
                                                                                                  reverse('blogs:posts:show', args=[model.id])),
                                             markup_method=MARKUP_METHOD.POSTMARKUP)

        model.forum_thread = thread._model
        model.save()

        post = cls(model)

        VotePrototype.create(post, author)

        for tag_id in conf.settings.DEFAULT_TAGS:
            models.Tagged.objects.create(post_id=post.id, tag_id=tag_id)

        return post
コード例 #39
0
    def create(cls, author, caption, text):

        model = models.Post.objects.create(author=author._model,
                                           caption=caption,
                                           text=text,
                                           state=relations.POST_STATE.ACCEPTED,
                                           created_at_turn=turn.number(),
                                           votes=1)

        thread = ForumThreadPrototype.create(
            ForumSubCategoryPrototype.get_by_uid(
                conf.settings.FORUM_CATEGORY_UID),
            caption=caption,
            author=get_system_user(),
            text='обсуждение [url="%s%s"]произведения[/url]' %
            (project_settings.SITE_URL,
             reverse('blogs:posts:show', args=[model.id])),
            markup_method=MARKUP_METHOD.POSTMARKUP)

        model.forum_thread = thread._model
        model.save()

        post = cls(model)

        VotePrototype.create(post, author)

        for tag_id in conf.settings.DEFAULT_TAGS:
            models.Tagged.objects.create(post_id=post.id, tag_id=tag_id)

        return post
コード例 #40
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)
コード例 #41
0
    def setUp(self):
        super(SubscriptionPrototypeTests, self).setUp()
        create_test_map()

        self.account = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory_1 = SubCategoryPrototype.create(category=self.category, caption='subcat-1-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(category=self.category, caption='subcat-2-caption', order=1)

        self.thread_1_1 = ThreadPrototype.create(self.subcategory_1, 'thread-1-1-caption', self.account, 'thread-1-1-text')
        self.thread_1_2 = ThreadPrototype.create(self.subcategory_1, 'thread-1-2-caption', self.account, 'thread-1-2-text')
        self.thread_1_3 = ThreadPrototype.create(self.subcategory_1, 'thread-1-3-caption', self.account_2, 'thread-1-3-text')
        self.thread_2_1 = ThreadPrototype.create(self.subcategory_2, 'thread-2-1-caption', self.account, 'thread-2-1-text')
        self.thread_2_2 = ThreadPrototype.create(self.subcategory_2, 'thread-2-2-caption', self.account, 'thread-2-2-text')
コード例 #42
0
ファイル: prototypes.py プロジェクト: Alkalit/the-tale
    def create(cls, owner, caption, rationale, bill, chronicle_on_accepted):

        model = Bill.objects.create(owner=owner._model,
                                    type=bill.type,
                                    caption=caption,
                                    rationale=rationale,
                                    created_at_turn=TimePrototype.get_current_turn_number(),
                                    technical_data=s11n.to_json(bill.serialize()),
                                    state=BILL_STATE.VOTING,
                                    chronicle_on_accepted=chronicle_on_accepted,
                                    votes_for=1) # author always wote for bill

        bill_prototype = cls(model)

        text = u'Обсуждение [url="%s%s"]закона[/url]' % (project_settings.SITE_URL,
                                                         reverse('game:bills:show', args=[model.id]) )

        thread = ThreadPrototype.create(SubCategoryPrototype.get_by_uid(bills_settings.FORUM_CATEGORY_UID),
                                        caption=caption,
                                        author=get_system_user(),
                                        text=bill_prototype.bill_info_text(text),
                                        technical=True,
                                        markup_method=MARKUP_METHOD.POSTMARKUP)

        model.forum_thread = thread._model
        model.save()

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

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

        signals.bill_created.send(sender=cls, bill=bill_prototype)

        return bill_prototype
コード例 #43
0
ファイル: test_prototypes.py プロジェクト: Alkalit/the-tale
    def setUp(self):
        super(SubcategoryPrototypeUpdateTests, self).setUp()

        create_test_map()

        register_user('test_user', '*****@*****.**', '111111')
        register_user('checked_user', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('test_user')
        self.checked_account = AccountPrototype.get_by_nick('checked_user')

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=2)

        self.thread_1 = ThreadPrototype.create(self.subcategory, 'thread-1-caption', self.account, 'thread-1-text')
        self.thread_2 = ThreadPrototype.create(self.subcategory, 'thread-2-caption', self.account, 'thread-2-text')
コード例 #44
0
    def get_subcategory(self, page=1):

        threads_query = Thread.objects.filter(subcategory=self.subcategory._model)

        url_builder = UrlBuilder(reverse('forum:subcategories:show', args=[self.subcategory.id]), arguments={'page': page})

        page -= 1

        paginator = Paginator(page, threads_query.count(), forum_settings.THREADS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        thread_from, thread_to = paginator.page_borders(page)

        threads = ThreadPrototype.from_query(threads_query.select_related().order_by('-important', '-updated_at')[thread_from:thread_to])

        important_threads = sorted([t for t in threads if t.important], key=lambda t: t.caption)
        threads = [t for t in threads if not t.important]

        read_state = ReadState(account=self.account)

        if self.account.is_authenticated:
            SubCategoryReadInfoPrototype.read_subcategory(subcategory=self.subcategory, account=self.account)

        return self.template('forum/subcategory.html',
                             {'category': self.category,
                              'subcategory': self.subcategory,
                              'can_create_thread': can_create_thread(self.account, self.subcategory),
                              'paginator': paginator,
                              'can_subscribe': self.account.is_authenticated and not self.account.is_fast,
                              'has_subscription': SubscriptionPrototype.has_subscription(self.account, subcategory=self.subcategory),
                              'threads': threads,
                              'important_threads': important_threads,
                              'read_state': read_state } )
コード例 #45
0
    def test_delete(self):
        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)

        subcategory_1 = SubCategoryPrototype.create(category=category, caption='subcat-1-caption', order=2)
        subcategory_2 = SubCategoryPrototype.create(category=category, caption='subcat-2-caption', order=1)

        thread_1_1 = ThreadPrototype.create(subcategory_1, 'thread-1_1-caption', self.account, 'thread-1_1-text')
        thread_1_2 = ThreadPrototype.create(subcategory_1, 'thread-1_2-caption', self.account, 'thread-1_2-text')
        thread_2_1 = ThreadPrototype.create(subcategory_2, 'thread-2_1-caption', self.account, 'thread-2_1-text')

        subcategory_1.delete()

        self.assertFalse(ThreadPrototype._db_filter(id__in=(thread_1_1.id, thread_1_2.id)).exists())
        self.assertTrue(ThreadPrototype._db_filter(id=thread_2_1.id).exists())

        self.assertFalse(SubCategoryPrototype._db_filter(id=subcategory_1.id).exists())
        self.assertTrue(SubCategoryPrototype._db_filter(id=subcategory_2.id).exists())
コード例 #46
0
ファイル: test_read_state.py プロジェクト: lshestov/the-tale
    def setUp(self):
        super(ReadStateTests, self).setUp()
        create_test_map()

        register_user("user_1", "*****@*****.**", "111111")
        register_user("user_2", "*****@*****.**", "111111")

        self.account = AccountPrototype.get_by_nick("user_1")
        self.account_2 = AccountPrototype.get_by_nick("user_2")

        category = CategoryPrototype.create(caption="cat-caption", slug="cat-slug", order=0)
        self.subcategory = SubCategoryPrototype.create(category=category, caption="subcat-caption", order=0)
        self.subcategory_2 = SubCategoryPrototype.create(category=category, caption="subcat-2-caption", order=0)

        self.thread = ThreadPrototype.create(self.subcategory, "thread1-caption", self.account_2, "thread-text")
        self.thread_2 = ThreadPrototype.create(self.subcategory, "thread2-caption", self.account_2, "thread-2-text")
        self.thread_3 = ThreadPrototype.create(self.subcategory_2, "thread2-caption", self.account, "thread-2-text")
コード例 #47
0
    def test_last_forum_posts_with_permissions(self):
        granted_account = self.accounts_factory.create_account()
        wrong_account = self.accounts_factory.create_account()

        restricted_subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat2-caption', order=1, restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        restricted_thread = ThreadPrototype.create(restricted_subcategory, 'thread-restricted-caption', self.account, 'thread-text')

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=None, limit=3)),
                         set([self.thread.id]))

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=granted_account, limit=3)),
                         set([self.thread.id, restricted_thread.id]))

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=wrong_account, limit=3)),
                         set([self.thread.id]))
コード例 #48
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_importans_threads_on_first_page(self):
        texts = [self.thread1.caption,
                 (self.thread2.caption, 0),
                 (self.thread3.caption, 0)]

        self.thread2._model.important = True
        self.thread2.save()

        for i in xrange(forum_settings.THREADS_ON_PAGE):
            caption = 'thread-x-%d-caption' % i
            ThreadPrototype.create(self.subcat1, caption, self.account, 'thread-text')
            if i != 0:
                texts.append((caption, 0))
            else:
                texts.append(caption)

        self.check_html_ok(self.request_html(url('forum:subcategories:show', self.subcat1.id, page=2)), texts=texts)

        self.check_html_ok(self.request_html(url('forum:subcategories:show', self.subcat1.id, page=1)), texts=[self.thread2.caption])
コード例 #49
0
ファイル: test_prototypes.py プロジェクト: Alkalit/the-tale
    def setUp(self):
        super(SubscriptionPrototypeTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory_1 = SubCategoryPrototype.create(category=self.category, caption='subcat-1-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(category=self.category, caption='subcat-2-caption', order=1)

        self.thread_1_1 = ThreadPrototype.create(self.subcategory_1, 'thread-1-1-caption', self.account, 'thread-1-1-text')
        self.thread_1_2 = ThreadPrototype.create(self.subcategory_1, 'thread-1-2-caption', self.account, 'thread-1-2-text')
        self.thread_1_3 = ThreadPrototype.create(self.subcategory_1, 'thread-1-3-caption', self.account_2, 'thread-1-3-text')
        self.thread_2_1 = ThreadPrototype.create(self.subcategory_2, 'thread-2-1-caption', self.account, 'thread-2-1-text')
        self.thread_2_2 = ThreadPrototype.create(self.subcategory_2, 'thread-2-2-caption', self.account, 'thread-2-2-text')
コード例 #50
0
ファイル: views.py プロジェクト: angru/the-tale
    def get_subcategory(self, page=1):

        threads_query = Thread.objects.filter(
            subcategory=self.subcategory._model)

        url_builder = UrlBuilder(reverse('forum:subcategories:show',
                                         args=[self.subcategory.id]),
                                 arguments={'page': page})

        page -= 1

        paginator = Paginator(page, threads_query.count(),
                              forum_settings.THREADS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        thread_from, thread_to = paginator.page_borders(page)

        threads = ThreadPrototype.from_query(
            threads_query.select_related().order_by(
                '-important', '-updated_at')[thread_from:thread_to])

        important_threads = sorted(filter(lambda t: t.important, threads),
                                   key=lambda t: t.caption)
        threads = filter(lambda t: not t.important, threads)

        read_state = ReadState(account=self.account)

        if self.account.is_authenticated():
            SubCategoryReadInfoPrototype.read_subcategory(
                subcategory=self.subcategory, account=self.account)

        return self.template(
            'forum/subcategory.html', {
                'category':
                self.category,
                'subcategory':
                self.subcategory,
                'can_create_thread':
                can_create_thread(self.account, self.subcategory),
                'paginator':
                paginator,
                'can_subscribe':
                self.account.is_authenticated() and not self.account.is_fast,
                'has_subscription':
                SubscriptionPrototype.has_subscription(
                    self.account, subcategory=self.subcategory),
                'threads':
                threads,
                'important_threads':
                important_threads,
                'read_state':
                read_state
            })
コード例 #51
0
ファイル: test_prototypes.py プロジェクト: Alkalit/the-tale
    def setUp(self):
        super(ThreadPrototypeTests, self).setUp()
        create_test_map()

        register_user('test_user', '*****@*****.**', '111111')
        self.account = AccountPrototype.get_by_nick('test_user')

        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-caption', self.account, 'thread-text')
コード例 #52
0
    def setUp(self):
        super(NewForumThreadTests, 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')

        self.message = MessagePrototype.get_priority_message()
コード例 #53
0
    def setUp(self):
        super(NewForumThreadTests, 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')

        self.message = MessagePrototype.get_priority_message()
コード例 #54
0
ファイル: test_prototypes.py プロジェクト: Alkalit/the-tale
    def test_last_forum_posts_with_permissions(self):

        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')


        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        restricted_subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat2-caption', order=1, restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        restricted_thread = ThreadPrototype.create(restricted_subcategory, 'thread-restricted-caption', self.account, 'thread-text')

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=None, limit=3)),
                         set([self.thread.id]))

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=granted_account, limit=3)),
                         set([self.thread.id, restricted_thread.id]))

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=wrong_account, limit=3)),
                         set([self.thread.id]))
コード例 #55
0
ファイル: test_prototypes.py プロジェクト: Alkalit/the-tale
    def setUp(self):
        super(ThreadReadInfoPrototypeTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        subcategory = SubCategoryPrototype.create(category=category, caption='subcat-caption', order=0)

        self.thread = ThreadPrototype.create(subcategory, 'thread1-caption', self.account, 'thread-text')
コード例 #56
0
ファイル: views.py プロジェクト: Jazzis18/the-tale
    def index(self):

        if portal_settings.ENABLE_FIRST_TIME_REDIRECT and accounts_logic.is_first_time_visit(self.request):
            return self.redirect(random.choice(portal_settings.FIRST_TIME_LANDING_URLS))

        news = news_logic.load_news_from_query(news_models.News.objects.all().order_by('-created_at')[:portal_settings.NEWS_ON_INDEX])

        bills = BillPrototype.get_recently_modified_bills(portal_settings.BILLS_ON_INDEX)

        account_of_the_day_id = settings.get(portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY)

        hero_of_the_day = None
        account_of_the_day = None
        clan_of_the_day = None

        if account_of_the_day_id is not None:
            hero_of_the_day = heroes_logic.load_hero(account_id=account_of_the_day_id)
            account_of_the_day = AccountPrototype.get_by_id(account_of_the_day_id)

            if account_of_the_day.clan_id is not None:
                clan_of_the_day = ClanPrototype.get_by_id(account_of_the_day.clan_id)

        forum_threads = ThreadPrototype.get_last_threads(account=self.account if self.account.is_authenticated() else None,
                                                         limit=portal_settings.FORUM_THREADS_ON_INDEX)

        blog_posts = [ BlogPostPrototype(blog_post_model)
                       for blog_post_model in BlogPost.objects.filter(state__in=[BLOG_POST_STATE.ACCEPTED, BLOG_POST_STATE.NOT_MODERATED],
                                                                      votes__gte=0).order_by('-created_at')[:portal_settings.BLOG_POSTS_ON_INDEX] ]

        map_info = map_info_storage.item

        chronicle_records = ChronicleRecordPrototype.get_last_records(portal_settings.CHRONICLE_RECORDS_ON_INDEX)

        chronicle_actors = RecordToActorPrototype.get_actors_for_records(chronicle_records)

        return self.template('portal/index.html',
                             {'news': news,
                              'forum_threads': forum_threads,
                              'bills': bills,
                              'hero_of_the_day': hero_of_the_day,
                              'account_of_the_day': account_of_the_day,
                              'clan_of_the_day': clan_of_the_day,
                              'map_info': map_info,
                              'blog_posts': blog_posts,
                              'TERRAIN': TERRAIN,
                              'MAP_STATISTICS': MAP_STATISTICS,
                              'chronicle_records': chronicle_records,
                              'chronicle_actors': chronicle_actors,
                              'RACE': RACE})
コード例 #57
0
    def create_thread(self):

        if not can_create_thread(self.account, self.subcategory):
            return self.json_error('forum.create_thread.no_permissions', 'Вы не можете создавать темы в данном разделе')

        new_thread_delay = ThreadPrototype.get_new_thread_delay(self.account)
        if new_thread_delay > 0:
            error_message = ('Создавать новые обсуждения можно не чаще раза в %d минут.<br/> Вы сможете создать новое обсуждение через %d сек.' %
                             ( int(forum_settings.THREAD_DELAY / 60),
                               int(new_thread_delay)))
            return self.json_error('forum.create_thread.delay', error_message)

        new_thread_form = forms.NewThreadForm(self.request.POST)

        if not new_thread_form.is_valid():
            return self.json_error('forum.create_thread.form_errors', new_thread_form.errors)

        thread = ThreadPrototype.create(self.subcategory,
                                        caption=new_thread_form.c.caption,
                                        author=self.account,
                                        text=new_thread_form.c.text)

        return self.json_ok(data={'thread_url': reverse('forum:threads:show', args=[thread.id]),
                                  'thread_id': thread.id})
コード例 #58
0
    def process(self):
        from the_tale.forum.prototypes import ThreadPrototype, SubscriptionPrototype

        thread = ThreadPrototype.get_by_id(self.thread_id)

        if thread is None:
            return True # thread can be removed by admins or with removed thread

        post = thread.get_first_post()

        accounts = SubscriptionPrototype.get_accounts_for_subcategory(thread.subcategory)

        subject = '«Сказка»: новая тема на форуме'

        context = {'thread': thread,
                   'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
コード例 #59
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')