當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。