• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Thread类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misago.threads.models.Thread的典型用法代码示例。如果您正苦于以下问题:Python Thread类的具体用法?Python Thread怎么用?Python Thread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Thread类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: split_posts_to_new_thread

def split_posts_to_new_thread(request, thread, validated_data, posts):
    new_thread = Thread(
        category=validated_data['category'],
        started_on=thread.started_on,
        last_post_on=thread.last_post_on,
    )

    new_thread.set_title(validated_data['title'])
    new_thread.save()

    for post in posts:
        post.move(new_thread)
        post.save()

    thread.synchronize()
    thread.save()

    new_thread.synchronize()
    new_thread.save()

    if validated_data.get('weight') == Thread.WEIGHT_GLOBAL:
        moderation.pin_thread_globally(request, new_thread)
    elif validated_data.get('weight'):
        moderation.pin_thread_locally(request, new_thread)
    if validated_data.get('is_hidden', False):
        moderation.hide_thread(request, new_thread)
    if validated_data.get('is_closed', False):
        moderation.close_thread(request, new_thread)

    thread.category.synchronize()
    thread.category.save()

    if new_thread.category != thread.category:
        new_thread.category.synchronize()
        new_thread.category.save()
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:35,代码来源:split.py


示例2: EventsAPITests

class EventsAPITests(TestCase):
    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester'
        )

        self.thread.set_title("Test thread")
        self.thread.save()

        add_acl(self.user, self.category)
        add_acl(self.user, self.thread)

    def test_record_event(self):
        """record_event registers event in thread"""
        message = "%(user)s has changed this thread to announcement."
        event = record_event(self.user, self.thread, "announcement", message, {
            'user': (u"Łob", self.user.get_absolute_url())
        })

        self.assertTrue(event.is_valid)
        self.assertTrue(event.message.endswith(message[8:]))
        self.assertTrue(self.thread.has_events)

    def test_add_events_to_posts(self):
        """add_events_to_posts makes posts event-aware"""
        message = "Test event was recorded."

        for p in xrange(2):
            reply_thread(self.thread, posted_on=timezone.now())
        event = record_event(self.user, self.thread, "check", message)
        for p in xrange(2):
            reply_thread(self.thread, posted_on=timezone.now())

        posts = [p for p in self.thread.post_set.all().order_by('id')]
        add_events_to_posts(self.user, self.thread, posts)

        for i, post in enumerate(posts):
            if i == 1:
                self.assertEqual(post.events[0].message, message)
            else:
                self.assertEqual(post.events, [])
开发者ID:Didan,项目名称:Misago,代码行数:53,代码来源:test_events.py


示例3: setUp

    def setUp(self):
        datetime = timezone.now()

        self.forum = Forum.objects.filter(role="forum")[:1][0]
        self.thread = Thread(
            forum=self.forum,
            weight=0,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester')

        self.thread.set_title("Test thread")
        self.thread.save()

        post = Post.objects.create(
            forum=self.forum,
            thread=self.thread,
            poster_name='Tester',
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime)

        self.thread.first_post = post
        self.thread.last_post = post
        self.thread.save()
开发者ID:dahito,项目名称:Misago,代码行数:31,代码来源:test_thread_model.py


示例4: setUp

    def setUp(self):
        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester'
        )

        self.thread.set_title("Test thread")
        self.thread.save()

        post = Post.objects.create(
            category=self.category,
            thread=self.thread,
            poster_name='Tester',
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime
        )

        self.thread.first_post = post
        self.thread.last_post = post
        self.thread.save()
开发者ID:Didan,项目名称:Misago,代码行数:32,代码来源:test_participants.py


示例5: create_thread

def create_thread(forum):
    thread = Thread()
    thread.forum = forum
    thread.name = 'Test Thread'
    thread.slug = 'test-thread'
    thread.start = timezone.now()
    thread.last = timezone.now()
    thread.save(force_insert=True)
    return thread
开发者ID:tylercole,项目名称:Misago,代码行数:9,代码来源:testutils.py


示例6: EventModelTests

class EventModelTests(TestCase):
    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester'
        )

        self.thread.set_title("Test thread")
        self.thread.save()

    def test_is_event_valid(self):
        """event is_valid flag returns valid value"""
        event = Event.objects.create(
            category=self.category,
            thread=self.thread,
            author=self.user,
            message="Lorem ipsum",
            author_name=self.user.username,
            author_slug=self.user.slug
        )

        update_event_checksum(event)

        self.assertTrue(is_event_valid(event))
        self.assertTrue(event.is_valid)

        event.message = "Ipsum lorem"

        self.assertFalse(is_event_valid(event))
        self.assertFalse(event.is_valid)
开发者ID:Didan,项目名称:Misago,代码行数:41,代码来源:test_event_model.py


示例7: EventsAPITests

class EventsAPITests(TestCase):
    def setUp(self):
        self.user = UserModel.objects.create_user("Bob", "[email protected]", "Pass.123")

        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester',
        )

        self.thread.set_title("Test thread")
        self.thread.save()

        add_acl(self.user, self.category)
        add_acl(self.user, self.thread)

    def test_record_event_with_context(self):
        """record_event registers event with context in thread"""
        request = MockRequest(self.user)
        context = {'user': 'Lorem ipsum'}
        event = record_event(request, self.thread, 'announcement', context)

        event_post = self.thread.post_set.order_by('-id')[:1][0]
        self.assertEqual(self.thread.last_post, event_post)
        self.assertTrue(self.thread.has_events)
        self.assertTrue(self.thread.last_post_is_event)

        self.assertEqual(event.pk, event_post.pk)
        self.assertTrue(event_post.is_event)
        self.assertEqual(event_post.event_type, 'announcement')
        self.assertEqual(event_post.event_context, context)
        self.assertEqual(event_post.poster_id, request.user.pk)
        self.assertEqual(event_post.poster_ip, request.user_ip)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:40,代码来源:test_events.py


示例8: test_merge

    def test_merge(self):
        """merge(other_thread) moves other thread content to this thread"""
        with self.assertRaises(ValueError):
            self.thread.merge(self.thread)

        datetime = timezone.now() + timedelta(5)

        other_thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester',
        )

        other_thread.set_title("Other thread")
        other_thread.save()

        post = Post.objects.create(
            category=self.category,
            thread=other_thread,
            poster_name='Admin',
            poster_ip='127.0.0.1',
            original="Hello! I am other message!",
            parsed="<p>Hello! I am other message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime,
        )

        other_thread.first_post = post
        other_thread.last_post = post
        other_thread.save()

        self.thread.merge(other_thread)

        self.thread.synchronize()
        self.assertEqual(self.thread.replies, 1)
        self.assertEqual(self.thread.last_post, post)
        self.assertEqual(self.thread.last_post_on, post.posted_on)
        self.assertEqual(self.thread.last_poster_name, "Admin")
        self.assertEqual(self.thread.last_poster_slug, "admin")
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:44,代码来源:test_thread_model.py


示例9: setUp

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        datetime = timezone.now()

        self.forum = Forum.objects.filter(role="forum")[:1][0]
        self.thread = Thread(
            forum=self.forum,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester')

        self.thread.set_title("Test thread")
        self.thread.save()
开发者ID:Backenkoehler,项目名称:Misago,代码行数:18,代码来源:test_event_model.py


示例10: setUp

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester'
        )

        self.thread.set_title("Test thread")
        self.thread.save()
开发者ID:Didan,项目名称:Misago,代码行数:19,代码来源:test_event_model.py


示例11: setUp

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        datetime = timezone.now()

        self.forum = Forum.objects.filter(role="forum")[:1][0]
        self.thread = Thread(
            forum=self.forum,
            weight=0,
            started_on=datetime,
            starter_name="Tester",
            starter_slug="tester",
            last_post_on=datetime,
            last_poster_name="Tester",
            last_poster_slug="tester",
        )

        self.thread.set_title("Test thread")
        self.thread.save()

        self.post = Post.objects.create(
            forum=self.forum,
            thread=self.thread,
            poster=self.user,
            poster_name=self.user.username,
            poster_ip="127.0.0.1",
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime,
        )

        update_post_checksum(self.post)
        self.post.save(update_fields=["checksum"])

        self.thread.first_post = self.post
        self.thread.last_post = self.post
        self.thread.save()
开发者ID:sun5495,项目名称:Misago,代码行数:40,代码来源:test_post_model.py


示例12: action_merge

    def action_merge(self, request, threads):
        if len(threads) == 1:
            message = _("You have to select at least two threads to merge.")
            raise moderation.ModerationError(message)

        form = MergeThreadsForm()

        if request.method == "POST" and 'submit' in request.POST:
            form = MergeThreadsForm(request.POST)
            if form.is_valid():
                thread_title = form.cleaned_data['merged_thread_title']

                with atomic():
                    merged_thread = Thread()
                    merged_thread.forum = self.forum
                    merged_thread.set_title(
                        form.cleaned_data['merged_thread_title'])
                    merged_thread.starter_name = "-"
                    merged_thread.starter_slug = "-"
                    merged_thread.last_poster_name = "-"
                    merged_thread.last_poster_slug = "-"
                    merged_thread.started_on = timezone.now()
                    merged_thread.last_post_on = timezone.now()
                    merged_thread.is_pinned = max(t.is_pinned for t in threads)
                    merged_thread.is_closed = max(t.is_closed for t in threads)
                    merged_thread.save()

                    for thread in threads:
                        moderation.merge_thread(
                            request.user, merged_thread, thread)

                    merged_thread.synchronize()
                    merged_thread.save()

                with atomic():
                    self.forum.synchronize()
                    self.forum.save()

                changed_threads = len(threads)
                message = ungettext(
                    '%(changed)d thread was merged into "%(thread)s".',
                    '%(changed)d threads were merged into "%(thread)s".',
                changed_threads)
                messages.success(request, message % {
                    'changed': changed_threads,
                    'thread': merged_thread.title
                })

                return None # trigger threads list refresh

        if request.is_ajax():
            template = self.merge_threads_modal_template
        else:
            template = self.merge_threads_full_template

        return render(request, template, {
            'form': form,
            'forum': self.forum,
            'path': get_forum_path(self.forum),
            'threads': threads
        })
开发者ID:nikescar,项目名称:Misago,代码行数:61,代码来源:actions.py


示例13: merge_threads

def merge_threads(user, validated_data, threads):
    new_thread = Thread(
        category=validated_data['category'],
        weight=validated_data.get('weight', 0),
        is_closed=validated_data.get('is_closed', False),
        started_on=threads[0].started_on,
        last_post_on=threads[0].last_post_on,
    )

    new_thread.set_title(validated_data['title'])
    new_thread.save()

    categories = []
    for thread in threads:
        categories.append(thread.category)
        new_thread.merge(thread)
        thread.delete()

    new_thread.synchronize()
    new_thread.save()

    if new_thread.category not in categories:
        categories.append(new_thread.category)

    for category in categories:
        category.synchronize()
        category.save()

    # set extra attrs on thread for UI
    new_thread.is_read = False
    new_thread.subscription = None

    # add top category to thread
    if validated_data.get('top_category'):
        categories = list(Category.objects.all_categories().filter(
            id__in=user.acl['visible_categories']
        ))
        add_categories_to_threads(
            validated_data['top_category'], categories, [new_thread])
    else:
        new_thread.top_category = None

    new_thread.save()

    add_acl(user, new_thread)
    return new_thread
开发者ID:mayblue9,项目名称:Misago,代码行数:46,代码来源:merge.py


示例14: handle

    def handle(self, *args, **options):
        try:
            fake_threads_to_create = int(args[0])
        except IndexError:
            fake_threads_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        forums = [f for f in Forum.objects.all_forums().filter(role='forum')]

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, fake_threads_to_create)
        for i in xrange(fake_threads_to_create):
            with atomic():
                datetime = timezone.now()
                forum = random.choice(forums)
                user = User.objects.order_by('?')[:1][0]

                thread_is_moderated = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    forum=forum,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=random.randint(0, 2000),
                    is_moderated=thread_is_moderated,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed)
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    forum=forum,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime)
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                forum.threads += 1
                forum.posts += 1
                forum.set_last_thread(thread)
                forum.save()

                user.threads += 1
                user.posts += 1
                user.save()

                created_threads += 1
                show_progress(
                    self, created_threads, fake_threads_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in xrange(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            thread.is_pinned = True
            thread.save()

        self.stdout.write(message % created_threads)
开发者ID:hwy801207,项目名称:Misago,代码行数:87,代码来源:createfakethreads.py


示例15: ParticipantsTests

class ParticipantsTests(TestCase):
    def setUp(self):
        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester'
        )

        self.thread.set_title("Test thread")
        self.thread.save()

        post = Post.objects.create(
            category=self.category,
            thread=self.thread,
            poster_name='Tester',
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime
        )

        self.thread.first_post = post
        self.thread.last_post = post
        self.thread.save()

    def test_thread_has_participants(self):
        """thread_has_participants returns true if thread has participants"""
        User = get_user_model()
        user = User.objects.create_user(
            "Bob", "[email protected]", "Pass.123")
        other_user = User.objects.create_user(
            "Bob2", "[email protected]", "Pass.123")

        self.assertFalse(thread_has_participants(self.thread))

        ThreadParticipant.objects.add_participant(self.thread, user)
        self.assertTrue(thread_has_participants(self.thread))

        ThreadParticipant.objects.add_participant(self.thread, other_user)
        self.assertTrue(thread_has_participants(self.thread))

        self.thread.threadparticipant_set.all().delete()
        self.assertFalse(thread_has_participants(self.thread))

    def test_make_thread_participants_aware(self):
        """
        make_thread_participants_aware sets participants_list and participant
        adnotations on thread model
        """
        User = get_user_model()
        user = User.objects.create_user(
            "Bob", "[email protected]", "Pass.123")
        other_user = User.objects.create_user(
            "Bob2", "[email protected]", "Pass.123")

        self.assertFalse(hasattr(self.thread, 'participants_list'))
        self.assertFalse(hasattr(self.thread, 'participant'))

        make_thread_participants_aware(user, self.thread)

        self.assertTrue(hasattr(self.thread, 'participants_list'))
        self.assertTrue(hasattr(self.thread, 'participant'))

        self.assertEqual(self.thread.participants_list, [])
        self.assertIsNone(self.thread.participant)

        ThreadParticipant.objects.add_participant(self.thread, user, True)
        ThreadParticipant.objects.add_participant(self.thread, other_user)

        make_thread_participants_aware(user, self.thread)

        self.assertEqual(self.thread.participant.user, user)
        for participant in self.thread.participants_list:
            if participant.user == user:
                break
        else:
            self.fail("thread.participants_list didn't contain user")

    def test_set_thread_owner(self):
        """set_thread_owner sets user as thread owner"""
        User = get_user_model()
        user = User.objects.create_user(
            "Bob", "[email protected]", "Pass.123")

        set_thread_owner(self.thread, user)

        owner = self.thread.threadparticipant_set.get(is_owner=True)
        self.assertEqual(user, owner.user)

    def test_set_user_unread_private_threads_sync(self):
        """
#.........这里部分代码省略.........
开发者ID:Didan,项目名称:Misago,代码行数:101,代码来源:test_participants.py


示例16: merge_threads

def merge_threads(request, validated_data, threads, poll):
    new_thread = Thread(
        category=validated_data['category'],
        started_on=threads[0].started_on,
        last_post_on=threads[0].last_post_on,
    )

    new_thread.set_title(validated_data['title'])
    new_thread.save()

    if poll:
        poll.move(new_thread)

    categories = []
    for thread in threads:
        categories.append(thread.category)
        new_thread.merge(thread)
        thread.delete()

        record_event(
            request,
            new_thread,
            'merged',
            {
                'merged_thread': thread.title,
            },
            commit=False,
        )

    new_thread.synchronize()
    new_thread.save()

    if validated_data.get('weight') == Thread.WEIGHT_GLOBAL:
        moderation.pin_thread_globally(request, new_thread)
    elif validated_data.get('weight'):
        moderation.pin_thread_locally(request, new_thread)
    if validated_data.get('is_hidden', False):
        moderation.hide_thread(request, new_thread)
    if validated_data.get('is_closed', False):
        moderation.close_thread(request, new_thread)

    if new_thread.category not in categories:
        categories.append(new_thread.category)

    for category in categories:
        category.synchronize()
        category.save()

    # set extra attrs on thread for UI
    new_thread.is_read = False
    new_thread.subscription = None

    add_acl(request.user, new_thread)
    return new_thread
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:54,代码来源:merge.py


示例17: ThreadModelTests

class ThreadModelTests(TestCase):
    def setUp(self):
        datetime = timezone.now()

        self.forum = Forum.objects.filter(role="forum")[:1][0]
        self.thread = Thread(
            forum=self.forum,
            weight=0,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester')

        self.thread.set_title("Test thread")
        self.thread.save()

        post = Post.objects.create(
            forum=self.forum,
            thread=self.thread,
            poster_name='Tester',
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime)

        self.thread.first_post = post
        self.thread.last_post = post
        self.thread.save()

    def test_synchronize(self):
        """synchronize method updates thread data to reflect its contents"""
        User = get_user_model()
        user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        self.assertEqual(self.thread.replies, 0)

        datetime = timezone.now() + timedelta(5)
        post = Post.objects.create(
            forum=self.forum,
            thread=self.thread,
            poster=user,
            poster_name=user.username,
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime)

        # first sync call, updates last thread
        self.thread.synchronize()

        self.assertEqual(self.thread.last_post, post)
        self.assertEqual(self.thread.last_post_on, post.posted_on)
        self.assertEqual(self.thread.last_poster, user)
        self.assertEqual(self.thread.last_poster_name, user.username)
        self.assertEqual(self.thread.last_poster_slug, user.slug)
        self.assertFalse(self.thread.has_reported_posts)
        self.assertFalse(self.thread.has_moderated_posts)
        self.assertFalse(self.thread.has_hidden_posts)
        self.assertEqual(self.thread.replies, 1)

        # add moderated post
        moderated_post = Post.objects.create(
            forum=self.forum,
            thread=self.thread,
            poster=user,
            poster_name=user.username,
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime + timedelta(5),
            updated_on=datetime + timedelta(5),
            is_moderated=True)

        self.thread.synchronize()
        self.assertEqual(self.thread.last_post, post)
        self.assertEqual(self.thread.last_post_on, post.posted_on)
        self.assertEqual(self.thread.last_poster, user)
        self.assertEqual(self.thread.last_poster_name, user.username)
        self.assertEqual(self.thread.last_poster_slug, user.slug)
        self.assertFalse(self.thread.has_reported_posts)
        self.assertTrue(self.thread.has_moderated_posts)
        self.assertFalse(self.thread.has_hidden_posts)
        self.assertEqual(self.thread.replies, 1)

        # add hidden post
        hidden_post = Post.objects.create(
            forum=self.forum,
            thread=self.thread,
            poster=user,
            poster_name=user.username,
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
#.........这里部分代码省略.........
开发者ID:dahito,项目名称:Misago,代码行数:101,代码来源:test_thread_model.py


示例18: ThreadModelTests

class ThreadModelTests(TestCase):
    def setUp(self):
        datetime = timezone.now()

        self.category = Category.objects.all_categories()[:1][0]
        self.thread = Thread(
            category=self.category,
            started_on=datetime,
            starter_name='Tester',
            starter_slug='tester',
            last_post_on=datetime,
            last_poster_name='Tester',
            last_poster_slug='tester',
        )

        self.thread.set_title("Test thread")
        self.thread.save()

        post = Post.objects.create(
            category=self.category,
            thread=self.thread,
            poster_name='Tester',
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime,
        )

        self.thread.first_post = post
        self.thread.last_post = post
        self.thread.save()

    def test_synchronize(self):
        """synchronize method updates thread data to reflect its contents"""
        user = UserModel.objects.create_user("Bob", "[email protected]", "Pass.123")

        self.assertEqual(self.thread.replies, 0)

        datetime = timezone.now() + timedelta(5)
        post = Post.objects.create(
            category=self.category,
            thread=self.thread,
            poster=user,
            poster_name=user.username,
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime,
            updated_on=datetime,
        )

        # first sync call, updates last thread
        self.thread.synchronize()

        self.assertEqual(self.thread.last_post, post)
        self.assertEqual(self.thread.last_post_on, post.posted_on)
        self.assertEqual(self.thread.last_poster, user)
        self.assertEqual(self.thread.last_poster_name, user.username)
        self.assertEqual(self.thread.last_poster_slug, user.slug)
        self.assertFalse(self.thread.has_reported_posts)
        self.assertFalse(self.thread.has_unapproved_posts)
        self.assertFalse(self.thread.has_hidden_posts)
        self.assertEqual(self.thread.replies, 1)

        # add unapproved post
        unapproved_post = Post.objects.create(
            category=self.category,
            thread=self.thread,
            poster=user,
            poster_name=user.username,
            poster_ip='127.0.0.1',
            original="Hello! I am test message!",
            parsed="<p>Hello! I am test message!</p>",
            checksum="nope",
            posted_on=datetime + timedelta(5),
            updated_on=datetime + timedelta(5),
            is_unapproved=True,
        )

        self.thread.synchronize()
        self.assertEqual(self.thread.last_post, post)
        self.assertEqual(self.thread.last_post_on, post.posted_on)
        self.assertEqual(self.thread.last_poster, user)
        self.assertEqual(self.thread.last_poster_name, user.username)
        self.assertEqual(self.thread.last_poster_slug, user.slug)
        self.assertFalse(self.thread.has_reported_posts)
        self.assertTrue(self.thread.has_unapproved_posts)
        self.assertFalse(self.thread.has_hidden_posts)
        self.assertEqual(self.thread.replies, 1)

        # add hidden post
        hidden_post = Post.objects.create(
            category=self.category,
            thread=self.thread,
            poster=user,
            poster_name=user.username,
            poster_ip='127.0.0.1',
#.........这里部分代码省略.........
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:101,代码来源:test_thread_model.py


示例19: post_action_split

 def post_action_split(self, ids):
     for id in ids:
         if id == self.thread.start_post_id:
             raise forms.ValidationError(_("You cannot split first post from thread."))
     message = None
     if self.request.POST.get('do') == 'split':
         form = SplitThreadForm(self.request.POST, request=self.request)
         if form.is_valid():
             new_thread = Thread()
             new_thread.forum = form.cleaned_data['thread_forum']
             new_thread.name = form.cleaned_data['thread_name']
             new_thread.slug = slugify(form.cleaned_data['thread_name'])
             new_thread.start = timezone.now()
             new_thread.last = timezone.now()
             new_thread.start_poster_name = 'n'
             new_thread.start_poster_slug = 'n'
             new_thread.last_poster_name = 'n'
             new_thread.last_poster_slug = 'n'
             new_thread.save(force_insert=True)
             prev_merge = -1
             merge = -1
             for post in self.posts:
                 if post.pk in ids:
                     if prev_merge != post.merge:
                         prev_merge = post.merge
                         merge += 1
                     post.merge = merge
                     post.move_to(new_thread)
                     post.save(force_update=True)
             new_thread.sync()
             new_thread.save(force_update=True)
             self.thread.sync()
             self.thread.save(force_update=True)
             self.forum.sync()
             self.forum.save(force_update=True)
             if new_thread.forum != self.forum:
                 new_thread.forum.sync()
                 new_thread.forum.save(force_update=True)
             self.request.messages.set_flash(Message(_("Selected posts have been split to new thread.")), 'success', 'threads')
             return redirect(reverse('thread', kwargs={'thread': new_thread.pk, 'slug': new_thread.slug}))
         message = Message(form.non_field_errors()[0], 'error')
     else:
         form = SplitThreadForm(request=self.request, initial={
                                                               'thread_name': _('[Split] %s') % self.thread.name,
                                                               'thread_forum': self.forum,
                                                               })
     return self.request.theme.render_to_response('threads/split.html',
                                                  {
                                                   'message': message,
                                                   'forum': self.forum,
                                                   'parents': self.parents,
                                                   'thread': self.thread,
                                                   'posts': ids,
                                                   'form': FormLayout(form),
                                                   },
                                                  context_instance=RequestContext(self.request));
开发者ID:tylercole,项目名称:Misago,代码行数:56,代码来源:thread.py


示例20: action_split

    def action_split(self, request, posts):
        if posts[0].id == self.thread.first_post_id:
            message = _("You can't split thread's first post.")
            raise moderation.ModerationError(message)

        form = SplitThreadForm(acl=request.user.acl)

        if 'submit' in request.POST or 'follow' in request.POST:
            form = SplitThreadForm(request.POST, acl=request.user.acl)
            if form.is_valid():
                split_thread = Thread()
                split_thread.forum = form.cleaned_data['forum']
                split_thread.set_title(
                    form.cleaned_data['thread_title'])
      

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testutils.post_thread函数代码示例发布时间:2022-05-27
下一篇:
Python shortcuts.render_to_response函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap