本文整理汇总了Python中misago.threads.models.Thread.merge方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.merge方法的具体用法?Python Thread.merge怎么用?Python Thread.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misago.threads.models.Thread
的用法示例。
在下文中一共展示了Thread.merge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_threads
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import merge [as 别名]
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
示例2: merge_threads
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import merge [as 别名]
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
示例3: ThreadModelTests
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import merge [as 别名]
#.........这里部分代码省略.........
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)
self.thread.set_first_post(post)
self.assertEqual(self.thread.first_post, post)
self.assertEqual(self.thread.started_on, post.posted_on)
self.assertEqual(self.thread.starter, user)
self.assertEqual(self.thread.starter_name, user.username)
self.assertEqual(self.thread.starter_slug, user.slug)
def test_set_last_post(self):
"""set_last_post sets first post and poster data on thread"""
User = get_user_model()
user = User.objects.create_user("Bob", "[email protected]", "Pass.123")
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)
self.thread.set_last_post(post)
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)
def test_move(self):
"""move(new_forum) moves thread to other forum"""
# pick category instead of forum (so we don't have to create one)
new_forum = Forum.objects.filter(role="category")[:1][0]
self.thread.move(new_forum)
self.assertEqual(self.thread.forum, new_forum)
for post in self.thread.post_set.all():
self.assertEqual(post.forum_id, new_forum.id)
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(
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')
other_thread.set_title("Other thread")
other_thread.save()
post = Post.objects.create(
forum=self.forum,
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")
示例4: ThreadModelTests
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import merge [as 别名]
#.........这里部分代码省略.........
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,
)
self.thread.set_last_post(post)
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)
def test_move(self):
"""move(new_category) moves thread to other category"""
# pick category instead of category (so we don't have to create one)
root_category = Category.objects.root_category()
Category(
name='New Category',
slug='new-category',
).insert_at(
root_category,
position='last-child',
save=True,
)
new_category = Category.objects.get(slug='new-category')
self.thread.move(new_category)
self.assertEqual(self.thread.category, new_category)
for post in self.thread.post_set.all():
self.assertEqual(post.category_id, new_category.id)
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")
def test_delete_private_thread(self):
"""
private thread gets deleted automatically
when there are no participants left in it
"""
user_a = UserModel.objects.create_user("Bob", "[email protected]", "Pass.123")
user_b = UserModel.objects.create_user("Weebl", "[email protected]", "Pass.123")
ThreadParticipant.objects.add_participants(self.thread, [user_a, user_b])
self.assertEqual(self.thread.participants.count(), 2)
user_a.delete()
Thread.objects.get(id=self.thread.id)
user_b.delete()
with self.assertRaises(Thread.DoesNotExist):
Thread.objects.get(id=self.thread.id)