Esempio n. 1
0
def save_message(sender, recipient, subject, body):
    _sender = User.query.filter_by(id=sender).first()
    _recipient = User.query.filter_by(username=recipient).first()
    Messages.create(sender=_sender.id, recipient=_recipient.id, subject=subject,
                    body=body, draft=True)
    db.session.commit()
    flash('Message saved.', 'success')
Esempio n. 2
0
def send_message(sender, recipient, subject, body):
    _sender = User.query.filter_by(id=sender).first()
    _recipient = User.query.filter_by(username=recipient).first()
    _msg_recipient = Messages.create(user_for=_recipient, sender=_sender, recipient=_recipient, subject=subject,
                                     body=body, sent_at=dt.utcnow())
    _msg_sender = Messages.create(user_for=_sender, sender=_sender, recipient=_recipient, subject=subject,
                                  body=body, sent_at=dt.utcnow())
    db.session.commit()
    flash('Message Sent.', 'success')