def confirmPersonCandidate(ticket): 'Move changes from the PersonCandidate table into the Person table' # Query candidate = Session.query(model.PersonCandidate).filter(model.PersonCandidate.ticket==ticket).filter(model.PersonCandidate.when_expired>=datetime.datetime.utcnow()).first() # If the ticket exists, if candidate: # If the person exists, if candidate.person_id: # Update person person = Session.query(model.Person).get(candidate.person_id) person.username = candidate.username person.password_hash = candidate.password_hash person.nickname = candidate.nickname person.email = candidate.email person.email_sms = candidate.email_sms # Reset rejection_count person.rejection_count = 0 # If the person does not exist, else: # Add person Session.add(model.Person(candidate.username, candidate.password_hash, candidate.nickname, candidate.email, candidate.email_sms)) # Delete ticket Session.delete(candidate) # Commit Session.commit() # Return return candidate
def delete(self, id): 'DELETE /scenarios/id: Delete an existing item' # Initialize personID = h.getPersonID() # Load scenario = Session.query(model.Scenario).filter(model.Scenario.id==id).first() # If the scenario doesn't exist, if not scenario: return dict(isOk=0, message='Scenario %s does not exist' % id) # If the user is not the owner, if personID != scenario.owner_id: return dict(isOk=0, message='You are not the owner of scenario %s' % id) # Delete Session.delete(scenario) Session.commit() # Return return dict(isOk=1)
scenario.input = scenarioInput Session.add(scenario) Session.commit() # Unzip scenarioFolder = scenario.getFolder() store.unzipData(scenarioFolder, scenarioData) # Run try: scenario.run() scenario.status = model.statusDone except: scenario.output = dict(traceback=''.join(traceback.format_exception(*sys.exc_info()))) scenario.status = model.statusFailed finally: Session.commit() # Pack result into outgoing message outgoingPack = scenarioID, scenario.output, open(scenarioFolder + '.zip', 'rb').read() if os.path.exists(scenarioFolder + '.zip') else None, scenario.status # Send outgoing message outgoingMessage = amqp.Message(pickle.dumps(outgoingPack)) outgoingMessage.properties['delivery_mode'] = 2 channel.basic_publish(outgoingMessage, exchange=outgoingExchange, routing_key=outgoingKey) # Clean up shutil.rmtree(scenarioFolder) store.removeSafely(scenarioFolder + '.zip') Session.delete(scenario) Session.commit() # Close channel channel.close() # Close connection connection.close()