Beispiel #1
0
    def save(self):
        """
        Save/update the object to the persistent backend. It will also invalidate certain caches.

        :raises ApiTokenNotFoundException
        """

        db = MySQLDB()

        if self.api_token:
            if self._exists():
                db.execute_query("UPDATE `API_Token` SET "
                                 "`user_id`={0},`distributed_on`='{1}',`valid_until`='{2}' WHERE `api_token`='{3}';"
                                 .format(self.user_id, self.distributed_on, self.valid_until, self.api_token)
                                 )
                db.commit()
            else:
                raise ApiTokenNotFoundException("Object ApiToken with api_token '{0}' "
                                                "not found in the persistent backend".format(self.api_token),
                                                self.module)
        else:
            self.logger.logger("Inserting new ApiToken into DB", 4, self.module)
            db.execute_query("INSERT INTO `API_Token` (`user_id`, `api_token`, `distributed_on`, `valid_until`) VALUES "
                             "({0}, '{1}', '{2}', '{3}';"
                             .format(self.user_id, self._api_token, self.distributed_on, self.valid_until)
                             )
            db.commit()
Beispiel #2
0
    def save(self):
        """
        Save/update the object to the persistent backend. It will also invalidate certain caches.

        :raises PiMoticUserNotFoundExceptionsException
        """

        db = MySQLDB()

        if self.id:
            if self._exists():
                db.execute_query("UPDATE `User` SET `password`='{0}',"
                                "`name`='{1}',`surname`='{2}',`e-mail`='{3}',"
                                "`user_access`={4}, `admin_access`={5} WHERE `id`={6};"
                                 .format(self.password, self.name, self.surname,
                                        self.email, self.user_access, self.admin_access, self.id)
                                 )
                db.commit()
            else:
                raise UserNotFoundException("Object User with name '{0}' not found in persistent database".format(self.name),
                                        self.module)
        else:
            self.logger.logger("Inserting new User into DB", 4, self.module)
            db.execute_query("INSERT INTO `User` (`username`, `password`, `name`, `surname`, `e-mail`, `joined_on`"
                            ", `user_access`, `admin_access`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', now(), "
                            "{5}, {6});".format(self.username, self.password, self.name, self.surname, self.email,
                                                self.user_access, self.admin_access))
            db.commit()
Beispiel #3
0
    def save(self): # @TODO: save
        """
        Save/update the object to the persistent backend. It will also invalidate certain caches.
        """

        db = MySQLDB()

        if self._exists():
            db.execute_query("UPDATE `PI_pin` SET `pin_number`='{0}', WHERE `id`={1};"
                             .format(self.pin_number, self.id)
                             )
            db.commit()
        else:
            self.logger.logger("Inserting new PiPin into DB", 4, self.module)
            db.execute_query("INSERT INTO `PI_pin`(`pin_number`) VALUES ('{0}');"
                             .format(self.pin_number))
            db.commit()
Beispiel #4
0
    def save(self):
        """
        Save/update the object to the persistent backend. It will also invalidate certain caches.
        """

        db = MySQLDB()

        if self._exists():
            db.execute_query("UPDATE `Room` SET `description`='{0}', WHERE `name`={1};"
                             .format(self.description, self.name)
                             )
            db.commit()
        else:
            self.logger.logger("Inserting new Room into DB", 4, self.module)
            db.execute_query("INSERT INTO `Room`(`name`, `description`) VALUES ('{0}', '{1}');"
                             .format(self.name, self.description))
            db.commit()
Beispiel #5
0
    def delete(self):
        """
        Deletes the object from the persistent backend. It will also invalidate certain caches.

        :raises UserNotFoundException
        """

        db = MySQLDB()

        if self._exists():
            mysql_check = self._select()

            if mysql_check:
                db.execute_query("DELETE FROM `User` WHERE `id`={0};".format(self.id))
                db.commit()
            else:
                raise UserNotFoundException("Object User with name '{0}' not found in the persistent backend"
                                        .format(self.name), self.module)
        else:
            raise UserNotFoundException("Object User with name '{0}' is a new object, "
                                    "and can't be deleted from the persistent database"
                                    .format(self.name), self.module)
Beispiel #6
0
    def delete(self): # @TODO: delete
        """
        Deletes the object from the persistent backend. It will also invalidate certain caches.

        :raises SensorNotFoundException
        """

        db = MySQLDB()

        if self._exists():
            mysql_check = self._select()

            if mysql_check:
                db.execute_query("DELETE FROM `PI_pin` WHERE `id`='{0}';".format(self.id))
                db.commit()
            else:
                raise SensorNotFoundException("Object PiPin with id '{0}' not found in the persistent database"
                                              .format(self.id), self.module)
        else:
            raise SensorNotFoundException("Object PiPin with id '{0}' is a new object, "
                                          "and can't be deleted from the persistent database"
                                          .format(self.id), self.module)
Beispiel #7
0
    def delete(self):
        """
        Deletes the object from the persistent backend. It will also invalidate certain caches.

        :raises ApiTokenNotFoundException
        """

        db = MySQLDB()

        if self._exists():
            mysql_check = self._select()

            if mysql_check:
                db.execute_query("DELETE FROM `API_Token` WHERE `api_token`='{0}';".format(self.api_token))
                db.commit()
            else:
                raise ApiTokenNotFoundException(
                        "Object ApiToken with api_token '{0}' not found in the persistent database"
                        .format(self.api_token), self.module)
        else:
            raise ApiTokenNotFoundException(
                    "Object ApiToken with api_token '{0}' is a new object, "
                    "and can't be deleted from the persistent database"
                    .format(self.api_token), self.module)