Ejemplo n.º 1
0
def make_init_state(request, workflow=None, modules=None):
    """Build a dict to embed as JSON in `window.initState` in HTML."""
    ret = {}

    if workflow:
        ret['workflowId'] = workflow.id
        ret['workflow'] = WorkflowSerializer(workflow,
                                             context={'request': request}).data
        wf_modules = workflow.wf_modules \
            .prefetch_related('parameter_vals__parameter_spec',
                              'module_version')
        wf_module_data_list = WfModuleSerializer(wf_modules, many=True).data
        ret['wfModules'] = dict([(str(wfm['id']), wfm)
                                 for wfm in wf_module_data_list])
        ret['selected_wf_module'] = workflow.selected_wf_module
        del ret['workflow']['selected_wf_module']

    if modules:
        modules_data_list = ModuleSerializer(modules, many=True).data
        ret['modules'] = dict([(str(m['id']), m) for m in modules_data_list])

    if request.user.is_authenticated():
        ret['loggedInUser'] = UserSerializer(request.user).data

    if workflow and not workflow.request_read_only(request):
        ret['updateTableModuleIds'] = load_update_table_module_ids()

    return ret
Ejemplo n.º 2
0
def make_init_state(request, workflow=None, modules=None):
    """Build a dict to embed as JSON in `window.initState` in HTML."""
    ret = {}

    if workflow:
        ret['workflowId'] = workflow.id
        ret['workflow'] = WorkflowSerializer(workflow,
                                             context={'request': request}).data
        wf_modules = workflow.wf_modules \
            .prefetch_related('parameter_vals__parameter_spec',
                              'module_version')
        wf_module_data_list = WfModuleSerializer(wf_modules, many=True).data
        ret['wfModules'] = dict([(str(wfm['id']), wfm)
                                 for wfm in wf_module_data_list])
        ret['selected_wf_module'] = workflow.selected_wf_module
        ret['uploadConfig'] = {
            'bucket': minio.UserFilesBucket,
            'accessKey': settings.MINIO_ACCESS_KEY,  # never _SECRET_KEY
            'server': settings.MINIO_EXTERNAL_URL
        }
        ret['user_files_bucket'] = minio.UserFilesBucket
        del ret['workflow']['selected_wf_module']

    if modules:
        modules_data_list = ModuleSerializer(modules, many=True).data
        ret['modules'] = dict([(str(m['id']), m) for m in modules_data_list])

    if request.user.is_authenticated():
        ret['loggedInUser'] = UserSerializer(request.user).data

    if workflow and not workflow.request_read_only(request):
        ret['updateTableModuleIds'] = load_update_table_module_ids()

    return ret
Ejemplo n.º 3
0
def module_detail(request, pk, format=None):
    if request.method == 'GET':
        try:
            module = Module.objects.get(pk=pk)
        except Module.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = ModuleSerializer(module)
        return Response(serializer.data)
Ejemplo n.º 4
0
def import_from_github(request):
    if not request.user.is_staff:
        return JsonResponse({'error': 'Only an admin can call this method'},
                            status=status.HTTP_403_FORBIDDEN)

    try:
        module = import_module_from_github(request.data["url"])
        data = ModuleSerializer(module).data
        return JsonResponse(data, status=status.HTTP_201_CREATED)
    except (RuntimeError, ValueError) as err:
        # Respond with 200 OK so the client side can read the error message.
        # TODO make the client smarter
        return JsonResponse({'error': str(err)}, status=status.HTTP_200_OK)
Ejemplo n.º 5
0
def make_init_state(request, workflow=None, modules=None):
    """
    Build a dict to embed as JSON in `window.initState` in HTML.

    Raise Http404 if the workflow disappeared.
    """
    ret = {}

    if workflow:
        try:
            with workflow.cooperative_lock():  # raise DoesNotExist on race
                ret['workflowId'] = workflow.id
                ret['workflow'] = WorkflowSerializer(workflow,
                                                     context={
                                                         'request': request
                                                     }).data

                tabs = list(workflow.live_tabs)
                ret['tabs'] = dict(
                    (str(tab.slug), TabSerializer(tab).data) for tab in tabs)

                wf_modules = list(WfModule.live_in_workflow(workflow))

                ret['wfModules'] = {
                    str(wfm.id): WfModuleSerializer(wfm).data
                    for wfm in wf_modules
                }
        except Workflow.DoesNotExist:
            raise Http404('Workflow was recently deleted')

        ret['uploadConfig'] = {
            'bucket': minio.UserFilesBucket,
            'accessKey': settings.MINIO_ACCESS_KEY,  # never _SECRET_KEY
            'server': settings.MINIO_EXTERNAL_URL
        }
        ret['user_files_bucket'] = minio.UserFilesBucket

    if modules:
        modules_data_list = ModuleSerializer(modules, many=True).data
        ret['modules'] = dict([(str(m['id_name']), m)
                               for m in modules_data_list])

    if request.user.is_authenticated:
        ret['loggedInUser'] = UserSerializer(request.user).data

    return ret
Ejemplo n.º 6
0
def make_init_state(request, workflow=None, modules=None):
    ret = {}

    if workflow:
        ret['workflowId'] = workflow.id
        ret['workflow'] = WorkflowSerializer(workflow, context={'user' : request.user}).data
        ret['selected_wf_module'] = workflow.selected_wf_module

    if modules:
        ret['modules'] = ModuleSerializer(modules, many=True).data

    if request.user.is_authenticated():
        ret['loggedInUser'] = UserSerializer(request.user).data
        ret['editCellsModuleId'] = edit_cells_module_id()
        ret['sortModuleId'] = sort_module_id()
        ret['reorderModuleId'] = reorder_module_id()

    return ret
Ejemplo n.º 7
0
def make_init_state(request, workflow=None, modules=None):
    """
    Build a dict to embed as JSON in `window.initState` in HTML.

    Raise Http404 if the workflow disappeared.

    Side-effect: update workflow.last_viewed_at.
    """
    ret = {}

    if workflow:
        try:
            with workflow.cooperative_lock():  # raise DoesNotExist on race
                ret['workflowId'] = workflow.id
                ret['workflow'] = WorkflowSerializer(workflow,
                                                     context={
                                                         'request': request
                                                     }).data

                tabs = list(workflow.live_tabs)
                ret['tabs'] = dict(
                    (str(tab.slug), TabSerializer(tab).data) for tab in tabs)

                wf_modules = list(WfModule.live_in_workflow(workflow))

                ret['wfModules'] = {
                    str(wfm.id): WfModuleSerializer(wfm).data
                    for wfm in wf_modules
                }
                workflow.last_viewed_at = timezone.now()
                workflow.save(update_fields=['last_viewed_at'])
        except Workflow.DoesNotExist:
            raise Http404('Workflow was recently deleted')

    if modules:
        modules_data_list = ModuleSerializer(modules, many=True).data
        ret['modules'] = dict([(str(m['id_name']), m)
                               for m in modules_data_list])

    if request.user.is_authenticated:
        ret['loggedInUser'] = UserSerializer(request.user).data

    return ret
Ejemplo n.º 8
0
def module_list(request, format=None):
    if request.method == 'GET':
        modules = Module.objects.all()
        serializer = ModuleSerializer(modules, many=True)
        return Response(serializer.data)