Beispiel #1
0
def direct_message():
    """ Function to save direct message content for user in databse """
    try:
        get_uid = request.args.get('userid', default=None, type=int)
        uid = current_user.id
        if get_uid is not None:
            uid = get_uid
        get_message = DirectMessage.byuser_id(uid)
        dform = direct_message_form.direct_message(obj=get_message)
        if not dform.message.data:
            dform.message.data = "Hi {@username}, Thanks for your follow"
        if dform.validate_on_submit():
            if get_message:
                get_message.message = dform.message.data
                get_message.updated_at = func.now()
            else:
                message_obj = DirectMessage(user_id=uid,
                                            message=dform.message.data,
                                            created_at=func.now(),
                                            updated_at=func.now())
                db.session.add(message_obj)
            db.session.commit()
            flash(SAVE_MESSAGE, 'success')
        return render_template('settings/direct_message.html', dform=dform)
    except Exception as err:
        errorlog.error('save direct message.', details=str(err))
        return str(err)
Beispiel #2
0
def new_direct_message():
    sender, recipient = choices(Profile.objects.all(), k=2)
    msg = DirectMessage(sender=sender,
                        recipient=recipient,
                        time_sent=f.date_time_this_year(),
                        subject=f.sentence(nb_words=4),
                        text=f.text())
    msg.save()
Beispiel #3
0
def create_message():
    form = CreateChatForm()
    form["csrf_token"].data = request.cookies["csrf_token"]

    if form.validate_on_submit():
        new_message = DirectMessage(
            senderId=form.data["senderId"],
            receiverId=form.data["receiverId"],
            message=form.data["message"],
        )
        db.session.add(new_message)
        db.session.commit()
        return new_message.to_dict()
    errors = validation_errors_to_error_messages(form.errors)
    return {"errors": errors}
Beispiel #4
0
def create_message():
    senderId = request.form["senderId"]
    receiverId = request.form["receiverId"]
    message = request.form["rawData"]
    mentioned_users = request.form["mentionedUsers"]
    mentioned_users = json.loads(mentioned_users)

    dm = DirectMessage(senderId=senderId,
                       receiverId=receiverId,
                       message=message)
    db.session.add(dm)
    db.session.flush()

    # for i in range(len(mentioned_users)):
    #     user_mention = MessageTaggedUser(
    #         messageId = dm.id,
    #         userId = int(mentioned_users[i]),
    #         viewStatus = False
    #     )
    #     db.session.add(user_mention)

    db.session.commit()
    #   return message.to_dict()
    myself = User.query.get(senderId)
    return {"user": myself.to_dict_for_self()}
Beispiel #5
0
def message_index(receiverId):
    senderId = request.json['senderId']
    # print("\n\n\n\n\nrequest.json", request.json)
    message = request.json['messageBody']
    dm = DirectMessage(senderId=senderId, receiverId=receiverId,
                       message=message, viewStatus=0)
    db.session.add(dm)
    db.session.commit()

    myself = User.query.get(senderId)

    return {"user": myself.to_dict_for_self()}
Beispiel #6
0
def create_message():
    senderId = request.form["senderId"]
    receiverId = request.form["receiverId"]
    message = request.form["rawData"]
    mentioned_users = request.form["mentionedUsers"]
    mentioned_users = json.loads(mentioned_users)

    dm = DirectMessage(
        senderId=senderId,
        receiverId=receiverId,
        message=message
    )
    db.session.add(dm)
    db.session.flush()

    db.session.commit()
#   return message.to_dict()
    myself = User.query.get(senderId)
    return {"user": myself.to_dict_for_self()}
Beispiel #7
0
def profile_target():
    """ Function to show profile targets """
    try:
        qry = request.args.get('q', default=None, type=str)
        get_uid = request.args.get('userid', default=None, type=int)
        uid = current_user.id
        if get_uid is not None and current_user.user_type == 'admin':
            uid = get_uid

        pf = TargetAccount.get_target(uid, 0, qry)
        if qry is not None:
            res = dict()
            res['status'] = 'success'
            res['account'] = render_template('targets/query_common.html',
                                             pf=pf,
                                             getpage='profile')
            return json.dumps(res)
        get_message = DirectMessage.byuser_id(uid)
        if get_message:
            message = get_message.message
        else:
            message = DIRECT_MESSAGE_DEFAULT
        qry_template = render_template('targets/query_common.html',
                                       pf=pf,
                                       getpage='profile')
        return render_template('targets/common.html',
                               pf=pf,
                               account_class="active",
                               get_page='profile_target',
                               message=message,
                               qry_template=qry_template,
                               btn_content='Add Target',
                               input_id='search-target-users',
                               action="targets")
    except Exception as err:
        errorlog.error('Profile Target Error', details=str(err))
        return render_template('error.html', message="Error!")
Beispiel #8
0
def seed_chat():

    user1 = User.query.filter_by(firstname="Demo").first()
    user2 = User.query.filter_by(firstname="Amber").first()
    user3 = User.query.filter_by(firstname="Courtney").first()
    user4 = User.query.filter_by(firstname="Arianna").first()
    user5 = User.query.filter_by(firstname="Nicole").first()
    user6 = User.query.filter_by(firstname="Kristen").first()
    user7 = User.query.filter_by(firstname="Zoe").first()
    user8 = User.query.filter_by(firstname="Valarie").first()
    user9 = User.query.filter_by(firstname="Tara").first()
    user10 = User.query.filter_by(firstname="Sarah").first()

    messages = [
        DirectMessage(
            senderid=user1.id,
            receiverid=user2.id,
            message="Your new project is so awesome",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user3.id,
            message="Did you hear about the new job post?!",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user4.id,
            message="what is your linkedin link?",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user5.id,
            message="what is your github link?",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user6.id,
            message="want to pair code this week?",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user7.id,
            message="How have you been!?",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user8.id,
            message="how was your interview?!",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user9.id,
            message="Hey how are you!?",
        ),
        DirectMessage(
            senderid=user1.id,
            receiverid=user10.id,
            message="I have an interview Tuesday with my dream company!",
        ),
        DirectMessage(
            senderid=user2.id,
            receiverid=user1.id,
            message="thank you so much!!",
        ),
        DirectMessage(
            senderid=user3.id,
            receiverid=user1.id,
            message="yeah! they want to hire a ux/ui designer",
        ),
        DirectMessage(
            senderid=user4.id,
            receiverid=user1.id,
            message="https://www.linkedin.com/in/arianna-johnson-92773859/",
        ),
        DirectMessage(
            senderid=user5.id,
            receiverid=user1.id,
            message="https://www.linkedin.com/in/nicole-marie-loescher/",
        ),
        DirectMessage(
            senderid=user6.id,
            receiverid=user1.id,
            message="yeah Tuesday works great, I am free after noon",
        ),
        DirectMessage(
            senderid=user7.id,
            receiverid=user1.id,
            message="been great just started a new project!",
        ),
        DirectMessage(
            senderid=user8.id,
            receiverid=user1.id,
            message=
            "I think it went great, left with a really positive feeling",
        ),
        DirectMessage(
            senderid=user9.id,
            receiverid=user1.id,
            message="I am great! how have you been!?",
        ),
        DirectMessage(
            senderid=user9.id,
            receiverid=user1.id,
            message="killin it!",
        ),
    ]

    db.session.bulk_save_objects(messages)
    db.session.commit()