def purchase_code(self, box): ''' Modify the database to reflect purchase ''' team = self.get_current_user().team source_code = SourceCode.by_box_id(box.id) team.money -= abs(source_code.price) team.purchased_source_code.append(source_code) logging.info("%s purchased '%s' from the source code market." % (team.name, source_code.file_name,) ) dbsession.add(team) dbsession.flush()
def create_source_code(self, box, price): ''' Save file data and create object in database ''' description = unicode(self.get_argument('description', '')) file_name = unicode( self.request.files['source_archive'][0]['filename']) source_code = SourceCode( file_name=file_name, box_id=box.id, price=price, description=description, ) dbsession.add(source_code) dbsession.flush() file_data = self.request.files['source_archive'][0]['body'] root = self.application.settings['source_code_market_dir'] save_file = open(str(root + '/' + source_code.uuid), 'w') source_code.checksum = self.get_checksum(file_data) save_file.write(b64encode(file_data)) save_file.close() dbsession.add(source_code) dbsession.flush()
def create_source_code(self, box, price): ''' Save file data and create object in database ''' description = unicode(self.get_argument('description', '')) file_name = unicode( self.request.files['source_archive'][0]['filename'] ) source_code = SourceCode( file_name=file_name, box_id=box.id, price=price, description=description, ) dbsession.add(source_code) dbsession.flush() file_data = self.request.files['source_archive'][0]['body'] root = self.application.settings['source_code_market_dir'] save_file = open(str(root + '/' + source_code.uuid), 'w') source_code.checksum = self.get_checksum(file_data) save_file.write(b64encode(file_data)) save_file.close() dbsession.add(source_code) dbsession.flush()