Example #1
0
def workflow_list(request, format=None):
    """List all workflows or create a new workflow."""
    if request.method == 'GET':
        workflows = Workflow.objects \
                .filter(Q(owner=request.user)
                        | Q(in_all_users_workflow_lists=True)) \
                .filter(Q(lesson_slug__isnull=True) | Q(lesson_slug=''))

        # turn queryset into list so we can sort it ourselves by reverse chron
        # (this is because 'last update' is a property of the delta, not the
        # Workflow. [2018-06-18, adamhooper] TODO make workflow.last_update a
        # column.
        workflows = list(workflows)
        workflows.sort(key=lambda wf: wf.last_update(), reverse=True)

        serializer = WorkflowSerializerLite(workflows, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        workflow = Workflow.objects.create(
            name='New Workflow',
            owner=request.user
        )
        serializer = WorkflowSerializerLite(workflow)
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Example #2
0
    def get(self, request: HttpRequest):
        """Render workflow-list page."""
        # Separate out workflows by type
        workflows = {}
        workflows['owned'] = Workflow.objects \
            .filter(owner=request.user) \
            .filter(Q(lesson_slug__isnull=True) | Q(lesson_slug=''))

        workflows['shared'] = Workflow.objects \
            .filter(acl__email=request.user.email) \
            .filter(Q(lesson_slug__isnull=True) | Q(lesson_slug=''))

        workflows['templates'] = Workflow.objects \
            .filter(in_all_users_workflow_lists=True) \
            .filter(Q(lesson_slug__isnull=True) | Q(lesson_slug=''))

        init_state = {
            'loggedInUser': UserSerializer(request.user).data,
            'workflows': {}
        }
        # turn queryset into list so we can sort it ourselves by reverse chron
        # (this is because 'last update' is a property of the delta, not the
        # Workflow. [2018-06-18, adamhooper] TODO make workflow.last_update a
        # column.
        for key, value in workflows.items():
            value = list(value)
            value.sort(key=lambda wf: wf.last_update(), reverse=True)
            serializer = WorkflowSerializerLite(value,
                                                many=True,
                                                context={'request': request})
            init_state['workflows'][key] = serializer.data

        return TemplateResponse(request, 'workflows.html',
                                {'initState': init_state})
Example #3
0
def refresh_from_github(request):
    serializer = WorkflowSerializerLite(request, many=True)
    try:
        refresh_module_from_github(request.data["url"])
        return Response(status=status.HTTP_201_CREATED)
    except ValidationError as error:
        return Response(error, status=status.HTTP_400_BAD_REQUEST)
Example #4
0
def embed(request, wfmodule_id):
    try:
        wf_module = WfModule.objects.get(pk=wfmodule_id, is_deleted=False)
    except WfModule.DoesNotExist:
        wf_module = None

    if wf_module and (not wf_module.workflow or
                      not wf_module.workflow.request_authorized_read(request)
                      or not wf_module.module_version
                      or not wf_module.module_version.html_output):
        wf_module = None

    if wf_module:
        workflow_module_serializer = WfModuleSerializer(wf_module)
        workflow_serializer = WorkflowSerializerLite(
            wf_module.workflow, context={"request": request})
        init_state = {
            "workflow": workflow_serializer.data,
            "wf_module": workflow_module_serializer.data,
        }
    else:
        init_state = {"workflow": None, "wf_module": None}

    response = TemplateResponse(request, "embed.html",
                                {"initState": init_state})
    return response
Example #5
0
def workflow_list(request, format=None):
    """List all workflows or create a new workflow."""
    workflow = Workflow.objects.create(
        name='New Workflow',
        owner=request.user
    )
    serializer = WorkflowSerializerLite(workflow,
                                        context={'request': request})
    return Response(serializer.data, status=status.HTTP_201_CREATED)
Example #6
0
def workflow_duplicate(request, pk):
    workflow = _lookup_workflow_for_read(pk, request)

    workflow2 = workflow.duplicate(request.user)
    serializer = WorkflowSerializerLite(workflow2)

    server.utils.log_user_event(request, 'Duplicate Workflow',
                                {'name': workflow.name})

    return Response(serializer.data, status.HTTP_201_CREATED)
Example #7
0
def workflow_list(request, format=None):
    """Create a new workflow."""
    workflow = Workflow.create_and_init(
        name='Untitled Workflow',
        owner=request.user,
        selected_tab_position=0
    )
    serializer = WorkflowSerializerLite(workflow,
                                        context={'request': request})
    return Response(serializer.data, status=status.HTTP_201_CREATED)
Example #8
0
    def post(self, request: HttpRequest, workflow: Workflow):
        workflow2 = workflow.duplicate(request.user)
        serializer = WorkflowSerializerLite(workflow2,
                                            context={'request': request})

        server.utils.log_user_event(request, 'Duplicate Workflow',
                                    {'name': workflow.name})

        async_to_sync(workflow2.last_delta.schedule_execute)()

        return JsonResponse(serializer.data, status=status.HTTP_201_CREATED)
Example #9
0
    def post(self, request: HttpRequest, workflow: Workflow):
        workflow2 = workflow.duplicate(request.user)
        serializer = WorkflowSerializerLite(workflow2,
                                            context={'request': request})

        server.utils.log_user_event_from_request(request, 'Duplicate Workflow',
                                                 {'name': workflow.name})

        async_to_sync(rabbitmq.queue_render)(workflow2.id,
                                             workflow2.last_delta_id)

        return JsonResponse(serializer.data, status=status.HTTP_201_CREATED)
Example #10
0
def workflow_duplicate(request, pk):
    try:
        workflow = Workflow.objects.get(pk=pk)
    except Workflow.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if not workflow.user_authorized_read(request.user):
        return HttpResponseForbidden()

    workflow2 = workflow.duplicate(request.user)
    serializer = WorkflowSerializerLite(workflow2)

    log_user_event(request.user, 'Duplicate Workflow', {'name':workflow.name})

    return Response(serializer.data, status.HTTP_201_CREATED)
Example #11
0
def workflow_list(request, format=None):
    if request.method == 'GET':
        workflows = Workflow.objects.filter(owner=request.user)
        serializer = WorkflowSerializerLite(workflows, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = WorkflowSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(owner=request.user)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Example #12
0
def embed(request, wfmodule_id):
    try:
        wf_module = WfModule.objects.get(pk=wfmodule_id)
    except WfModule.DoesNotExist:
        wf_module = None

    if wf_module and (not wf_module.workflow.request_authorized_read(request)
                      or not wf_module.module_version.html_output):
        wf_module = None

    if wf_module:
        workflow_module_serializer = WfModuleSerializer(wf_module)
        workflow_serializer = WorkflowSerializerLite(wf_module.workflow)
        init_state = {
            'workflow': workflow_serializer.data,
            'wf_module': workflow_module_serializer.data
        }
    else:
        init_state = {'workflow': None, 'wf_module': None}

    response = TemplateResponse(request, 'embed.html',
                                {'initState': init_state})
    return response
Example #13
0
def workflow_list(request, format=None):
    if request.method == 'GET':
        workflows = Workflow.objects.filter(Q(owner=request.user))

        # turn queryset into array so we can sort it ourselves by reverse chron
        workflows = workflows.all()
        workflows = sorted(workflows, key=lambda wf: wf.last_update(), reverse=True)

        serializer = WorkflowSerializerLite(workflows, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = WorkflowSerializer(data=request.data, context={'user': request.user})
        if serializer.is_valid():
            serializer.save(owner=request.user)
            log_user_event(request.user, 'Create Workflow')
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)