示例#1
0
def get_question_data(thread):
    """returns data dictionary for a given thread"""
    question_post = thread._question_post()
    datum = {
        'added_at': get_epoch_str(thread.added_at),
        'id': question_post.id,
        'answer_count': thread.answer_count,
        'answer_ids': thread.get_answer_ids(),
        'view_count': thread.view_count,
        'score': thread.score,
        'last_activity_at': get_epoch_str(thread.last_activity_at),
        'title': thread.title,
        'summary': question_post.summary,
        'tags': thread.tagnames.strip().split(),
        'url': site_url(thread.get_absolute_url()),
    }
    datum['author'] = {
        'id': thread._question_post().author.id,
        'username': thread._question_post().author.username
    }
    datum['last_activity_by'] = {
        'id': thread.last_activity_by.id,
        'username': thread.last_activity_by.username
    }
    return datum
示例#2
0
def get_question_data(thread):
    """returns data dictionary for a given thread"""
    question_post = thread._question_post()
    datum = {
        'added_at': get_epoch_str(thread.added_at),
        'id': question_post.id,
        'answer_count': thread.answer_count,
        'answer_ids': thread.get_answer_ids(),
        'accepted_answer_id': thread.accepted_answer_id,
        'view_count': thread.view_count,
        'score': thread.score,
        'last_activity_at': get_epoch_str(thread.last_activity_at),
        'title': thread.title,
        'summary': question_post.summary,
        'tags': thread.tagnames.strip().split(),
        'url': site_url(thread.get_absolute_url()),
    }
    datum['author'] = {
        'id': thread._question_post().author.id,
        'username': thread._question_post().author.username
    }
    datum['last_activity_by'] = {
        'id': thread.last_activity_by.id,
        'username': thread.last_activity_by.username
    }
    return datum
示例#3
0
def get_question_data(thread):
    """returns data dictionary for a given thread"""
    question_post = thread._question_post()  #pylint: disable=protected-access
    datum = {
        'added_at': get_epoch_str(thread.added_at),
        'id': question_post.id,
        'answer_count': thread.answer_count,
        'answer_ids': thread.get_answer_ids(),
        'accepted_answer_id': thread.accepted_answer_id,
        'view_count': thread.view_count,
        'score': thread.score,
        'last_activity_at': get_epoch_str(thread.last_activity_at),
        'title': thread.title,
        'summary': question_post.summary,
        'tags': thread.tagnames.strip().split(),
        'url': site_url(thread.get_absolute_url()),
    }
    if question_post.last_edited_at:
        datum['last_edited_at'] = get_epoch_str(question_post.last_edited_at)

    if question_post.last_edited_by:
        datum['last_edited_by'] = get_user_id_info(
            question_post.last_edited_by)

    if thread.closed:
        datum['closed'] = True
        datum['closed_by'] = get_user_id_info(thread.closed_by)
        datum['closed_at'] = get_epoch_str(thread.closed_at)
        datum['closed_reason'] = thread.get_close_reason_display()

    datum['author'] = get_user_id_info(question_post.author)
    datum['last_activity_by'] = get_user_id_info(thread.last_activity_by)
    return datum
示例#4
0
def get_user_data(user):
    """get common data about the user"""
    avatar_url = user.get_avatar_url()
    if not ('gravatar.com' in avatar_url):
        avatar_url = site_url(avatar_url)

    return {
        'id': user.id,
        'avatar': avatar_url,
        'username': user.username,
        'joined_at': get_epoch_str(user.date_joined),
        'last_seen_at': get_epoch_str(user.last_seen),
        'reputation': user.reputation,
    }
示例#5
0
def get_user_data(user):
    """get common data about the user"""
    avatar_url = user.get_avatar_url()
    if not ('gravatar.com' in avatar_url):
        avatar_url = site_url(avatar_url)

    return {
        'id': user.id,
        'avatar': avatar_url,
        'username': user.username,
        'joined_at': get_epoch_str(user.date_joined),
        'last_seen_at': get_epoch_str(user.last_seen),
        'reputation': user.reputation,
    }
示例#6
0
def get_user_data(user):
    """get common data about the user"""
    avatar_url = user.get_avatar_url()
    if not ("gravatar.com" in avatar_url):
        avatar_url = site_url(avatar_url)

    return {
        "id": user.id,
        "avatar": avatar_url,
        "username": user.username,
        "joined_at": get_epoch_str(user.date_joined),
        "last_seen_at": get_epoch_str(user.last_seen),
        "reputation": user.reputation,
    }
示例#7
0
def get_user_data(user_obj):
    """get common data about the user"""
    avatar_url = user_obj.get_avatar_url()
    if 'gravatar.com' not in avatar_url:
        avatar_url = site_url(avatar_url)

    return {
        'id': user_obj.id,
        'avatar': avatar_url,
        'username': user_obj.username,
        'joined_at': get_epoch_str(user_obj.date_joined),
        'last_seen_at': get_epoch_str(user_obj.last_seen),
        'reputation': user_obj.reputation,
        'gold': user_obj.gold,
        'silver': user_obj.silver,
        'bronze': user_obj.bronze,
    }
示例#8
0
def get_answer_data(post):
    """returns data dictionary for a given answer post"""
    datum = {
        'added_at': get_epoch_str(post.added_at),
        'id': post.id,
        'score': post.score,
        'summary': post.summary,
        'url': site_url(post.get_absolute_url()),
    }
    datum['author'] = get_user_id_info(post.author)

    if post.last_edited_at:
        datum['last_edited_at'] = get_epoch_str(post.last_edited_at)

    if post.last_edited_by:
        datum['last_edited_by'] = get_user_id_info(post.last_edited_by)

    return datum
示例#9
0
def get_question_data(thread):
    """returns data dictionary for a given thread"""
    question_post = thread._question_post()
    datum = {
        "added_at": get_epoch_str(thread.added_at),
        "id": question_post.id,
        "answer_count": thread.answer_count,
        "answer_ids": thread.get_answer_ids(),
        "accepted_answer_id": thread.accepted_answer_id,
        "view_count": thread.view_count,
        "score": thread.score,
        "last_activity_at": get_epoch_str(thread.last_activity_at),
        "title": thread.title,
        "summary": question_post.summary,
        "tags": thread.tagnames.strip().split(),
        "url": site_url(thread.get_absolute_url()),
    }
    datum["author"] = {"id": thread._question_post().author.id, "username": thread._question_post().author.username}
    datum["last_activity_by"] = {"id": thread.last_activity_by.id, "username": thread.last_activity_by.username}
    return datum
示例#10
0
 def test_api_v1_answer(self):
     user = self.create_user('user')
     question = self.post_question(user=user)
     answer = self.post_answer(user=user, question=question)
     response = self.client.get(reverse('api_v1_answer', kwargs={'answer_id': answer.id}))
     data = simplejson.loads(response.content)
     self.assertEqual(data['author']['id'], user.id)
     self.assertEqual(data['author']['username'], user.username)
     self.assertEqual(data['url'], site_url(answer.get_absolute_url()))
     self.assertEqual(data['added_at'], get_epoch_str(answer.added_at))
     self.assertEqual(data['score'], answer.score)
     self.assertEqual(data['id'], answer.id)
     self.assertEqual(data['summary'], answer.summary)