'Create a new release as a copy of the state of the compiled slug and config vars of a
previous release.'

def rollback(self, request, **kwargs):

    app = self.get_app()
    try:
        release = app.release_set.latest()
        version_to_rollback_to = (release.version - 1)
        if request.data.get('version'):
            version_to_rollback_to = int(request.data['version'])
        new_release = release.rollback(request.user, version_to_rollback_to)
        response = {'version': new_release.version}
        return Response(response, status=status.HTTP_201_CREATED)
    except EnvironmentError as e:
        return Response({'detail': str(e)}, status=status.HTTP_400_BAD_REQUEST)
    except RuntimeError:
        new_release.delete()
        raise
