def notes(): try: try: if session['email'] is None: return render_template('/notes/pub_notes.html', notes=Note.find_shared_notes()) else: return render_template('/notes/pub_notes.html', notes=Note.get_only_with_users() + Note.find_shared_notes()) except: return render_template('/notes/pub_notes.html', notes=Note.find_shared_notes()) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='notes publick note reading') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading users notes...')
def user_page(user_id): try: try: user = User.find_by_id(user_id) except: user = User.find_by_email(user_id) user_notes = Note.find_shared_notes_by_user(user.email) return render_template('/users/user.html', user=user, user_notes=user_notes, user_note_count=len(user_notes)) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location='user_page while loading user{} info'.format( user_id)) Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading information...')
def edit_user(user_id): try: current_user = User.find_by_id(user_id) if request.method == 'POST': nick_name = request.form['nickname'] current_user.nick_name = nick_name current_user.save_to_mongo() return redirect(url_for('.user_page', user_id=user_id)) return render_template("users/edit_user.html", user=current_user) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location= 'edit_user while finding user/saving changes to database') Error_obj.save_to_mongo() return render_template('error_page.html', error_msgr='Crashed during saving changes...')
def login_user(): try: e = '' if request.method == 'POST': email = request.form['email'] password = request.form['password'] try: if User.is_login_valid(email, password): session['email'] = email user = User.find_by_email(email) session['_id'] = user._id user.last_logined = datetime.datetime.now() user.save_to_mongo() return redirect(url_for("home")) except UserErrors.UserError as e: return render_template("users/login.html", message=e) return render_template("users/login.html", message=e) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='login_user while logining user') Error_obj.save_to_mongo() return render_template('error_page.html', error_msgr='Crashed during login...')
def send_message(): try: all_users = User.get_all() recivers = [] if request.method == 'POST': title = request.form['title'] content = request.form['content'] if request.form['reciver_email'] in [None, [], ""]: return render_template( 'messages/send_message.html', e= 'Your receiver field is empty. Please fill in at least ONE receiver.', all_users=all_users, title=title, content=content) try: # reciver_id = User.find_by_email(request.form['reciver_email'])._id recivers_string = request.form['reciver_email'].split() for email in recivers_string: recivers.append(User.find_by_email(email)._id) except Exception: return render_template( 'messages/send_message.html', e= "Please Check That you have coped EXACTLY the target user's email! And separated the emails with spaces!!", all_users=all_users, title=title, content=content) sender_id = User.find_by_email(session['email'])._id message = Message(title=title, content=content, reciver_id=recivers, sender_id=sender_id, is_a_noteOBJ=False) message.save_to_mongo() return redirect(url_for('.my_sended_messages', user_id=sender_id)) return render_template('messages/send_message.html', all_users=all_users) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='send_message message sending') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during sending your message...')
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): 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 all_messages(): try: all_messagess = Message.find_all() return render_template('messages/all_messages.html', all_messagess=all_messagess) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='message reading') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading your messages...')
def delete_message(message_id): try: message = Message.find_by_id(message_id) message.delete() return redirect(url_for('.my_recived_messages', user_id=session['_id'])) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='delete_message message deleting') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during deleteing your message...')
def create_note(): try: 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'] author_email = session['email'] author_nickname = User.find_by_email(author_email).nick_name note_for_save = Note(title=title, content=content, author_email=author_email, shared=share, author_nickname=author_nickname, share_only_with_users=share_only_with_users) note_for_save.save_to_mongo() return redirect(url_for('.user_notes')) return render_template('/notes/create_note.html') except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='create_note creating note') Error_obj.save_to_mongo() return render_template('error_page.html', error_msgr='Crashed during saving your note...')
def users_page(): try: users = User.get_all() # TODO: 일래스틱서치 배우고 완료하기 return render_template('/users/users_page.html', users=users) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location= 'users_page while loading users info and posting to html') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading information...')
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 my_recived_messages(user_id): try: messages = Message.find_by_reciver_id(user_id) user_nickname = User.find_by_id(session['_id']).nick_name return render_template('messages/my_recived_messages.html', messages=messages, user_nickname=user_nickname) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location='my_recived_messages-during message finding') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading your messages')
def user_notes(): try: user = User.find_by_email(session['email']) user_notes = User.get_notes(user) user_name = user.email return render_template('/notes/my_notes.html', user_name=user_name, user_notes=user_notes) except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_(error_msg=''.join(error_msg), error_location='user note reading USER:'******'email']) Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during reading your notes...')
def delete_user(user_id): try: if request.method == 'POST': user = User.find_by_id(user_id) user.delete_user_notes() user.delete() session['email'] = None return redirect(url_for('home')) return render_template('/users/confrim.html') except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location='delete_user while removing user from database') Error_obj.save_to_mongo() return render_template( 'error_page.html', error_msgr='Crashed during deleting your account...')
def register_user(): try: if request.method == 'POST': email = request.form['email'] password = request.form['password'] nick_name = request.form['nickname'] try: if User.register_user(email, password, nick_name): session['email'] = email message = Message( title="Welcome to Note-it™!", content="""Welcome to Note-it! You can make a note, and share it with other users! Or you can just keep the note to your selves. You can send messages to other users too! Check out this website!!""", reciver_id=User.find_by_email(email)._id, sender_id=User.find_by_email('*****@*****.**')._id) message.save_to_db() return redirect(url_for("home")) except UserErrors.UserError as e: return e.message return render_template("users/register.html") except: error_msg = traceback.format_exc().split('\n') Error_obj = Error_( error_msg=''.join(error_msg), error_location='register_user while registering user') Error_obj.save_to_mongo() return render_template('error_page.html', error_msgr='Crashed during registering you...')
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...')