示例#1
0
    def get(self, request, user_id):
        """
            View individual user.
        """

        with Database() as cursor:
            query = """
                SELECT *
                FROM user
                WHERE id={}
            """.format(user_id)

            try:
                cursor.execute(query)
                serializer = UserSerializer(data=cursor.fetchall(), many=True)

                if not serializer.is_valid():
                    return Response(serializer.errors,
                                    status=status.HTTP_400_BAD_REQUEST)

            except Exception as error:
                print(error)
                return Response(serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)

        return Response(serializer.data, status=status.HTTP_200_OK)
    def handle(self, *args, **options):

        with Database() as cursor:

            for monitor in monitors:
                query = """
                    INSERT INTO monitorDisplay (modelNumber, quantity, name, weight, weightFormat, price, priceFormat,
                                                brandName, type, size, sizeFormat)
                    VALUES ('{modelNumber}', {quantity}, '{name}', {weight}, '{weightFormat}', {price}, '{priceFormat}',
                             '{brandName}', '{type}', {size}, '{sizeFormat}');
                """.format(**monitor)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)

            for monitorDisplayID in monitorDisplayIDs:
                query = """
                    INSERT INTO monitorDisplayID (serialNum, modelNum, isLocked)
                    VALUES ('{serialNum}', '{modelNum}', {isLocked});
                """.format(**monitorDisplayID)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)
示例#3
0
    def handle(self, *args, **options):

        with Database() as cursor:

            for laptop in laptops:
                query = """
                    INSERT INTO laptop (modelNumber, quantity, name, weight, weightFormat, price,
                    priceFormat, brandName, type, ramSize, ramFormat, processorType, numCores,
                    hardDriveSize, hardDriveFormat, containsCamera, isTouch, batteryInfo, os,
                           size, sizeFormat)
                    VALUES ('{modelNumber}', {quantity}, '{name}', {weight}, '{weightFormat}', {price},
                            '{priceFormat}', '{brandName}', '{type}', {ramSize}, '{ramFormat}',
                            '{processorType}', {numCores}, {hardDriveSize}, '{hardDriveFormat}',
                             {containsCamera}, {isTouch}, '{batteryInfo}', '{os}',
                             {size}, '{sizeFormat}');
                """.format(**laptop)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)

            for laptopID in laptopIDs:
                query = """
                    INSERT INTO laptopID (serialNum, modelNum, isLocked)
                    VALUES ('{serialNum}', '{modelNum}', {isLocked});
                """.format(**laptopID)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)
示例#4
0
    def get(self, request):
        """
            List users.
        """

        with Database() as cursor:
            query = """
                SELECT *
                FROM user
            """

            try:
                cursor.execute(query)
                serializer = UserSerializer(data=cursor.fetchall(), many=True)

                if not serializer.is_valid():
                    return Response(serializer.errors,
                                    status=status.HTTP_400_BAD_REQUEST)

            except Exception as error:
                print(error)
                return Response(serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)

        return Response(serializer.data, status=status.HTTP_200_OK)
示例#5
0
    def update(desktop):

        with Database() as cursor:
            query = """
                    UPDATE desktop SET
                    quantity = {quantity},
                    name = '{name}',
                    weight = {weight},
                    weightFormat = '{weightFormat}',
                    price = {price},
                    priceFormat = '{priceFormat}',
                    brandName = '{brandName}',
                    ramSize = {ramSize},
                    ramFormat = '{ramFormat}',
                    processorType = '{processorType}',
                    numCores = '{numCores}',
                    hardDriveSize = '{hardDriveSize}',
                    hardDriveFormat = '{hardDriveFormat}',
                    dx = '{dx}',
                    dy = '{dy}',
                    dz = '{dz}',
                    dimensionFormat = '{dimensionFormat}',
                    type = '{type}'
                    WHERE modelNumber = '{modelNumber}';
                """.format(**(desktop.__dict__))

            try:
                cursor.execute(query)

            except Exception as error:
                print(error)
示例#6
0
    def handle(self, *args, **options):

        with Database() as cursor:

            for tablet in tablets:
                query = """
                    INSERT INTO tablet (modelNumber, quantity, name, weight, weightFormat, price, priceFormat, brandName,
                                        type, ramSize, ramFormat, processorType, numCores, hardDriveSize, hardDriveFormat,
                                        os, batteryInfo, dx, dy, dz, dimensionFormat, cameraInfo, size, sizeFormat)
                    VALUES ('{modelNumber}', {quantity}, '{name}', {weight}, '{weightFormat}', {price}, '{priceFormat}',
                                        '{brandName}', '{type}', {ramSize}, '{ramFormat}', '{processorType}', {numCores},
                                        {hardDriveSize}, '{hardDriveFormat}', '{os}', '{batteryInfo}', {dx}, {dy}, {dz},
                                        '{dimensionFormat}', '{cameraInfo}', {size}, '{sizeFormat}');
                """.format(**tablet)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)

            for tabletID in tabletIDs:
                query = """
                    INSERT INTO tabletID (serialNum, modelNum, isLocked)
                    VALUES ('{serialNum}', '{modelNum}', {isLocked});
                """.format(**tabletID)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)
示例#7
0
    def updateActivation(useremail):

        with Database() as cursor:
            query = "UPDATE user SET isActivated = 0 WHERE email = '{}';".format(
                useremail)

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#8
0
    def delete(serialNum):

        with Database() as cursor:

            query = """
                DELETE FROM laptopID WHERE serialNum = '{}';
            """.format(serialNum)
            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#9
0
    def findUsers():

        with Database() as cursor:

            try:
                cursor.execute("SELECT * FROM user WHERE isActivated = 1;")
                resultSet = cursor.fetchall()
                return resultSet
            except Exception as error:
                print(error)
                return None
示例#10
0
    def delete(serialNumber):

        with Database() as cursor:

            query = """
                DELETE FROM purchasecollection WHERE serialNum = '{}';
                """.format(serialNumber)

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
    def delete(serialNum):

        with Database() as cursor:
            print('delete')
            query = """
                DELETE FROM monitorDisplayID WHERE serialNum = '{}';
            """.format(serialNum)

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#12
0
    def delete(monitor):

        with Database() as cursor:
            query = """
                INSERT INTO deleteFlag (modelNumber, type)
                VALUES ('{modelNumber}', 'monitor');
            """.format(**(monitor.__dict__))

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#13
0
    def delete(laptop):

        with Database() as cursor:
            query = """
                INSERT INTO deleteFlag (modelNumber, type)
                VALUES ('{modelNumber}', 'laptop');
            """

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
    def handle(self, *args, **options):

        with Database() as cursor:

            query = """
                CREATE TABLE tablet (
                    modelNumber varchar(255) NOT NULL,
                    quantity integer(11) NOT NULL,
                    name varchar(255) NOT NULL,
                    weight double NOT NULL,
                    weightFormat varchar(255) NOT NULL,
                    price double NOT NULL,
                    priceFormat varchar(255) NOT NULL,
                    brandName varchar(255) NOT NULL,
                    type varchar(255) NOT NULL,
                    ramSize integer(11) NOT NULL,
                    ramFormat varchar(255) NOT NULL,
                    processorType varchar(255) NOT NULL,
                    numCores integer(11) NOT NULL,
                    hardDriveSize double NOT NULL,
                    hardDriveFormat varchar(255) NOT NULL,
                    os varchar(255) NOT NULL,
                    batteryInfo varchar(255) NOT NULL,
                    dx double NOT NULL,
                    dy double NOT NULL,
                    dz double NOT NULL,
                    dimensionFormat varchar(255) NOT NULL,
                    cameraInfo varchar(255) NOT NULL,
                    size double NOT NULL,
                    sizeFormat varchar(255) NOT NULL,
                    PRIMARY KEY (modelNumber)
                );
            """

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)

            query = """
                CREATE TABLE tabletID (
                    serialNum varchar(255) NOT NULL,
                    modelNum varchar(255) NOT NULL,
                    isLocked tinyint(1) DEFAULT 0,
                    PRIMARY KEY (serialNum),
                    FOREIGN KEY (modelNum) REFERENCES tablet (modelNumber)
                );
            """
            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#15
0
    def insert(serialNum, modelNumber, email, type, timeOfCheckout):

        with Database() as cursor:

            query = """
                    INSERT INTO purchasecollection (serialNum, modelNum, userId, type, timeStamp)
                    VALUES ('{}', '{}','{}','{}','{}');
                """.format(serialNum, modelNumber, email, type, timeOfCheckout)

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#16
0
    def insert(customer):

        with Database() as cursor:
            query = """
                INSERT INTO user (email, password, isAdmin, isActivated, username, firstname, lastname, address, phone)
                VALUES ('{email}', '{password}', 0, 1, '{username}', '{firstname}', '{lastname}',
                        '{address}', '{phone}');
            """.format(**(customer.__dict__))

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#17
0
    def findUser(useremail):

        with Database() as cursor:

            try:
                query = "SELECT * FROM user WHERE email = '{}';".format(
                    useremail)
                cursor.execute(query)
                resultSet = cursor.fetchone()
                return resultSet
            except Exception as error:
                print(error)
                return None
示例#18
0
    def update(desktopID):
        with Database() as cursor:
            isLockedInt = 1 if desktopID.isLocked else 0
            query = """
                UPDATE desktopID SET
                isLocked = {}
                WHERE serialNum = '{}';
            """.format(isLockedInt, desktopID.serialNumber)

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#19
0
    def insert(desktopID):

        with Database() as cursor:

            query = """
                INSERT INTO desktopID (serialNum, modelNum, isLocked)
                VALUES ('{}', '{}', 0);
            """.format(desktopID.serialNumber, desktopID.spec.modelNumber)

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#20
0
    def update(user):

        with Database() as cursor:
            query = """
                UPDATE user SET
                timeStamp = '{timeStamp}'
                WHERE id = {id};
            """.format(**(user.__dict__))

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#21
0
    def findBySpec(spec):

        with Database() as cursor:

            query = """
                SELECT * FROM desktopID WHERE modelNum = '{}';
            """.format(spec.modelNumber)
            try:
                cursor.execute(query)
                resultSet = cursor.fetchall()
                return resultSet
            except Exception as error:
                print(error)
                return None
示例#22
0
    def findAll():

        with Database() as cursor:
            query = """
                SELECT * FROM monitorDisplay WHERE modelNumber NOT IN (SELECT modelNumber FROM deleteFlag);
            """
            try:
                cursor.execute(query)

                result = cursor.fetchall()
                return result
            except Exception as error:
                print(error)
                return None
示例#23
0
    def find(modelNumber):

        with Database() as cursor:
            query = """
                SELECT * FROM monitorDisplay WHERE modelNumber = '{}';
            """.format(modelNumber)
            try:
                cursor.execute(query)

                result = cursor.fetchone()
                return result
            except Exception as error:
                print(error)
                return None
示例#24
0
    def insert(monitor):

        with Database() as cursor:
            query = """
                INSERT INTO monitorDisplay (modelNumber, quantity, name, weight, weightFormat, price, priceFormat,
                                            brandName, type, size, sizeFormat)
                VALUES ('{modelNumber}', {quantity}, '{name}', {weight}, '{weightFormat}', {price}, '{priceFormat}',
                         '{brandName}', 'monitor', {size}, '{sizeFormat}');
            """.format(**(monitor.__dict__))

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#25
0
    def findBySerialNumber(serialNum):

        with Database() as cursor:

            query = """
                SELECT * FROM desktopID WHERE serialNum = '{}';
            """.format(serialNum)
            try:
                cursor.execute(query)
                result = cursor.fetchone()
                return result
            except Exception as error:
                print(error)
                return None
示例#26
0
    def findByPurchaseId(purchaseID):

        with Database() as cursor:

            query = """
                    SELECT * FROM purchasecollection WHERE serialNum = '{}';
                """.format(purchaseID)
            try:
                cursor.execute(query)
                resultSet = cursor.fetchone()
                return resultSet
            except Exception as error:
                print(error)
                return None
示例#27
0
    def findByUser(userId):

        with Database() as cursor:

            query = """
                  SELECT * FROM purchasecollection WHERE userId = '{}';
                """.format(userId)
            try:
                cursor.execute(query)
                result = cursor.fetchall()
                return result
            except Exception as error:
                print(error)
                return None
示例#28
0
    def handle(self, *args, **options):

        with Database() as cursor:

            for user in users:      
                      
                query = """
                    INSERT INTO user (username, firstname, lastname, email, password, isAdmin)
                    VALUES ('{username}', '{firstname}', '{lastname}', '{email}', '{password}', {isAdmin});
                """.format(**user)

                try:
                    cursor.execute(query)
                except Exception as error:
                    print(error)
    def handle(self, *args, **options):

        with Database() as cursor:

            query = """
                CREATE TABLE deleteFlag (
                    modelNumber varchar(255) NOT NULL,
                    type varchar(255) NOT NULL,
                    PRIMARY KEY (modelNumber)
                );
            """

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)
示例#30
0
    def insert(desktop):
        with Database() as cursor:

            query = """
                INSERT INTO desktop (modelNumber, quantity, name, weight, weightFormat, price,
                    priceFormat, brandName, type, ramSize, ramFormat, processorType, numCores, hardDriveSize,
                    hardDriveFormat, dx, dy, dz, dimensionFormat)
                VALUES ('{modelNumber}', {quantity}, '{name}', {weight}, '{weightFormat}', {price},
                    '{priceFormat}', '{brandName}', 'desktop', {ramSize}, '{ramFormat}', '{processorType}', {numCores}, {hardDriveSize},
                    '{hardDriveFormat}', {dx}, {dy}, {dz}, '{dimensionFormat}');
            """.format(**(desktop.__dict__))

            try:
                cursor.execute(query)
            except Exception as error:
                print(error)