当前位置: 首页>>代码示例>>Python>>正文


Python user.Activity类代码示例

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


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

示例1: record_favorite_question

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:7,代码来源:__init__.py

示例2: record_answer_event

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:26,代码来源:__init__.py

示例3: record_answer_event

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()
开发者ID:samadhy,项目名称:osqa,代码行数:35,代码来源:__init__.py

示例4: record_answer_accepted

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:8,代码来源:__init__.py

示例5: record_user_full_updated

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()
开发者ID:samadhy,项目名称:osqa,代码行数:8,代码来源:__init__.py

示例6: record_mark_offensive

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()
开发者ID:samadhy,项目名称:osqa,代码行数:8,代码来源:__init__.py

示例7: record_revision_answer_event

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()
开发者ID:samadhy,项目名称:osqa,代码行数:9,代码来源:__init__.py

示例8: record_ask_event

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()
开发者ID:samadhy,项目名称:osqa,代码行数:9,代码来源:__init__.py

示例9: record_delete_question

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:11,代码来源:__init__.py

示例10: record_comment_event

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:11,代码来源:__init__.py

示例11: record_update_tags

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()
开发者ID:samadhy,项目名称:osqa,代码行数:11,代码来源:__init__.py

示例12: record_cancel_vote

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()
开发者ID:samadhy,项目名称:osqa,代码行数:11,代码来源:__init__.py

示例13: record_vote

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:12,代码来源:__init__.py

示例14: record_award_event

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()
开发者ID:pekka,项目名称:askbot-devel,代码行数:20,代码来源:__init__.py


注:本文中的user.Activity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。