예제 #1
0
def notifications_count():
    notifications = Notification.query.filter_by(read=False).filter_by(
        user_id=current_user.id).count()
    messages = current_user.new_messages()

    return jsonify({
        'status': 1,
        'notifications': notifications,
        'messages': messages
    })
예제 #2
0
def messages():
    current_user.last_message_read_time = datetime.utcnow()
    current_user.add_notification(
        'unread_message_count', current_user.new_messages())
    db.session.commit()
    page = request.args.get('page', 1, type=int)
    messages = current_user.messages_received.order_by(Message.timestamp.desc(
    )).paginate(page, current_app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('main.messages', page=messages.next_num) \
        if messages.has_next else None
    prev_url = url_for('main.messages', page=messages.prev_num) \
        if messages.has_prev else None
    return render_template('messages.html', messages=messages.items,
                           next_url=next_url, prev_url=prev_url)
예제 #3
0
def notify():

    recipient = request.args.get('recipient', 0, type=str)
    if recipient == "0":
        return "error"

    if request.method == 'POST':
        user = User.query.filter_by(email=recipient).first_or_404()
        print("Crack Detected")
        msg = Message(recipient=user, body=request.form['msg_from_rpi'])
        db.session.add(msg)
        db.session.commit()
        return "Message sent successfully"

    if request.method == 'GET':
        messg = {"count": current_user.new_messages()}
        return jsonify(messg)
예제 #4
0
파일: routes.py 프로젝트: kadakia/rohanapp
def messages():
    current_user.last_message_read_time = datetime.utcnow()
    current_user.add_notification('unread_message_count', current_user.new_messages())
    db.session.commit()
    page = request.args.get('page', 1, type=int)
    sub = db.session.query(func.max(Message.timestamp).label("max_stamp")).filter(
        Message.recipient == current_user).group_by(Message.sender_id).subquery()
    messages = current_user.messages_received.join(sub, and_(Message.timestamp == sub.c.max_stamp)).order_by(
        Message.timestamp.desc()).paginate(
            page, current_app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('main.messages', page=messages.next_num) if messages.has_next else None
    prev_url = url_for('main.messages', page=messages.prev_num) if messages.has_prev else None
    if messages.total % current_app.config['POSTS_PER_PAGE'] == 0:
        last_page = messages.total // current_app.config['POSTS_PER_PAGE']
    else:
        last_page = messages.total // current_app.config['POSTS_PER_PAGE'] + 1
    last_url = url_for('main.messages', page=last_page)
    return render_template('messages.html', messages=messages.items,
                           next_url=next_url, prev_url=prev_url, title='Messages', last_url=last_url)