def updateJournal(): date_str = request.json['date'] content = request.json['text'] # update dropbox dropbox = DropboxApi() filename = date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/journal/" + filename, content) # update metadata date = date_helpers.parse_date_str(date_str) entry_metadata = {} if len(content) > 0: entry_metadata = TasksParser(date_str, content).to_dict() models.entries.create_or_update_entry(g.user["_id"], filename, date, entry_metadata, file_metadata) return jsonify({"success": True, **file_metadata})
def perform_update(date_str, date, action, params): metadata = models.entries.find_one_for_user_and_date(g.user["_id"], date) parser = TasksParser(date_str, "") if metadata: parser.from_dict(metadata["metadata"]) if action == "add_line": parser.add_line(params["line"], params["is_after_midnight"]) elif action == "edit_line": parser.edit_line(params["prev_line"], params["new_line"], params["is_after_midnight"]) content = parser.to_tasks_file() entry_metadata = parser.to_dict() # update dropbox dropbox = DropboxApi() filename = date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/journal/" + filename, content) return models.entries.create_or_update_entry(g.user["_id"], filename, date, entry_metadata, file_metadata)
def perform_update(date_str, date, action, params): metadata = models.entries.find_one_for_user_and_date(g.user["_id"], date) parser = TasksParser(date_str, "") if metadata: parser.from_dict(metadata["metadata"]) if action == 'add_line': parser.add_line(params["line"], params["is_after_midnight"]) elif action == 'edit_line': parser.edit_line(params["prev_line"], params["new_line"], params["is_after_midnight"]) content = parser.to_tasks_file() entry_metadata = parser.to_dict() # update dropbox dropbox = DropboxApi() filename = date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/journal/" + filename, content) return models.entries.create_or_update_entry(g.user["_id"], filename, date, entry_metadata, file_metadata)
def update_goals(): """ updates the goals file """ start_date_str = request.json['start_date'] end_date_str = request.json['end_date'] start_date = date_helpers.parse_date_str(start_date_str) end_date = date_helpers.parse_date_str(end_date_str) content = request.form['content'] # update Dropbox dropbox = DropboxApi() filename = start_date_str + "-" + end_date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/goals/" + filename, content) # update metadata goal_metadata = [] if len(content) > 0: goal_metadata = GoalsParser(content).to_array() models.goals.create_or_update_entry(g.user["_id"], start_date, end_date, goal_metadata, file_metadata) return jsonify({"success": True, **file_metadata})