def create(project, creator): # If the project argument is an integer then get # project by `id`, otherwise by `address` try: project_id = int(project) except ValueError: project_id = None if project_id: project = Project.objects.get(id=project_id) else: project = Project.objects.get(address=project) # Check that there are no open checkouts for the # project (for some projects/editors/permissions this may be # able to be relaxed in the future) checkouts_open = Checkout.objects.filter( Q(project=project) & (Q(status=OPEN) | Q(status=LAUNCHING))) if checkouts_open: # TODO Terminate the open checkout if they have not been `saved` # for more than a certain period of time checkout = checkouts_open[0] raise CheckoutCreateError( type='exists', message='You already have a checkout open for this project', data={'url': checkout.editor.url}) # Currently, create a native editor # In the future, this the editor class might be chosen # by the user editor = Editor.create('native') # Currently, create a native execution host # In the future, this the editor class might be chosen # by the user host = Host.create('native') return Checkout.objects.create(project=project, editor=editor, host=host, creator=creator)