def add_task(self): """ Add a task with user flags :param self: self instance :returns: void """ conn = sqlite3.connect(DATABASE['file']) cur = conn.cursor() cur.execute( 'INSERT INTO Tasks (description, fulldescription, completed) VALUES (?, ?, ?)', ( self.app.args.description, self.app.args.fulldescription, 0, )) conn.commit() conn.close() success([ 'Task added successfully', 'To check these process', 'Use instead:', '$ tasks-app show --filter=description --value="{}"'.format( self.app.args.description), ])
def removeby_another_filter(self): """ Remove by another filter if not it is "completed" :param self: self instance :returns: void """ exists = self.check_if_tasks_exists(self.app.args.removeby, self.app.args.value) if exists is False: fatal([ 'Invalid flag "value"', 'The task with "{}" "{}" not found'.format( self.app.args.removeby, self.app.args.value), 'To show the tasks use instead', '$ tasks-app show', ]) (task, ) = self.get_task(self.app.args.removeby, self.app.args.value) # Getting task data, struct = (description, fulldescription, completed (0 False, 1 True),) description = task[0] fulldescription = task[1] completed = task[2] if completed == 0: completed = 'Incompleted' else: completed = 'Completed' print('Selecting the task with description = "{}"'.format(description)) print( 'NOTE: Your value "{}" of filter "{}" like with description "{}"'. format(self.app.args.value, self.app.args.removeby, description)) print('NOTE: The complete task is:') print('NOTE: {} - {} ({})'.format(description, fulldescription, completed)) print('Do you want to continue?') cont = confirm('Remove?') if cont is True: ok = self.remove_task(self.app.args.removeby, self.app.args.value) if ok is True: success([ 'The task with {} description'.format(description), 'was deleted successfully', 'to verify these use instead:', '$ tasks-app show --filter=description --value={}'.format( description), 'if the output is none results all are ok!', ])
def removeby_completed_filter(self): """ Remove all tasks with the completed status :param self: self instance :returns: void """ if self.app.args.value == 'True': value = 1 else: value = 0 # Getting all task with completed status conn = sqlite3.connect(DATABASE['file']) cur = conn.cursor() cur.execute('SELECT * FROM Tasks WHERE completed = {}'.format(value)) tasks = list(cur) conn.close() # Checking the task len if len(tasks) == 0: fatal([ 'No tasks found with completed = {}'.format( self.app.args.value) ]) # Showing selected tasks print('Selected tasks:') for description, fulldescription, completed in tasks: if completed == 0: completed = 'Incompleted' else: completed = 'Completed' print(' > {} - {} ({})'.format(description, fulldescription, completed)) print('NOTE: because the value {} i want selected the before list'. format(self.app.args.value)) print('Do you want to continue?') cont = confirm('Remove?') if cont is True: for task in tasks: description = task[0] # Task description ok = self.remove_task('description', description) if ok is True: success(['Removed {}'.format(description)])
def remove_without_filter(self): """ Remove a task without filter. default filter is: "description" :param self: self instance :returns: void """ exists = self.check_if_tasks_exists('description', self.app.args.value) if exists is False: fatal([ 'Invalid flag "value"', 'The task with "description" "{}" not found'.format( self.app.args.value), 'To show the tasks use instead:', '$ tasks-app show', ]) (task, ) = self.get_task('description', self.app.args.value) description = task[ 0] # The task description, struct is: (description, fulldescription, completed,) print('Selecting the task with description = "{}"'.format(description)) print('NOTE: Your value "{}" like with "{}"'.format( self.app.args.value, description)) print('Do you want to continue?') cont = confirm('Remove?') if cont is True: ok = self.remove_task('description', self.app.args.value) if ok is True: success([ 'The task with {} description'.format(description), 'was deleted successfully', 'to verify these use instead:', '$ tasks-app show --filter=description --value={}'.format( description), 'if the output is none results all are ok!' ])
def run(self): """ Main method :param self: self instance :returns: void """ ok = self.validate_newcompleted() if ok is False: fatal([ 'Invalid flag "newcompleted"', 'the available values for newcompleted are True|False', 'Use instead:', '$ tasks-app edit --description="{}" --newdescription="{}" --newfulldescription="{}" --newcompleted=True|False' .format(self.app.args.description, self.app.args.newdescription, self.app.args.newfulldescription) ]) self.app.args.newcompleted = self.process_new_completed_arg() exists = self.check_if_exists_task() if exists is True: fatal([ 'The task with description "{}" was exists'.format( self.app.args.newdescription), 'to get all tasks. Use instead:', '$ tasks-app show', ]) selected_task = self.get_selected_task() if selected_task is None: fatal([ 'Invalid task to search with "description" LIKE "{}"'.format( self.app.args.description), 'The task with description like to "{}" doesn\'t exists'. format(self.app.args.description), 'To show all tasks use instead:', '$ tasks-app show', ]) # Getting the selected task data, struct = (description, fulldescription, completed 0|1) description = selected_task[0] fulldescription = selected_task[1] completed = selected_task[2] if completed == 0: completed = 'Incompleted' else: completed = 'Completed' print('NOTE: Selected the task with description = "{}"'.format( description)) print('NOTE: Your description "{}" like with description "{}"'.format( self.app.args.description, description)) print('NOTE: The complete task format is:') print('NOTE: {} - {} ({})'.format(description, fulldescription, completed)) print('Do you want to update to:') description = self.app.args.newdescription fulldescription = self.app.args.newfulldescription completed = self.app.args.newcompleted if completed == 0: completed = 'Incompleted' else: completed = 'Completed' print('{} - {} ({})'.format(description, fulldescription, completed)) cont = confirm('Update?') if cont is True: ok = self.update() if ok is True: success([ 'The task with description = "{}"'.format( selected_task[0]), 'was update successfully to verify these', 'Use instead:', '$ tasks-app show --filter=description --value="{}"'. format(self.app.args.newdescription) ])