# hockey_player.py # # BUGS: # # - HTML: # Floating the picture left doesn't play well with the containing # div since it takes the image out of the normal flow, so it # doesn't get bordered. # # Version 0 (archived as Quote_0.py) # # - Initial roughing out by modifying quote.py # - Delete console routines. def HTML_factory(form_dict): '''Builds a Quote from the data returned in the form CREATION_FORM.''' return Hockey_player(form_dict['name'], form_dict['goals'], form_dict['image']) # Use this template for both creation via POST and update via PUT. CREATION_FORM = '''

Create form




''' UPDATE_TEMPLATE = '''

Update form




''' HTML_TEMPLATE = '''

%s
%s career goals (regular season plus playoffs).

''' class Hockey_player: def __init__(self, name, goals='0', image=''): self.name = name self.goals = goals self.image = image self.uid = str(hash('Hockey_player' + self.name)) def __str__(self): return '[%s] %s: %s career goals. Image at: %s' % (self.uid, self.name, self.goals, self.image) def HTML(self): return HTML_TEMPLATE % (self.image, self.name, self.goals, self.uid, self.uid, self.uid) def HTML_update_form(self): return UPDATE_TEMPLATE % (self.name, self.image, self.goals, self.author) if __name__ == '__main__': def bordered(s): return len(s)*'='+'\n'+s+'\n'+len(s)*'-' print bordered('Testing __init__() and __str__()') p = Hockey_player( 'Gordie Howe', '1071', 'http://www.doubleextrapoint.com/images/stories/gordie-howe-puck.jpg') print 'The Hockey_player p is:' print '\t', p print print bordered('Testing HTML()') print 'Here\'s the HTMl representation of p:' print p.HTML()