def __init__(self): print '\n' print '**Entering __init__ CD method**' StockItem.__init__(self) '''This loop will continuously re-prompt the user to enter the title if it is larger than 100 characters or has no characters at all. A message will also be displayed on screen describing the errors.''' self.title = raw_input('Please enter the title of the CD: ') while True: if ExceptionCatcher.nameCheck(self.title) == True: break else: self.title = raw_input('Please enter the title of the CD: ') '''The user will only be allowed to enter a date in the correct integer format, otherwise they are caught in a loop forever being re-prompted to enter the date in the correct format''' self.dateReleased = raw_input('Please enter the date of release in the following format DDMMYYYY: ') while True: if ExceptionCatcher.dateCheck(self.dateReleased) == True: break else: self.dateReleased = raw_input('Please enter the date of release in the following format DDMMYYYY: ') '''The user is asked to enter one of three genres. They must enter the genre option properly before they are allowed to proceed.''' while True: self.genre = raw_input('Please enter the genre. "rock", "metal", "blues" are the only allowed options: ') if self.genre == 'rock' or self.genre == 'metal' or self.genre == 'blues': break else: continue self.artist = raw_input('Please enter the name of the artist: ') while True: if ExceptionCatcher.nameCheck(self.artist) == True: break else: self.artist = raw_input('Please enter the name of the artist: ')
def __init__(self, titleStr, dateStr, genreStr, authorStr, clientNameStr, warehouseNumberInt, pricePerUnitFloat): # print 'Creating a book' # Initialise the StockItem class. StockItem.__init__(self, clientNameStr, warehouseNumberInt, pricePerUnitFloat) # Sets the title, test to make sure its a string and is less than 100 characters. if isinstance(titleStr, str) == True: if len(titleStr) <= 100: self.title = titleStr else: self.title = titleStr[:100] raise StockException('Book', '__init__', 'Title must be less than 100 characters.') else: raise StockException('Book', '__init__', 'Title must be a string.') # Sets the dateReleased, tests to make sure date is in a valid format. try: self.dateReleased = datetime.strptime(dateStr, "%d/%m/%Y") except ValueError: raise StockException('Book', '__init__', 'Date must be in the format DD/MM/YYYY.') # Sets the genre, tests to make sure its a string and a valid genre. if isinstance(genreStr, str) == True: if genreStr in ['Rock', 'Metal', 'Blues']: self.genre = genreStr else: self.genreStr = 'Rock' raise StockException('Book', '__init__', 'Genre must be either Rock, Metal or Blues.') else: self.genreStr = 'Rock' raise StockException('Book', '__init__', 'Genre must be a string.') # Sets the artist, tests to make sure its a string. if isinstance(authorStr, str) == True: self.author = authorStr else: raise StockException('Book', '__init__', 'Author must be a string.')