예제 #1
0
    def create_db(self, itemClass):
        """ creates the intial database with headers """
        print("Constructing database ...")

        # * Creating the database if it does not exist
        # Connecting to the database
        conn = create_connection_db(itemClass.databaseFile)

        # Create table if it doesnt exist
        create_table(conn, itemClass.createSqlCmd)
예제 #2
0
    def view_folder(self, itemClass):
        #    """ open folder in ranger """

        # Show the table of specified item
        # self.show_table(itemClass)

        # Ask User for the id of the item they want to view
        id = self.id_input()

        # * View File
        # Connecting to the database
        conn = create_connection_db(itemClass.databaseFile)
        # Get the folderpath
        folderpath = get_item_attribute(conn, itemClass, "folderpath", id)

        os.system("ranger " + folderpath)
예제 #3
0
    def view_file(self, itemClass):
        """ opens file in default program """

        # Show the table of specified item
        # self.show_table(itemClass)

        # Ask User for the id of the item they want to view
        id = self.id_input()

        # * View File
        # Connecting to the database
        conn = create_connection_db(itemClass.databaseFile)
        # Get the filepath
        filepath = get_item_attribute(conn, itemClass, "filepath", id)

        os.system("evince " + filepath)
예제 #4
0
    def delete_item(self, itemClass):
        """ ask user which item they want to delete """

        # Show the table of specified item
        # self.show_table(itemClass)

        # Ask User for the id of the item they want to remove
        id = self.id_input()

        # * Adding to the database
        # Connecting to the database
        conn = create_connection_db(itemClass.databaseFile)

        # Remove item with id
        remove_item_db(conn, itemClass, id)

        # * Exit from database
        conn.commit()
        conn.close()
예제 #5
0
    def modify_numbers_done(self, itemClass):
        """ ask the user which item they want to modify the numbers did """

        # Show the table of specified item
        # self.show_table(itemClass)

        # Ask User for the id of the item they want to update
        id = self.id_input()

        # Ask the User how many they did more
        # * Ask user fo the # done
        questions = [{
            'type': 'input',
            'name': 'amount',
            'message': 'Amount done :',
        }]

        answers = prompt(questions, style=custom_style_2)
        amount = answers['amount']

        # * Editing the Percentage
        # Connecting to the database
        conn = create_connection_db(itemClass.databaseFile)

        # Get the current number done and the total
        currentNumber = get_item_attribute(conn, itemClass, "currentNumbers",
                                           id)
        currentNumber = int(currentNumber) + int(amount)

        totalNumber = get_item_attribute(conn, itemClass, "totalNumbers", id)
        totalNumber = int(totalNumber)

        # Calculating the percentage
        percentage = self.calculate_percentage(currentNumber, totalNumber)

        # Edit the percentage
        set_item_percentage_db(conn, itemClass, percentage, currentNumber, id)

        # * Exit from database
        conn.commit()
        conn.close()
예제 #6
0
    def create_item(self, itemClass):
        """ ask user for input and adds to the database for them """

        # * Creating item
        # Creating input and getting the answer
        item = itemClass(new=True)

        print(type(item))

        # * Adding to the database
        # Connecting to the database
        conn = create_connection_db(item.databaseFile)

        # Create table if it doesnt exist
        create_table(conn, itemClass.createSqlCmd)

        # Add to database
        add_item_db(conn, item)

        # * Exit from database
        conn.commit()
        conn.close()
예제 #7
0
    def update_daysLeft(self, itemClasses):
        """ goes over all the tables with daysLeft and update them depending on the current date """
        # iterate over the tables
        files = [
            "assignments_db.sqlite", "labreports_db.sqlite", "exams_db.sqlite"
        ]
        tableNames = ["assignments", "labreports", "exams"]

        # ! expecting -> itemClasses = [Assignment, LabReport, Exam]

        # iterate over the itemClass

        for itemClass in itemClasses:

            # * Adding to the database
            # Connecting to the database
            conn = create_connection_db(itemClass.databaseFile)
            cur = conn.cursor()

            print(itemClass.tableName)

            for row in cur.execute('SELECT date, id FROM ' +
                                   itemClass.tableName):
                days = 0

                # TODO -> Getting a weird error of "NoteType" -> but the date is there ???
                # get the due date
                date = cur.fetchone()[0]
                id = cur.fetchone()[1]
                print(date)
                dueDate = datetime.datetime.strptime(
                    date,
                    '%Y-%m-%d').date()  # converts string date into a date obj

                # calculate the daysLeft
                daysLeft = itemClass.days_left(dueDate)
                print(daysLeft)
예제 #8
0
    def edit_item(self, itemClass):
        """ lets user edit an item inside a itemClass """

        # Ask User for the id of the item they want to remove
        id = self.id_input()

        # * Adding to the database
        # Connecting to the database
        conn = create_connection_db(itemClass.databaseFile)

        # * Have a mulit-line selection - ask user what they wanna change
        question = [
            {
                'type': 'list',
                'name': 'item',
                'message': 'What would you like to edit?',
                'choices': itemClass.editStringList
            },
        ]
        itemStringanswers = prompt(question, style=custom_style_2)
        itemString = itemStringanswers["item"]

        itemValQuestion = [{
            'type':
            'input',
            'name':
            'itemValue',
            'message':
            'What\'s the value you want to change to ?',
        }]

        # * Checking if they are special cases (ie. date,currentNumbers)
        if itemString == "date":
            # Asking for date
            answers = prompt(itemValQuestion, style=custom_style_2)
            date = answers["itemValue"]

            # Calculate the days left needed
            date = datetime.datetime.strptime(
                date,
                '%Y-%m-%d').date()  # converts string date into a date obj
            daysLeft = itemClass.days_left(date)

            # TODO -> ERROR : daysLeft in color not good with the sql execute command -> not sure why + not updating the table ...
            editSqlCmd = "UPDATE " + itemClass.tableName + " SET " + itemString + " = ? " + ", daysLeft = ? WHERE id = ?"
            cur = conn.cursor()
            cur.execute(editSqlCmd, (str(date), daysLeft, id))

        elif itemString == "currentNumbers":
            # Asking for currentNumber
            answers = prompt(itemValQuestion, style=custom_style_2)
            currentNumber = int(answers["itemValue"])

            # Calculate the percentage
            # TODO Calculate the percentage
            cur = conn.cursor()
            cur.execute('SELECT totalNumbers FROM ' + itemClass.tableName +
                        " WHERE id = " + str(id))
            totalNumbers = int(cur.fetchone()[0])
            percentage = self.calculate_percentage(currentNumber, totalNumbers)

        elif itemString == "folderpath" or itemString == "filepath":
            # Show folder explorer to get folderpath
            from PySide2.QtWidgets import QFileDialog, QApplication
            import sys
            app = QApplication(sys.argv)
            folderpath = QFileDialog.getExistingDirectory()

            editSqlCmd = "UPDATE " + itemClass.tableName + " SET " + itemString + " = ? " + " WHERE id = ?"
            cur = conn.cursor()
            cur.execute(editSqlCmd, (folderpath, id))

        else:
            # Asking for Value
            answers = prompt(itemValQuestion, style=custom_style_2)
            itemValue = answers["itemValue"]
            editSqlCmd = "UPDATE " + itemClass.tableName + " SET " + itemString + " = ? " + " WHERE id = ?"
            cur = conn.cursor()
            cur.execute(editSqlCmd, (itemValue, id))

        # ! IF EDIT DATE -> AUTOMATICALLY UPDATE DAYS_LEFTIC -> PERCEnTAGE CHANGE
        # ! ID EDIT CURRENT_NUMBERS -> UPDATE PECENTAGE

        # TODO depending on what they want to change -> input / folderpath / date ...

        # cur = conn.cursor()
        # cur.execute('SELECT ' + itemToChange + ' FROM exams')
        # data = cur.fetchall()

        # * User can then modify the form to make their changes and then change

        # * pass the update itemlist

        # * Exit from database
        conn.commit()
        conn.close()