-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.py
31 lines (24 loc) · 993 Bytes
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import jsonify
from config import time_format, entries
from bson.objectid import ObjectId
"""
Update functions
"""
# This function creates return information for AJAX when a field is updated.
def update_success_msg(field, timestamp, image=""):
return jsonify({"status": "success",
"updated_on": timestamp.strftime(time_format),
"new_image": image,
"message": f"{field} sucessfully updated.",
"message_class": "valid-update"})
# This function sends information back to the frontend if a field cannot be updated
def update_failure_msg(message):
return jsonify({"status": "failure",
"message": message,
"message_class": "invalid-update"})
# This function updates a document in the database with new information
def update_field(fields, entry_id):
entries.update_one(
{"_id": ObjectId(entry_id)},
{"$set": fields}
)