本文整理汇总了Python中models.Message.sent方法的典型用法代码示例。如果您正苦于以下问题:Python Message.sent方法的具体用法?Python Message.sent怎么用?Python Message.sent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.sent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_compose
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import sent [as 别名]
def api_compose():
if not request.json:
return jsonify({'status': 'false', 'error': 'Not JSON'})
mess = Message()
try:
mess.text = request.json['text']
mess.destName = request.json['destName']
mess.originName = request.json['originName']
except KeyError:
return jsonify({'status': 'false', 'error': 'Missing fields.'})
if load_user(mess.destName) is None or load_user(mess.originName) is None:
return jsonify({'status': 'false', 'error': 'Users do not exist.'})
mess.read = False
mess.sent = datetime.datetime.now()
db.session.add(mess)
db.session.commit()
return jsonify({'status': 'true'})
示例2: post_mail
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import sent [as 别名]
def post_mail(token):
endpoint = Endpoint.query.filter_by(token=token).first_or_404()
if endpoint.disabled:
return abort(410)
subject = None
text = None
reqid = None
invalid_args = []
missing_args = []
content_type = request.headers.get("content-type")
if content_type == "application/json":
subject = request.json.get("subject")
text = request.json.get("text")
reqid = request.json.get("_reqid")
invalid_args = (set(request.json.keys()) - {"subject", "text", "_reqid"}).union(request.args.keys())
elif content_type == "application/x-www-form-urlencoded":
subject = request.form.get("subject")
text = request.form.get("text")
reqid = request.form.get("_reqid")
invalid_args = (set(request.form.keys()) - {"subject", "text", "_reqid"}).union(request.args.keys())
else: # Assume we want to send the mail as-is
subject = request.args.get("subject")
reqid = request.args.get("reqid")
text = request.data
invalid_args = set(request.args.keys()) - {"subject", "_reqid"}
if not subject:
missing_args.append("subject")
if not text:
missing_args.append("text")
errors = ["Invalid argument `{}`".format(arg) for arg in invalid_args]
errors += ["Missing required argument `{}`".format(arg) for arg in missing_args]
if errors:
return "\n".join(errors), 400
# Need to catch duplicate errors
message = Message(endpoint_id=endpoint.id, subject=subject, body=text, reqid=reqid)
try:
db.session.add(message)
db.session.commit()
message.reference_id = send_mail(
sender_domain=current_app.config["SERVER_NAME"],
sender_name="{} - Varmail".format(endpoint.name),
sender_account="mailer",
recipient=endpoint.user.email,
subject=subject,
text=text,
)
message.sent = True
db.session.add(message)
db.session.commit()
except IntegrityError as e:
# This appears to be the only way to distinguish different types
# of integrity errors :(
if e.orig.pgcode != "23505": # UNIQUE VIOLATION
raise e
# Else swallow the error
return "Sent"