Example #1
0
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...')
Example #2
0
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))
Example #3
0
def quick_note():
    data = request.get_json()
    title = ""
    content = data['note']
    url = data['url']

    notebook = Notebook.find_by_title('inbox', get_jwt_identity())
    notebook.increment_note()

    new_note = Note(notebook._id, notebook.title, title, content, get_jwt_identity(), url)
    new_note.save_to_mongo()

    return jsonify({"msg": "note created"}), 201
Example #4
0
def create_note():
    data = request.get_json()
    title = data['title']
    content = data['note']
    notebook_title = data['notebook']

    notebook = Notebook.find_by_title(notebook_title, get_jwt_identity())
    notebook.increment_note()

    new_note = Note(notebook._id, notebook.title, title, content, get_jwt_identity())
    new_note.save_to_mongo()

    return jsonify({"msg": "note created"}), 201
Example #5
0
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)
Example #6
0
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...')
Example #7
0
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))
Example #8
0
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)
Example #9
0
def create_note(notebook_id):
    if request.method == 'POST':
        title = request.form['title']
        content = ""

        notebook = Notebook.find_by_id(notebook_id)
        notebook.increment_note()

        new_note = Note(notebook_id, notebook.title, title, content,
                        session['username'])
        new_note.save_to_mongo()

        # return redirect(url_for('.get_notes', notebook_id=notebook_id))
        return redirect(url_for('.edit_note', note_id=new_note._id))

    return render_template('notes/new_note.html')
Example #10
0
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...')
Example #11
0
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))
Example #12
0
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...')
Example #13
0
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...')
Example #14
0
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...')
Example #15
0
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)
Example #16
0
 def get_notes(self):
     return Note.find_by_user_email(self.email)
Example #17
0
 def delete(self):
     Note.delete_notes(self._id)
     Database.remove(NotebookConstants.COLLECTION, {'_id': self._id})
Example #18
0
def get_tag(tag):
    notes = Note.find_by_tag(tag, session['username'])

    return render_template('notes/by_tag.html', notes=notes, tag_name=tag)
Example #19
0
def get_note(note_id):
    note = Note.find_by_id(note_id)
    return render_template('notes/note.html', note=note)
Example #20
0
def delete_note(note_id):

    try:
        Note.find_by_id(note_id).delete()
    finally:
        return redirect(url_for('.user_notes'))
Example #21
0
 def get_notes(self):
     return Note.from_notebook(self._id)