本文整理汇总了Python中the_tale.forum.prototypes.PostPrototype类的典型用法代码示例。如果您正苦于以下问题:Python PostPrototype类的具体用法?Python PostPrototype怎么用?Python PostPrototype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PostPrototype类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
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)
示例2: setUp
def setUp(self):
super(TestModeration, self).setUp()
create_test_map()
register_user('main_user', '[email protected]', '111111')
register_user('moderator', '[email protected]', '111111')
register_user('second_user', '[email protected]', '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')
示例3: apply
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 = 'Итоги голосования: %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()
with transaction.atomic():
if self.is_percents_barier_not_passed:
self.state = BILL_STATE.REJECTED
self.save()
PostPrototype.create(ThreadPrototype(self._model.forum_thread),
get_system_user(),
'Законопроект отклонён.\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(),
'Законопроект принят. Изменения вступят в силу в ближайшее время.\n\n%s' % results_text,
technical=True)
for actor in self.data.actors:
if isinstance(actor, places_objects.Place):
actor.effects.add(effects.Effect(name='закон №{}'.format(self.id),
attribute=places_relations.ATTRIBUTE.STABILITY,
value=-self.type.stability))
logic.initiate_actual_bills_update(self._model.owner_id)
signals.bill_processed.send(self.__class__, bill=self)
return True
示例4: test_automatic_update_on_post_creating
def test_automatic_update_on_post_creating(self):
old_time = datetime.datetime.now()
PostPrototype.create(thread=self.thread, author=self.checked_account, text='post-1-text')
self.thread.reload()
self.assertEqual(self.thread.posts_count, 1)
self.assertEqual(self.thread.last_poster.id, self.checked_account.id)
self.assertTrue(self.thread.updated_at > old_time)
示例5: test_posts_count
def test_posts_count(self):
for i in xrange(4):
PostPrototype.create(self.thread1, self.account, 'subcat1-thread1-post%d-text' % i)
for i in xrange(7):
PostPrototype.create(self.thread2, self.account, 'subcat1-thread2-post%d-text' % i)
# first post in thread does not count
self.assertEqual(SubCategory.objects.get(id=self.subcat1.id).posts_count, 12)
self.assertEqual(Thread.objects.get(id=self.thread1.id).posts_count, 5)
self.assertEqual(Thread.objects.get(id=self.thread2.id).posts_count, 7)
示例6: test_delete_success
def test_delete_success(self):
from the_tale.forum.prototypes import PostPrototype as ForumPostPrototype
self.assertEqual(ForumPostPrototype._db_count(), 1)
self.check_ajax_ok(self.client.post(reverse("blogs:posts:accept", args=[self.post.id]), {}))
self.assertTrue(prototypes.PostPrototype.get_by_id(self.post.id).state.is_ACCEPTED)
self.check_ajax_ok(self.client.post(reverse("blogs:posts:decline", args=[self.post.id]), {}))
self.assertTrue(prototypes.PostPrototype.get_by_id(self.post.id).state.is_DECLINED)
self.assertEqual(ForumPostPrototype._db_count(), 2)
示例7: remove
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)
示例8: test_automatic_update_on_post_deleting
def test_automatic_update_on_post_deleting(self):
old_time = datetime.datetime.now()
self.test_automatic_update_on_post_creating()
PostPrototype._db_get_object(1).delete(self.checked_account)
self.thread.update()
self.assertEqual(self.thread.posts_count, 1)
self.assertEqual(self.thread._model.last_poster.id, self.account.id)
self.assertTrue(self.thread.updated_at < old_time)
示例9: decline
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)
示例10: __init__
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')
示例11: __init__
def __init__(self):
register_user('forum_user', '[email protected]', '111111')
register_user('forum_user_2', '[email protected]', '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')
示例12: test_created_at_turn
def test_created_at_turn(self):
current_turn = TimePrototype.get_current_time()
current_turn.increment_turn()
current_turn.increment_turn()
post = PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')
self.assertEqual(post.created_at_turn, current_turn.turn_number)
示例13: test_post_created_at_turn
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)
示例14: test_main_user_remove_post
def test_main_user_remove_post(self):
self.request_login('[email protected]')
self.assertEqual(Thread.objects.get(id=self.thread.id).posts_count, 3)
self.assertEqual(SubCategory.objects.get(id=self.subcategory.id).posts_count, 5)
self.check_ajax_ok(self.client.post(url('forum:posts:delete', self.post.id)))
self.assertTrue(PostPrototype.get_by_id(self.post.id).is_removed)
# check if edit & remove buttons has dissapeared
self.check_html_ok(self.request_html(url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-post-button', 2),
('pgf-change-post-button', 2)])
示例15: stop
def stop(self):
if not self.state.is_VOTING:
raise exceptions.StopBillInWrongStateError(bill_id=self.id)
results_text = 'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % (self.votes_for,
self.votes_against,
round(self.votes_for_percents, 3)*100,
self.votes_refrained)
with transaction.atomic():
self._model.voting_end_at = datetime.datetime.now()
self.state = BILL_STATE.STOPPED
self.save()
PostPrototype.create(ThreadPrototype(self._model.forum_thread),
get_system_user(),
'Законопроект потерял смысл, голосование остановлено. %s' % results_text,
technical=True)
signals.bill_stopped.send(self.__class__, bill=self)