Example #1
0
 def __init__(self, first_name, last_name):
     """
     Extends from Person.__init__() to store common data of a person
     first_name and last_name are string type and storep the first name and last name of a director
     """
     Person.__init__(self, first_name, last_name)
     self._filmography = []
     self.id = ''
     """Store the movies instances in filmography list"""
     self.conn = DBManager()
Example #2
0
 def save_membership(self):
     """
     insert the new membership to database
     :return:
     """
     conn = DBManager()
     type = self.get_type()
     percent = str(self._percent_of_discount)
     execution_query = "insert into membership values('" + type + "'," + percent + ")"
     try:
         conn.query(execution_query)
     except ValueError:
         print("there was an error in the process")
Example #3
0
 def save_membership(self):
     """
     insert the new membership to database
     :return:
     """
     conn = DBManager()
     type = self.get_type()
     percent = str(self._percent_of_discount)
     execution_query = "insert into membership values('" + type + "'," + percent + ")"
     try:
         conn.query(execution_query)
     except ValueError:
         print("there was an error in the process")
Example #4
0
 def get_discount(self, membership_type):
     """
     Returns the percentage of discount according the membership type
     method receives the membership type to search the percent discount according membership
     :return: the percentage from 0 to 100
     """
     conn = DBManager()
     discount = 0
     execution_query = "select percent_discount from membership where type='" + membership_type + "'"
     try:
         discount = conn.query(execution_query).fetchone()[0]
     except ValueError:
         print("there was an error in the process")
     return discount
Example #5
0
 def get_discount(self, membership_type):
     """
     Returns the percentage of discount according the membership type
     method receives the membership type to search the percent discount according membership
     :return: the percentage from 0 to 100
     """
     conn = DBManager()
     discount = 0
     execution_query = "select percent_discount from membership where type='" + membership_type + "'"
     try:
         discount = conn.query(execution_query).fetchone()[0]
     except ValueError:
         print("there was an error in the process")
     return discount
Example #6
0
 def save_customer (self):
     """
     this method will save the customer information
     """
     conn = DBManager()
     first_name = self.first_name
     last_name = self.last_name
     birth_date =  self._birth_date
     address = self._address
     phone = self._email
     email =self._email
     is_active = 1
     execution_query = "insert into customer values('"+ first_name + "','" + last_name + "','" + birth_date + "','" + address + "','" + phone + "','" + email + "'," + is_active +")"
     try:
         conn.query(execution_query)
     except ValueError:
         print ("there was an error in the process")
Example #7
0
class TransactionManager(object):

    def __init__(self):
        """
        Create connection with data base sqlite
        :return:
        """
        self.conn = DBManager()

    def get_users(self):
        """
        Get list of users
        :return:
        """
        for row in self.conn.query("select * from user"):
            print type(row)
            print row
 def simple(self):
     db = DBManager(self.db_name)
     for row in db.query("select * from user"):
         print row
Example #9
0
 def __init__(self):
     """
     Create connection with data base sqlite
     :return:
     """
     self.conn = DBManager()
Example #10
0
class Director(Person):
    """
    Create an instance of Director class
    it will contain director data of a movie
    Director class extends from Person class, attibute 'filmography' keeps a movies list
    that were directed by this director
    """

    def __init__(self, first_name, last_name):
        """
        Extends from Person.__init__() to store common data of a person
        first_name and last_name are string type and storep the first name and last name of a director
        """
        Person.__init__(self, first_name, last_name)
        self._filmography = []
        self.id = ''
        """Store the movies instances in filmography list"""
        self.conn = DBManager()

    def add_movie_to_filmography(self, movie):
        """
        Adds a movie object to filmography list, the movies that were directed by director
        :param movie: Movie instance that will stored in director's filmography list
        :return: True if movie was added to director's filmography otherwise False
        """

        if not self.get_movie({'code': movie.code}):
            self._filmography.append(movie)
            return True
        else:
            print("The movie \'%s\' already exists in director filmography" % movie.title)
            return False

    def get_filmography_list(self):
        """
        Returns the filmography list with movie objects that were directed by director
        :return: The filmography list that stores the movies directed by director
        """
        return self._filmographhy

    def get_movie(self, criteria):
        """
        Returns a movie object from filmography list
        :param criteria: dictionary type, used to search a movie in filmography list by code or title
        :return: a movie object that meets with search criteria, empty list otherwise
        """
        return search_movie_in_filmography(criteria, self._filmography)

    def print_director(self):
        print("{0} {1}".format(self.last_name, self.first_name))

    def save_into_database(self):
        insert_query = "INSERT INTO Director (director_first_name, director_last_name)" + \
                       "VALUES ('" + self.first_name + "', '" + self.last_name + "')"
        self.conn.query(insert_query)
        self.conn.close()

    def update_into_database(self, director_id):
        update_query = "UPDATE Director " +\
                       "SET director_first_name='" + self.first_name + "', director_last_name='" + self.last_name + "'" +\
                        "WHERE director_id='" + str(director_id) + "'"
        self.conn.query(update_query)
        self.conn.close()

    def delete_director_from_database(self, director_id):
        delete_query = "DELETE FROM Director " +\
                        "WHERE director_id='" + str(director_id) + "'"
        self.conn.query(delete_query)
        self.conn.close()