コード例 #1
0
ファイル: manage_topic.py プロジェクト: alexdiao/3805
def update_user_topic_fame(topic_id, current_user_id, previous_user_id=None):
    """
    Updates the topic_action_count and reverted_in_topic_count field in User_Topic_Fame
    for all the changes that are involved with topic management(not including add/delete item_topic)
    current_user is the one who did this operation, while previous user is the one whose operation gets reverted
    """
    if previous_user_id:        
        utf_previous = User_Topic_Fame.objects.get(user__pk=previous_user_id, topic__pk=topic_id)
        utf_previous.reverted_in_topic_count = utf_previous.reverted_in_topic_count + 1
        utf_previous.save()
    
    utf_current_set = User_Topic_Fame.objects.filter(user__pk=current_user_id, topic__pk=topic_id)
    if utf_current_set:
        utf_current = utf_current_set[0]
        utf_current. topic_action_count = utf_current.topic_action_count + 1
        utf_current.save()
    else:
        utf_current = User_Topic_Fame()
        utf_current.topic_id = topic_id
        utf_current.user_id = current_user_id
        utf_current.topic_action_count = 1
        utf_current.save()
    
    return "success"