Exemplo n.º 1
0
 def delete_note(self, note_id):
     # delete note
     try:
         self.note = Note().get(note_id)
         self.note.delete()
     except Exception as e:
         logger.error(e)
         raise Exception(Message.DELETE_NOTE_FAILED)
Exemplo n.º 2
0
 def get_user_notes(self, user_id):
     # get all note of user
     try:
         user_notes = Note().get_user_notes(user_id)
         return user_notes
     except Exception as e:
         logger.error(e)
         raise Exception(Message.GET_USER_NOTES_FAILED)
Exemplo n.º 3
0
 def write_data(self):
     """method to create data for user"""
     title = input("Title: ")
     content = input("Content: ")
     author = self.username
     note = Note(title, content, author)
     note.save_to_mongo()
     print("\nEntry added to database")
Exemplo n.º 4
0
def add_note():
    title = request.form['title']
    description = request.form['content']

    note = Note(title=title, description=description)
    note.save_to_mongo()

    return redirect(url_for('index'))
Exemplo n.º 5
0
 def edit_note(self, note_id, title, content, note_type, user_id):
     # editing note with changing informations: title, content, note_type, user_id
     try:
         self.note = Note().get(note_id)
         self.note.title = title
         self.note.content = content
         self.note.note_type = note_type
         self.note.updated_by = user_id
         self.note.updated_at = datetime.now()
         self.note.update()
     except Exception as e:
         logger.error(e)
         raise Exception(Message.EDIT_NOTE_FAILED)
Exemplo n.º 6
0
 def create_note(self, user_id, title, content, note_type):
     # creating note for user_id, with informations: title, content and note_type
     try:
         self.note = Note(
             id=str(uuid.uuid4()),
             user_id=user_id,
             title=title,
             content=content,
             note_type=note_type,
             created_by=user_id
         )
         return self.note.add()
     except Exception as e:
         logger.error(e)
         raise Exception(Message.CREATE_NOTE_FAILED)
Exemplo n.º 7
0
    def edit_data(self):
        """method to edit title or content of a note"""
        note_list = self.read_data()
        if note_list is not None:
            try:
                num = int(input("Enter ID of Note to Edit: "))
                # get id from serial number
                for note in note_list:
                    if note["S/N"] == num:
                        id = note["_id"]

                # get note using id
                response = Note.find_one(id)
                note = Note(**response)

                # get key match that will be used for edit
                current_title = note.title
                current_content = note.content

                # prompt user to edit title or content
                ans = input("Edit\n1. Title\n2. Content\n")
                ans = ans.strip()

                # edit title or content based on user choice
                if ans == "1":
                    title = input("Enter new title: ")
                    note.title = title
                    note.update_mongo(match={"title": current_title})
                    print("Title successfully edited")
                elif ans == "2":
                    content = input("Enter new content: ")
                    note.content = content
                    note.update_mongo(match={"content": current_content})
                    print("Content successfully edited")
                else:
                    print("Invalid option selected")
            except:
                print("Error occurred during edit, check Id and try again")