Beispiel #1
0
def thumb_user_to_dict(user, current_user_id=None):
    from configs import config
    from controllers import is_following
    user_dict = {
        'id':user.id,
        'username': user.username,
        'first_name': user.first_name,
        'last_name': None,
        'profile_picture': user.profile_picture,
        'gender':user.gender,
        'user_type':user.user_type,
        'bio' : user.bio or config.DEFAULT_BIO,
        'allow_anonymous_question' : user.allow_anonymous_question,
        'location': location_dict(user.lat, user.lon, user.location_name, user.country_name, user.country_code),
        'user_title':user.user_title,
        'is_following':is_following(user.id, current_user_id) if current_user_id else False,
        'channel_id':'user_{user_id}'.format(user_id=user.id)
    }
    return user_dict
Beispiel #2
0
def make_celeb_questions_dict(celeb, questions, current_user_id=None):
    from controllers import get_question_upvote_count, is_following,\
        is_upvoted, get_upvoters, get_thumb_users, is_question_remindable

    upvoters = []
    for question in questions:
        upvoters.extend(get_upvoters(question.id, count=5))
    
    users = get_thumb_users(set([question.question_author for question in questions]+upvoters))

    celeb_dict =   {   
                    'id': celeb.id,
                    'username': celeb.username,
                    'first_name': celeb.first_name,
                    'last_name': None,
                    'profile_picture': celeb.profile_picture,
                    'gender': celeb.gender,
                    'user_title': celeb.user_title,
                    'user_type':celeb.user_type,
                    'is_following': is_following(celeb.id, current_user_id),
                    'bio':celeb.bio,
                    'channel_id':'user_{user_id}'.format(user_id=celeb.id),
                    'questions':[],
                    'twitter_handle': celeb.twitter_handle
                }
    for question in questions:
        ques_dict = {
        'id': question.id,
        'question_author': {
                            'id':users[question.question_author]['id'],
                            'username': users[question.question_author]['username'] if not question.is_anonymous else 'Anonymous',
                            'first_name': users[question.question_author]['first_name'] if not question.is_anonymous else 'Anonymous',
                            'last_name': None,
                            'profile_picture': users[question.question_author]['profile_picture'] if not question.is_anonymous else None,
                            'gender':users[question.question_author]['gender'],
                            'channel_id':'                                      user_{user_id}'.format(user_id=question.question_author)
                            },
        'question_to':{
                        'id':celeb.id,
                        'username': celeb.username,
                        'first_name': celeb.first_name,
                        'last_name': None,
                        'profile_picture': celeb.profile_picture,
                        'gender': celeb.gender,
                        'user_type': celeb.user_type,
                        'user_title': celeb.user_title,
                        'is_following':celeb_dict['is_following'],
                        'channel_id':'user_{user_id}'.format(user_id=celeb.id),
                        'twitter_handle':users[question.question_to]['twitter_handle'] if not question.open_question else None

                        },
        'tags': [],
        'body': question.body,        
        'timestamp': int(time.mktime(question.timestamp.timetuple())),
        'location': location_dict(question.lat, question.lon, question.location_name, question.country_name, question.country_code),
        'is_anonymous' : question.is_anonymous,
        'ask_count': get_question_upvote_count(question.id),
        'askers': [{'id':users[upvoter]['id'], 'profile_picture':users[upvoter]['profile_picture'], 'gender':users[upvoter]['gender']} for upvoter in upvoters],
        'background_image':"http://api.frankly.me/question/bg_image/%s"%(str(question.id)),
        'is_voted': is_upvoted(question.id, current_user_id) if current_user_id else False,
        'web_link':'http://frankly.me',
        'slug':question.slug,
        'is_remindable':is_question_remindable(question.id,current_user_id) if current_user_id else False
        }
        celeb_dict['questions'].append(ques_dict)
    return celeb_dict