コード例 #1
0
ファイル: search.py プロジェクト: gidsey/project_03
 def edit_task(self):
     """Edit the task."""
     utilities.show_edit_title()
     self.show_task_detail()  # Display the entry to be edited
     utilities.show_edit_menu_options()  # Ask the user what to change
     while True:
         edit_item = input("\nEnter 'a', 'b', 'c' 'd' or 'r': ")
         if edit_item.upper() == 'A':  # Edit date
             self.edit_taskdate()
             break
         if edit_item.upper() == 'B':  # Edit task name
             self.edit_taskname()
             break
         if edit_item.upper() == 'C':  # Edit time spent
             self.edit_tasktime()
             break
         if edit_item.upper() == 'D':  # Edit notes
             self.edit_tasknotes()
             break
         if edit_item.upper() == 'R':
             from work_log import search_menu
             search_menu()
             break
         else:  # Capture incorrect user input
             utilities.show_edit_title()
             self.show_task_detail()
             utilities.show_edit_menu_options()
             print("\nSorry, we did not recoginse '{}'"
                   ", please try again.".format(edit_item))
             continue
コード例 #2
0
ファイル: search.py プロジェクト: gidsey/project_03
 def edit_taskname(self):
     """Edit the task name."""
     utilities.show_edit_title()
     self.show_task_detail()
     while True:
         new_taskname = str(input('\nEnter the new task name: '))
         if new_taskname == '':
             print("sorry, task name cannot be blank.\n")
             continue
         else:
             self.do_edit(name=new_taskname)
             break
コード例 #3
0
ファイル: search.py プロジェクト: gidsey/project_03
 def edit_tasktime(self):
     """Edit the task time."""
     utilities.show_edit_title()
     self.show_task_detail()
     while True:
         try:
             new_tasktime = int(
                 input("\nEnter the new amount of time "
                       "spent on the task (rounded mins): "))
         except ValueError:
             utilities.show_edit_title()
             self.show_task_detail()
             print("Error. Please enter the number of minutes "
                   "as a whole number.\n")
             continue
         else:
             self.do_edit(time=new_tasktime)
             break
コード例 #4
0
ファイル: search.py プロジェクト: gidsey/project_03
 def edit_taskdate(self):
     """Edit the task date."""
     utilities.show_edit_title()
     self.show_task_detail()
     while True:
         new_date = input("\nPlease enter new date "
                          "in 'DD/MM/YYYY format: ")
         try:
             new_date = datetime.datetime.strptime(new_date, fmt)
         except ValueError:
             utilities.show_edit_title()
             self.show_task_detail()
             print("\nSorry '{}' is not in the correct date format. "
                   "Please try again.".format(new_date))
             continue
         else:
             self.do_edit(date=new_date)
             break
コード例 #5
0
ファイル: search.py プロジェクト: gidsey/project_03
    def do_edit(self, **kwargs):
        """Update the CSV with the edited record."""
        self.delete = False
        self.date = None
        self.name = None
        self.time = None
        self.notes = None

        for key, value in kwargs.items():
            setattr(self, key, value)

        utilities.show_edit_title()

        if self.delete:  # Delete the record (https://tinyurl.com/y4je42ka)
            status = "deleted"
            fieldnames = [
                'task_id', 'task_date', 'task_name', 'task_time', 'task_notes'
            ]
            with open('tasks.csv') as csvfile, \
                    open('temp.csv', 'w', newline='') as outputfile:
                reader = csv.DictReader(csvfile, fieldnames=fieldnames)
                writer = csv.DictWriter(outputfile, fieldnames=fieldnames)

                for row in reader:
                    if not row['task_id'] == self.results[
                            self.count]['task_id']:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
            shutil.move('temp.csv', 'tasks.csv')

        elif self.date:  # Update the task date
            status = "updated"
            fieldnames = [
                'task_id', 'task_date', 'task_name', 'task_time', 'task_notes'
            ]

            with open('tasks.csv') as csvfile, \
                    open('temp.csv', 'w', newline='') as outputfile:
                reader = csv.DictReader(csvfile, fieldnames=fieldnames)
                writer = csv.DictWriter(outputfile, fieldnames=fieldnames)

                for row in reader:
                    if row['task_id'] == self.results[self.count]['task_id']:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': self.date,
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
                    else:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
            shutil.move('temp.csv', 'tasks.csv')

        elif self.name:  # Update the task name
            status = "updated"
            fieldnames = [
                'task_id', 'task_date', 'task_name', 'task_time', 'task_notes'
            ]

            with open('tasks.csv') as csvfile, \
                    open('temp.csv', 'w', newline='') as outputfile:
                reader = csv.DictReader(csvfile, fieldnames=fieldnames)
                writer = csv.DictWriter(outputfile, fieldnames=fieldnames)

                for row in reader:
                    if row['task_id'] == self.results[self.count]['task_id']:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': self.name,
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
                    else:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
            shutil.move('temp.csv', 'tasks.csv')

        elif self.time:  # Update the task time
            status = "updated"
            fieldnames = [
                'task_id', 'task_date', 'task_name', 'task_time', 'task_notes'
            ]

            with open('tasks.csv') as csvfile, \
                    open('temp.csv', 'w', newline='') as outputfile:
                reader = csv.DictReader(csvfile, fieldnames=fieldnames)
                writer = csv.DictWriter(outputfile, fieldnames=fieldnames)

                for row in reader:
                    if row['task_id'] == self.results[self.count]['task_id']:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': self.time,
                            'task_notes': row['task_notes']
                        })
                    else:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
            shutil.move('temp.csv', 'tasks.csv')

        elif self.notes or self.notes == '':  # Update the task notes
            status = "updated"
            fieldnames = [
                'task_id', 'task_date', 'task_name', 'task_time', 'task_notes'
            ]

            with open('tasks.csv') as csvfile, \
                    open('temp.csv', 'w', newline='') as outputfile:
                reader = csv.DictReader(csvfile, fieldnames=fieldnames)
                writer = csv.DictWriter(outputfile, fieldnames=fieldnames)

                for row in reader:
                    if row['task_id'] == self.results[self.count]['task_id']:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': self.notes
                        })
                    else:
                        writer.writerow({
                            'task_id': row['task_id'],
                            'task_date': row['task_date'],
                            'task_name': row['task_name'],
                            'task_time': row['task_time'],
                            'task_notes': row['task_notes']
                        })
            shutil.move('temp.csv', 'tasks.csv')

        utilities.show_search_title()  # Show the sucess message
        input('\nEntry {} successfully.\n\n'
              'Press ENTER to return to the search menu.'.format(status))
        from work_log import search_menu
        search_menu()
コード例 #6
0
ファイル: search.py プロジェクト: gidsey/project_03
 def edit_tasknotes(self):
     """Edit the task notes."""
     utilities.show_edit_title()
     self.show_task_detail()
     new_tasknotes = str(input('\nEnter the new task notes: '))
     self.do_edit(notes=new_tasknotes)