本文整理汇总了Python中misago.threads.models.Thread.synchronize方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.synchronize方法的具体用法?Python Thread.synchronize怎么用?Python Thread.synchronize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misago.threads.models.Thread
的用法示例。
在下文中一共展示了Thread.synchronize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: split_posts_to_new_thread
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [as 别名]
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()
示例2: action_merge
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [as 别名]
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 'submit' in request.POST:
form = MergeThreadsForm(request.POST)
if form.is_valid():
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()
self.forum.lock()
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
})
示例3: merge_threads
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [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
示例4: merge_threads
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [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
示例5: ThreadModelTests
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [as 别名]
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>",
#.........这里部分代码省略.........
示例6: handle
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [as 别名]
#.........这里部分代码省略.........
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=0,
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()
user.threads += 1
user.posts += 1
user.save()
thread_type = random.randint(0, 100)
if thread_type > 95:
thread_replies = random.randint(200, 500)
elif thread_type > 50:
thread_replies = random.randint(5, 30)
else:
thread_replies = random.randint(0, 10)
for x in xrange(thread_replies):
datetime = timezone.now()
user = User.objects.order_by('?')[:1][0]
fake_message = "\n\n".join(fake.paragraphs())
is_moderated = random.randint(0, 100) > 97
if not is_moderated:
is_hidden = random.randint(0, 100) > 97
else:
is_hidden = False
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),
is_hidden=is_hidden,
is_moderated=is_moderated,
posted_on=datetime,
updated_on=datetime)
update_post_checksum(post)
post.save(update_fields=['checksum'])
user.posts += 1
user.save()
thread.synchronize()
thread.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()
for forum in forums:
forum.synchronize()
forum.save()
self.stdout.write(message % created_threads)
示例7: ThreadModelTests
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [as 别名]
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',
#.........这里部分代码省略.........
示例8: action_split
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import synchronize [as 别名]
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'])
split_thread.starter_name = "-"
split_thread.starter_slug = "-"
split_thread.last_poster_name = "-"
split_thread.last_poster_slug = "-"
split_thread.started_on = timezone.now()
split_thread.last_post_on = timezone.now()
split_thread.save()
for post in posts:
post.move(split_thread)
post.save()
split_thread.synchronize()
split_thread.save()
if split_thread.forum != self.forum:
split_thread.forum.lock()
split_thread.forum.synchronize()
split_thread.forum.save()
changed_posts = len(posts)
message = ungettext(
'%(changed)d post was split to "%(thread)s".',
'%(changed)d posts were split to "%(thread)s".',
changed_posts)
messages.success(request, message % {
'changed': changed_posts,
'thread': split_thread.title
})
if 'follow' in request.POST:
return redirect(split_thread.get_absolute_url())
else:
return None # trigger thread refresh
if request.is_ajax():
template = self.split_thread_modal_template
else:
template = self.split_thread_full_template
return render(request, template, {
'form': form,
'forum': self.forum,
'thread': self.thread,
'path': get_forum_path(self.forum),
'posts': posts
})