def my_recived_messages(user_id):
    try:
        messages = Message.find_by_reciver_id(user_id)
        user_nickname = User.find_by_id(session['_id']).nick_name

        return render_template('messages/my_recived_messages.html',
                               messages=messages,
                               user_nickname=user_nickname)
    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(
            error_msg=''.join(error_msg),
            error_location='my_recived_messages-during message finding')
        Error_obj.save_to_mongo()
        return render_template(
            'error_page.html',
            error_msgr='Crashed during reading your messages')
Exemple #2
0
def my_recived_messages(user_id):
    try:
        messages_by_db = Message.find_by_reciver_id(user_id)
        user_nickname = User.find_by_id(session['_id']).nick_name

        if request.method == 'POST':
            form_ = request.form['Search_message']

            messages = Message.search_on_elastic(form_, user_id)

            try:
                for message in messages:
                    if type(message) is 'NoneType':
                        messages.remove(message)
            except TypeError:
                pass

            if messages is None:
                messages = []

            return render_template('messages/my_recived_messages.html',
                                   messages=messages,
                                   user_nickname=user_nickname,
                                   form=form_)
        return render_template('messages/my_recived_messages.html',
                               messages=messages_by_db,
                               user_nickname=user_nickname)

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(
            error_msg=''.join(error_msg),
            error_location='my_recived_messages-during message finding')
        Error_obj.save_to_mongo()
        return render_template(
            'base_htmls/error_page.html',
            error_msgr='Crashed during reading your messages')