本文整理汇总了Python中user.Activity.save方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.save方法的具体用法?Python Activity.save怎么用?Python Activity.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.Activity
的用法示例。
在下文中一共展示了Activity.save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: record_favorite_question
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_favorite_question(instance, created, **kwargs):
"""
when user add the question in him favorite questions list.
"""
if created:
activity = Activity(user=instance.user, active_at=datetime.datetime.now(), content_object=instance, activity_type=TYPE_ACTIVITY_FAVORITE)
activity.save()
示例2: record_answer_event
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_answer_event(instance, created, **kwargs):
if created:
q_author = instance.question.author
found_match = False
for m in q_author.message_set.all():
match = record_answer_event_re.search(m.message)
if match:
found_match = True
try:
cnt = int(match.group(1))
except:
cnt = 1
m.message = u"You have received %d <a href=\"%s?sort=responses\">new responses</a>."\
% (cnt+1, q_author.get_profile_url())
m.save()
break
if not found_match:
msg = u"You have received a <a href=\"%s?sort=responses\">new response</a>."\
% q_author.get_profile_url()
q_author.message_set.create(message=msg)
activity = Activity(user=instance.author, \
active_at=instance.added_at,\
content_object=instance, \
activity_type=TYPE_ACTIVITY_ANSWER)
activity.save()
示例3: record_answer_event
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_answer_event(instance, created, **kwargs):
if created:
q_author = instance.question.author
found_match = False
# print 'going through %d messages' % q_author.message_set.all().count()
for m in q_author.message_set.all():
# print m.message
match = record_answer_event_re.search(m.message)
if match:
found_match = True
try:
cnt = int(match.group(1))
except:
cnt = 1
m.message = u'You have received %d <a href="%s?sort=responses">new responses</a>.' % (
cnt + 1,
q_author.get_profile_url(),
)
# print 'updated message'
# print m.message
m.save()
break
if not found_match:
msg = u'You have received a <a href="%s?sort=responses">new response</a>.' % q_author.get_profile_url()
# print 'new message'
# print msg
q_author.message_set.create(message=msg)
activity = Activity(
user=instance.author,
active_at=instance.added_at,
content_object=instance,
activity_type=TYPE_ACTIVITY_ANSWER,
)
activity.save()
示例4: record_answer_accepted
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_answer_accepted(instance, created, **kwargs):
"""
when answer is accepted, we record this for question author - who accepted it.
"""
if not created and instance.accepted:
activity = Activity(user=instance.question.author, active_at=datetime.datetime.now(), \
content_object=instance, activity_type=TYPE_ACTIVITY_MARK_ANSWER)
activity.save()
示例5: record_user_full_updated
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_user_full_updated(instance, **kwargs):
activity = Activity(
user=instance,
active_at=datetime.datetime.now(),
content_object=instance,
activity_type=TYPE_ACTIVITY_USER_FULL_UPDATED,
)
activity.save()
示例6: record_mark_offensive
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_mark_offensive(instance, mark_by, **kwargs):
activity = Activity(
user=mark_by,
active_at=datetime.datetime.now(),
content_object=instance,
activity_type=TYPE_ACTIVITY_MARK_OFFENSIVE,
)
activity.save()
示例7: record_revision_answer_event
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_revision_answer_event(instance, created, **kwargs):
if created and instance.revision <> 1:
activity = Activity(
user=instance.author,
active_at=instance.revised_at,
content_object=instance,
activity_type=TYPE_ACTIVITY_UPDATE_ANSWER,
)
activity.save()
示例8: record_ask_event
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_ask_event(instance, created, **kwargs):
if created:
activity = Activity(
user=instance.author,
active_at=instance.added_at,
content_object=instance,
activity_type=TYPE_ACTIVITY_ASK_QUESTION,
)
activity.save()
示例9: record_delete_question
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_delete_question(instance, delete_by, **kwargs):
"""
when user deleted the question
"""
if instance.__class__ == "Question":
activity_type = TYPE_ACTIVITY_DELETE_QUESTION
else:
activity_type = TYPE_ACTIVITY_DELETE_ANSWER
activity = Activity(user=delete_by, active_at=datetime.datetime.now(), content_object=instance, activity_type=activity_type)
activity.save()
示例10: record_comment_event
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_comment_event(instance, created, **kwargs):
if created:
from django.contrib.contenttypes.models import ContentType
question_type = ContentType.objects.get_for_model(Question)
question_type_id = question_type.id
if (instance.content_type_id == question_type_id):
type = TYPE_ACTIVITY_COMMENT_QUESTION
else:
type = TYPE_ACTIVITY_COMMENT_ANSWER
activity = Activity(user=instance.user, active_at=instance.added_at, content_object=instance, activity_type=type)
activity.save()
示例11: record_update_tags
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_update_tags(question, **kwargs):
"""
when user updated tags of the question
"""
activity = Activity(
user=question.author,
active_at=datetime.datetime.now(),
content_object=question,
activity_type=TYPE_ACTIVITY_UPDATE_TAGS,
)
activity.save()
示例12: record_cancel_vote
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_cancel_vote(instance, **kwargs):
"""
when user canceled vote, the vote will be deleted.
"""
activity = Activity(
user=instance.user,
active_at=datetime.datetime.now(),
content_object=instance,
activity_type=TYPE_ACTIVITY_CANCEL_VOTE,
)
activity.save()
示例13: record_vote
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_vote(instance, created, **kwargs):
"""
when user have voted
"""
if created:
if instance.vote == 1:
vote_type = TYPE_ACTIVITY_VOTE_UP
else:
vote_type = TYPE_ACTIVITY_VOTE_DOWN
activity = Activity(user=instance.user, active_at=instance.voted_at, content_object=instance, activity_type=vote_type)
activity.save()
示例14: record_award_event
# 需要导入模块: from user import Activity [as 别名]
# 或者: from user.Activity import save [as 别名]
def record_award_event(instance, created, **kwargs):
"""
After we awarded a badge to user, we need to record this activity and notify user.
We also recaculate awarded_count of this badge and user information.
"""
if created:
activity = Activity(user=instance.user, active_at=instance.awarded_at, content_object=instance,
activity_type=TYPE_ACTIVITY_PRIZE)
activity.save()
instance.badge.awarded_count += 1
instance.badge.save()
if instance.badge.type == Badge.GOLD:
instance.user.gold += 1
if instance.badge.type == Badge.SILVER:
instance.user.silver += 1
if instance.badge.type == Badge.BRONZE:
instance.user.bronze += 1
instance.user.save()