Esempio n. 1
0
def save_workspace(request, workspaceID=None):
    name = request.POST.get("name")
    contents = request.POST.get("contents")
    python_contents = request.POST.get("python_contents")
    blockly_enabled = json.loads(request.POST.get("blockly_enabled"))
    python_enabled = json.loads(request.POST.get("python_enabled"))

    workspace = None
    if workspaceID:
        workspace = Workspace.objects.get(id=workspaceID)
    elif permissions.can_create_workspace(request.user):
        workspace = Workspace(owner=request.user.userprofile)

    if workspace and permissions.can_save_workspace(request.user, workspace):
        workspace.name = name
        workspace.contents = contents
        workspace.python_contents = python_contents
        workspace.blockly_enabled = blockly_enabled
        workspace.python_enabled = python_enabled
        workspace.save()

    return load_list_of_workspaces(request)
Esempio n. 2
0
def save_workspace(request, workspaceID=None):
    name = request.POST.get('name')
    contents = request.POST.get('contents')
    python_contents = request.POST.get('python_contents')

    workspace = None
    if workspaceID:
        workspace = Workspace.objects.get(id=workspaceID)
    elif permissions.can_create_workspace(request.user):
        workspace = Workspace(owner=request.user.userprofile)

    if workspace and permissions.can_save_workspace(request.user, workspace):
        workspace.name = name
        workspace.contents = contents
        workspace.python_contents = python_contents
        workspace.save()

    return load_list_of_workspaces(request)
Esempio n. 3
0
def save_workspace(request, workspaceID=None):
    name = request.POST.get('name')
    contents = request.POST.get('contents')
    python_contents = request.POST.get('python_contents')
    blockly_enabled = json.loads(request.POST.get('blockly_enabled'))
    python_enabled = json.loads(request.POST.get('python_enabled'))

    workspace = None
    if workspaceID:
        workspace = Workspace.objects.get(id=workspaceID)
    elif permissions.can_create_workspace(request.user):
        workspace = Workspace(owner=request.user.userprofile)

    if workspace and permissions.can_save_workspace(request.user, workspace):
        workspace.name = name
        workspace.contents = contents
        workspace.python_contents = python_contents
        workspace.blockly_enabled = blockly_enabled
        workspace.python_enabled = python_enabled
        workspace.save()

    return load_list_of_workspaces(request)
Esempio n. 4
0
def load_workspace_solution(request, levelName):

    if levelName in solutions:
        workspace = Workspace(owner=request.user.userprofile)
        workspace.id = levelName
        workspace.name = levelName
        workspace.contents = solutions["blockly_default"]
        workspace.python_contents = solutions["python_default"]

        if int(levelName) <= 91:
            workspace.contents = solutions[levelName]
            workspace.blockly_enabled = True
            workspace.python_enabled = False
        else:
            workspace.python_contents = solutions[levelName]
            workspace.blockly_enabled = False
            workspace.python_enabled = True

        return HttpResponse(
            json.dumps({
                "contents": workspace.contents,
                "python_contents": workspace.python_contents,
            }),
            content_type="application/json",
        )

    raise Http404
Esempio n. 5
0
def load_workspace_solution(request, levelName):

    if levelName in solutions:
        workspace = Workspace(owner=request.user.userprofile)
        workspace.id = levelName
        workspace.name = levelName
        workspace.contents = solutions["blockly_default"]
        workspace.python_contents = solutions["python_default"]

        if int(levelName) <= 91:
            workspace.contents = solutions[levelName]
            workspace.blockly_enabled = True
            workspace.python_enabled = False
        else:
            workspace.python_contents = solutions[levelName]
            workspace.blockly_enabled = False
            workspace.python_enabled = True

        return HttpResponse(
            json.dumps(
                {
                    "contents": workspace.contents,
                    "python_contents": workspace.python_contents,
                }
            ),
            content_type="application/json",
        )

    raise Http404