コード例 #1
0
 def test_read_thread__unexisted_info(self):
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
     read_info = ThreadReadInfoPrototype.read_thread(self.thread, self.account)
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
     self.assertEqual(read_info.thread_id, self.thread.id)
     self.assertEqual(read_info.account_id, self.account.id)
     self.assertTrue(read_info.read_at > datetime.datetime.now() - datetime.timedelta(seconds=1))
コード例 #2
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)
            })
コード例 #3
0
 def test_read_thread__unexisted_info(self):
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
     read_info = ThreadReadInfoPrototype.read_thread(self.thread, self.account)
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
     self.assertEqual(read_info.thread_id, self.thread.id)
     self.assertEqual(read_info.account_id, self.account.id)
     self.assertTrue(read_info.read_at > datetime.datetime.now() - datetime.timedelta(seconds=1))
コード例 #4
0
    def test_thread_is_new_messages__thread_read(self):
        read_state = self.get_read_state()
        self.assertTrue(read_state.thread_is_new(self.thread))

        ThreadReadInfoPrototype.read_thread(self.thread, self.account)
        read_state = self.get_read_state()

        self.assertFalse(read_state.thread_is_new(self.thread))
コード例 #5
0
ファイル: test_read_state.py プロジェクト: serhii73/the-tale
    def test_thread_is_new_messages__thread_read(self):
        read_state = self.get_read_state()
        self.assertTrue(read_state.thread_is_new(self.thread))

        ThreadReadInfoPrototype.read_thread(self.thread, self.account)
        read_state = self.get_read_state()

        self.assertFalse(read_state.thread_is_new(self.thread))
コード例 #6
0
ファイル: test_read_state.py プロジェクト: serhii73/the-tale
    def test_thread_has_new_messages__read(self):
        ThreadReadInfoPrototype.read_thread(self.thread, self.account)

        read_state = self.get_read_state()

        self.assertFalse(read_state.thread_has_new_messages(self.thread))

        self.thread._model.updated_at = datetime.datetime.now()
        self.thread.save()

        self.assertTrue(read_state.thread_has_new_messages(self.thread))
コード例 #7
0
ファイル: portal_clean.py プロジェクト: lshestov/the-tale
    def handle(self, *args, **options):
        from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype
        from the_tale.forum.prototypes import SubCategoryReadInfoPrototype, ThreadReadInfoPrototype
        from the_tale.post_service.prototypes import MessagePrototype

        PostponedTaskPrototype.remove_old_tasks()

        ThreadReadInfoPrototype.remove_old_infos()
        SubCategoryReadInfoPrototype.remove_old_infos()

        MessagePrototype.remove_old_messages()
コード例 #8
0
    def test_thread_has_new_messages__read(self):
        ThreadReadInfoPrototype.read_thread(self.thread, self.account)

        read_state = self.get_read_state()

        self.assertFalse(read_state.thread_has_new_messages(self.thread))

        self.thread._model.updated_at = datetime.datetime.now()
        self.thread.save()

        self.assertTrue(read_state.thread_has_new_messages(self.thread))
コード例 #9
0
    def handle(self, *args, **options):
        from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype
        from the_tale.forum.prototypes import SubCategoryReadInfoPrototype, ThreadReadInfoPrototype
        from the_tale.post_service.prototypes import MessagePrototype

        PostponedTaskPrototype.remove_old_tasks()

        ThreadReadInfoPrototype.remove_old_infos()
        SubCategoryReadInfoPrototype.remove_old_infos()

        MessagePrototype.remove_old_messages()
コード例 #10
0
    def test_create_post_success(self):

        self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)

        response = self.client.post(url('forum:threads:create-post', self.thread3.id), {'text': 'thread3-test-post'})

        post = PostPrototype._db_get_object(4)

        self.check_ajax_ok(response, data={'next_url': url('forum:threads:show', self.thread3.id) + ('?page=1#m%d' % post.id)})

        self.assertEqual(Post.objects.all().count(), 5)

        self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
        self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).thread_id, self.thread3.id)
コード例 #11
0
    def get_thread(self, page=1):

        thread_data = ThreadPageData()

        if not thread_data.initialize(account=self.account, thread=self.thread, page=page):
            return self.redirect(thread_data.paginator.last_page_url, permanent=False)

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

        return self.template('forum/thread.html',
                             {'category': self.category,
                              'thread': self.thread,
                              'thread_data': thread_data} )
コード例 #12
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
    def test_create_post_success(self):

        self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)

        response = self.client.post(url('forum:threads:create-post', self.thread3.id), {'text': 'thread3-test-post'})

        post = PostPrototype._db_get_object(4)

        self.check_ajax_ok(response, data={'next_url': url('forum:threads:show', self.thread3.id) + ('?page=1#m%d' % post.id)})

        self.assertEqual(Post.objects.all().count(), 5)

        self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
        self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).thread_id, self.thread3.id)
コード例 #13
0
ファイル: views.py プロジェクト: angru/the-tale
    def get_thread(self, page=1):

        thread_data = ThreadPageData()

        if not thread_data.initialize(
                account=self.account, thread=self.thread, page=page):
            return self.redirect(thread_data.paginator.last_page_url,
                                 permanent=False)

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

        return self.template(
            'forum/thread.html', {
                'category': self.category,
                'thread': self.thread,
                'thread_data': thread_data
            })
コード例 #14
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)})
コード例 #15
0
    def test_remove_old_infos(self):
        read_info_1 = ThreadReadInfoPrototype.read_thread(self.thread, self.account)
        read_info_2 = ThreadReadInfoPrototype.read_thread(self.thread, self.account_2)

        removed_time = datetime.datetime.now() - datetime.timedelta(seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME)
        ThreadReadInfoPrototype._model_class.objects.filter(id=read_info_2.id).update(read_at=removed_time)

        self.assertEqual(ThreadReadInfoPrototype._db_count(), 2)
        ThreadReadInfoPrototype.remove_old_infos()
        self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
        self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).id, read_info_1.id)
コード例 #16
0
    def test_remove_old_infos(self):
        read_info_1 = ThreadReadInfoPrototype.read_thread(self.thread, self.account)
        read_info_2 = ThreadReadInfoPrototype.read_thread(self.thread, self.account_2)

        removed_time = datetime.datetime.now() - datetime.timedelta(seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME)
        ThreadReadInfoPrototype._model_class.objects.filter(id=read_info_2.id).update(read_at=removed_time)

        self.assertEqual(ThreadReadInfoPrototype._db_count(), 2)
        ThreadReadInfoPrototype.remove_old_infos()
        self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
        self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).id, read_info_1.id)
コード例 #17
0
 def test_subcategory_has_new_messages__unread_but_thread_read(self):
     SubCategoryReadInfoPrototype.read_subcategory(subcategory=self.subcategory, account=self.account)
     self.subcategory._model.updated_at = datetime.datetime.now()
     self.subcategory.save()
     self.assertTrue(self.get_read_state().subcategory_has_new_messages(self.subcategory))
     ThreadReadInfoPrototype.read_thread(self.thread, self.account)
     ThreadReadInfoPrototype.read_thread(self.thread_2, self.account)
     ThreadReadInfoPrototype.read_thread(self.thread_3, self.account)
     self.assertFalse(self.get_read_state().subcategory_has_new_messages(self.subcategory))
コード例 #18
0
ファイル: test_read_state.py プロジェクト: serhii73/the-tale
 def test_subcategory_has_new_messages__unread_but_thread_read(self):
     SubCategoryReadInfoPrototype.read_subcategory(
         subcategory=self.subcategory, account=self.account)
     self.subcategory._model.updated_at = datetime.datetime.now()
     self.subcategory.save()
     self.assertTrue(self.get_read_state().subcategory_has_new_messages(
         self.subcategory))
     ThreadReadInfoPrototype.read_thread(self.thread, self.account)
     ThreadReadInfoPrototype.read_thread(self.thread_2, self.account)
     ThreadReadInfoPrototype.read_thread(self.thread_3, self.account)
     self.assertFalse(self.get_read_state().subcategory_has_new_messages(
         self.subcategory))
コード例 #19
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
 def test_get_thread_unlogined(self):
     self.request_logout()
     self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=(('pgf-new-post-form', 0),
                                                                                              self.fixture.clan_1.abbr))
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
コード例 #20
0
 def test_get_thread(self):
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
     self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=('pgf-new-post-form',))
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
コード例 #21
0
 def test_get_thread_unlogined(self):
     self.request_logout()
     self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=(('pgf-new-post-form', 0),
                                                                                              self.fixture.clan_1.abbr))
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
コード例 #22
0
ファイル: test_requests.py プロジェクト: Alkalit/the-tale
 def test_get_thread(self):
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
     self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=('pgf-new-post-form',))
     self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
コード例 #23
0
ファイル: read_state.py プロジェクト: Alkalit/the-tale
    def get_threads_read_info(self):
        if not self._account.is_authenticated():
            return {}

        return ThreadReadInfoPrototype.get_threads_info(account_id=self._account.id)
コード例 #24
0
ファイル: read_state.py プロジェクト: serhii73/the-tale
    def get_threads_read_info(self):
        if not self._account.is_authenticated:
            return {}

        return ThreadReadInfoPrototype.get_threads_info(
            account_id=self._account.id)