Ejemplo n.º 1
0
    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!',
                ])
Ejemplo n.º 2
0
 def run(self):
     """Main method"""
     exists = self.check_if_exists_task()
     if exists is False:
         self.add_task()
     else:
         fatal([
             'Invalid flag "description"',
             'The task with description = "{}" exists'.format(
                 self.app.args.description),
             'to show the available tasks',
             'Use instead:',
             '$ tasks-app show',
         ])
Ejemplo n.º 3
0
    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)])
Ejemplo n.º 4
0
    def check_correct_removeby_filter(self):
        """
        Check if the value of removeby filter is correct
        :returns: Are OK?
        """
        if self.app.args.removeby == 'completed':
            if self.app.args.value != 'True' and self.app.args.value != 'False':
                fatal([
                    'Invalid flag "value" for flag "removeby"',
                    'The flag "value" must be True|False to removeby',
                    'because the removeby flag is completed',
                    'Use instead:',
                    '$ tasks-app remove --removeby=completed --value=True|False',
                ])

        return True
Ejemplo n.º 5
0
    def is_to_filter(self):
        """Check if is to filter"""
        if not self.app.args.filter is None:
            # Check the flag value to evite problem in search process
            ok = self.validate_value_flag()

            if ok is False:
                fatal([
                    'Invalid value for "value" flag',
                    'The value flag is required to filter',
                    'Use instead:',
                    '$ tasks-app show --filter/-f={} --value/-v=VALUE'.format(self.app.args.filter),
                ])
            else:
                return True
        else:
            return False
Ejemplo n.º 6
0
    def check_removeby(self):
        """
        Check if to removeby filter
        :param self: self instance
        :returns: Is to remove by filter
        """
        if not self.app.args.removeby is None:
            ok = self.check_removeby_type()

            if not ok is True:
                fatal([
                    'Invalid flag "removeby"',
                    'The available types for these flag are',
                    'description|fulldescription|completed',
                    'Use instead:',
                    '$ tasks-app remove --removeby=description|fulldescription|completed --value={}'
                    .format(self.app.args.value),
                ])

            return True
        else:
            return False
Ejemplo n.º 7
0
    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!'
                ])
Ejemplo n.º 8
0
    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)
                ])
Ejemplo n.º 9
0
    def filterby(self, filterval, valueoffilter):
        """
        Filter by a name
        :param filterval: The value to filter
        :param valueoffilter: The value of filter camp
        """
        if valueoffilter == '':
            fatal([
                'Invalid flag "value"',
                'value is required to flag "filter"'
            ])

        ok = self.validate_filterval(filterval)

        if ok is False:
            fatal([
                'Invalid flag "filter"',
                'The available filter values are:',
                'description (name)|fulldescription (description)|completed',
                'Use instead:',
                '$ tasks-app show --filter=description|fulldescription|completed --value={}'.format(valueoffilter)
            ])

        if filterval == 'completed':
            if valueoffilter != 'True' and valueoffilter != 'False':
                fatal([
                    'Invalid flag "value"',
                    'the available values for completed filter flag are:',
                    'True|False',
                    'Use instead:',
                    '$ tasks-app show --filter={filterval} --value=True|False',
                ])

        if filterval == 'completed':
            if valueoffilter == 'True':
                valueoffilter = 1
            elif valueoffilter == 'False':
                valueoffilter = 0

        if not filterval == 'completed':
            sql = 'SELECT * FROM Tasks WHERE {} LIKE "{}%"'.format(filterval, valueoffilter)
        else:
            sql = 'SELECT * FROM Tasks WHERE {} LIKE "{}"'.format(filterval, valueoffilter)

        conn = sqlite3.connect(DATABASE['file'])
        cur = conn.cursor()
        cur.execute(sql)

        if not len(list(cur)) == 0:
            print('Tasks found')

        cur.execute(sql)

        for description, fulldescription, completed in cur:
            if completed == 0:
                completed = 'Incompleted'
            else:
                completed = 'Completed'

            print('  > {} - {} ({})'.format(description, fulldescription, completed))

        cur.execute(sql)

        if len(list(cur)) == 0:
            print('No tasks found with search {}={}'.format(filterval, valueoffilter))

        conn.close()