def share_note(note_id): try: Note.find_by_id(note_id).share_or_unshare() finally: return redirect( url_for('.note', note_id=note_id, msg='Your note is shared!!', msg_=True))
def send_note_radio(note_id): note = Note.find_by_id(note_id) all_notes = Note.get_all() all_users = User.get_all() if request.method == 'POST': try: note = Note.find_by_id(request.form['note']) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='send_note note finding/reading') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during preparing page...') message_title = request.form['title'] if request.form.getlist("user") in [None, [], ""]: return render_template( 'messages/send_note.html', e= "You hadn't selected an reciver. Please select at least ONE reciver.", all_users=all_users, title=message_title, ) else: recivers = request.form.getlist("user") sender_id = User.find_by_email(session['email'])._id message = Message(title=message_title, content=note._id, reciver_id=recivers, sender_id=sender_id, is_a_noteOBJ=True) message.save_to_mongo() return redirect(url_for('.my_sended_messages', user_id=sender_id)) return render_template('messages/send_note.html', all_notes=all_notes, all_users=all_users, note_=note)
def edit_note(note_id): note = Note.find_by_id(note_id) if request.method == 'POST': title = request.form['title'] content = request.form['content'] notebook = request.form['notebookNames'] if notebook != note.notebook_title: old_notebook = Notebook.find_by_title(note.notebook_title) old_notebook.decrement_note() new_notebook = Notebook.find_by_title(notebook) new_notebook.increment_note() note.notebook_title = new_notebook.title note.notebook_id = new_notebook._id note.title = title note.content = content note.last_updated = datetime.datetime.utcnow() note.update() return redirect(url_for('.get_notes', notebook_id=note.notebook_id)) notebooks = Notebook.find_by_username(session['username']) return render_template('notes/edit_note.html', note=note, notebooks=notebooks)
def remove_tag(note_id, tag): note = Note.find_by_id(note_id) note.remove_tag(tag) Tag.find_by_name(tag, session['username']).decrement_counter() return redirect(url_for('.get_notes', notebook_id=note.notebook_id))
def delete_note(note_id): note = Note.find_by_id(note_id) notebook_id = note.notebook_id notebook = Notebook.find_by_id(notebook_id) for tag in note.tags: Tag.find_by_name(tag, session['username']).decrement_counter() note.delete() notebook.decrement_note() return redirect(url_for('.get_notes', notebook_id=notebook_id))
def edit_note(note_id): try: note = Note.find_by_id(note_id) if request.method == 'POST': if request.method == 'POST': share = request.form['inputGroupSelect01'] if share == '0': return render_template( '/notes/create_note.html', error_msg= "You did not selected an Share label. Please select an Share label." ) if share == '1': share = True share_only_with_users = False else: share = False share_only_with_users = True title = request.form['title'] content = request.form['content'] note.shared = share note.share_only_with_users = share_only_with_users note.title = title note.content = content note.save_to_mongo() return redirect(url_for('.note', note_id=note_id)) else: return render_template('/notes/edit_note.html', note=note) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location='edit_note saveing and getting input from html file' ) Error_obj.save_to_mongo() return render_template('error_page.html', error_msgr='Crashed during saving your note...')
def message(message_id, is_sended=False): try: message = Message.find_by_id(message_id) if message is None: return 'There was an server error. Please try again a another time!' if message.readed_by_reciver is False and is_sended is False and session[ '_id'] in message.reciver_id and message.readed_date is None: message.readed_by_reciver = True message.readed_date = datetime.datetime.now() message.save_to_mongo() sender_nickname = User.find_by_id(message.sender_id).nick_name if type(message.reciver_id) is list: reciver_nickname = [] for reciver in message.reciver_id: reciver_nickname.append(User.find_by_id(reciver).nick_name) else: reciver_nickname = User.find_by_id(message.reciver_id).nick_name if message.is_a_noteOBJ: note = Note.find_by_id(message.content) else: note = None return render_template('messages/message.html', message=message, sender_nickname=sender_nickname, reciver_nickname=reciver_nickname, is_a_note=message.is_a_noteOBJ, note=note) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='message message reading') Error_obj.save_to_mongo() return render_template('error_page.html', error_msgr='Crashed during reading message...')
def note(note_id): try: note = Note.find_by_id(note_id) user = User.find_by_email(note.author_email) try: if note.author_email == session['email']: author_email_is_session = True else: author_email_is_session = False except: author_email_is_session = False finally: return render_template( '/notes/note.html', note=note, author_email_is_session=author_email_is_session, msg_=False, user=user) except: error_msg = traceback.format_exc().split('\n') try: Error_obj = Error_(error_msg=''.join(error_msg), error_location='note reading NOTE:' + note._id) except: Error_obj = Error_(error_msg=''.join(error_msg), error_location='note reading NOTE:NONE') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading your note...')
def add_tag(note_id): note = Note.find_by_id(note_id) if request.method == 'POST': new_tag = request.form['name'] existing_tag = request.form['userTags'] if new_tag: if new_tag in note.tags: return "Tag already exists for that note" # setup error for this situation. else: note.add_tag(new_tag) if Tag.exists(new_tag, session['username']) is not None: Tag.find_by_name(new_tag, session['username']).increment_counter() else: Tag(new_tag, session['username']).save_to_mongo() else: if existing_tag in note.tags: return "Tag already exists for that note" # setup error for this situation. else: note.add_tag(existing_tag) Tag.find_by_name(existing_tag, session['username']).increment_counter() return redirect(url_for('.get_notes', notebook_id=note.notebook_id)) tags = Tag.find_by_username(session['username']) return render_template('notes/add_tag.html', note=note, tags=tags)
def delete_note(note_id): try: Note.find_by_id(note_id).delete() finally: return redirect(url_for('.user_notes'))
def get_note(note_id): note = Note.find_by_id(note_id) return render_template('notes/note.html', note=note)