Exemple #1
0
def save_level_for_editor(request, levelId=None):
    """ Processes a request on creation of the map in the level editor """
    data = json.loads(request.POST['data'])
    if levelId is not None:
        level = get_object_or_404(Level, id=levelId)
    else:
        level = Level(default=False, anonymous=data['anonymous'])
        if permissions.can_create_level(request.user):
            level.owner = request.user.userprofile
    if not permissions.can_save_level(request.user, level):
        return HttpResponseUnauthorized()

    pattern = re.compile("^(\w?[ ]?)*$")
    if pattern.match(data['name']):
        level_management.save_level(level, data)
        # Add the teacher automatically if it is a new level and the student is not independent
        if ((levelId is None) and hasattr(level.owner, 'student') and
                not level.owner.student.is_independent()):
            level.shared_with.add(level.owner.student.class_field.teacher.user.user)
            level.save()
            level_management.email_new_custom_level(level.owner.student.class_field.teacher.new_user.email,
                                                    request.build_absolute_uri(reverse('level_moderation')),
                                                    request.build_absolute_uri(reverse('play_custom_level',
                                                                                       kwargs={'levelId': level.id})),
                                                    request.build_absolute_uri(reverse('home')),
                                                    str(level.owner.student), level.owner.student.class_field.name)
        response = {'id': level.id}
        return HttpResponse(json.dumps(response), content_type='application/javascript')
    else:
        return HttpResponseUnauthorized()
def create_save_level(teacher):
    data = {
        u"origin": u'{"coordinate":[3,5],"direction":"S"}',
        u"pythonEnabled": False,
        u"decor": [],
        u"blocklyEnabled": True,
        u"blocks": [
            {u"type": u"move_forwards"},
            {u"type": u"turn_left"},
            {u"type": u"turn_right"},
        ],
        u"max_fuel": u"50",
        u"pythonViewEnabled": False,
        u"character": u"3",
        u"name": u"abc",
        u"theme": 1,
        u"anonymous": False,
        u"cows": u"[]",
        u"path": u'[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],"connectedNodes":[0]}]',
        u"traffic_lights": u"[]",
        u"destinations": u"[[3,4]]",
    }
    level = Level(default=False, anonymous=data["anonymous"])
    level.owner = teacher.user.user.userprofile
    level_management.save_level(level, data)
    level.save()

    return level.id
Exemple #3
0
def create_save_level(teacher):
    data = {u'origin': u'{"coordinate":[3,5],"direction":"S"}', u'pythonEnabled': False, u'decor': [], u'blocklyEnabled': True, u'blocks': [{u'type': u'move_forwards'}, {u'type': u'turn_left'}, {u'type': u'turn_right'}], u'max_fuel': u'50', u'pythonViewEnabled': False, u'character': u'3', u'name': u'abc', u'theme': 1, u'anonymous': False, u'cows': u'[]', u'path': u'[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],"connectedNodes":[0]}]', u'traffic_lights': u'[]', u'destinations': u'[[3,4]]'}
    level = Level(default=False, anonymous=data['anonymous'])
    level.owner = teacher.user.user.userprofile
    level_management.save_level(level, data)
    level.save()

    return level.id
Exemple #4
0
def create_save_level(teacher):
    data = {
        u"origin":
        u'{"coordinate":[3,5],"direction":"S"}',
        u"pythonEnabled":
        False,
        u"decor": [],
        u"blocklyEnabled":
        True,
        u"blocks": [
            {
                u"type": u"move_forwards"
            },
            {
                u"type": u"turn_left"
            },
            {
                u"type": u"turn_right"
            },
        ],
        u"max_fuel":
        u"50",
        u"pythonViewEnabled":
        False,
        u"character":
        u"3",
        u"name":
        u"abc",
        u"theme":
        1,
        u"anonymous":
        False,
        u"cows":
        u"[]",
        u"path":
        u'[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],"connectedNodes":[0]}]',
        u"traffic_lights":
        u"[]",
        u"destinations":
        u"[[3,4]]",
    }
    level = Level(default=False, anonymous=data["anonymous"])
    level.owner = teacher.user.user.userprofile
    level_management.save_level(level, data)
    level.save()

    return level.id
def save_level_for_editor(request, levelId=None):
    """ Processes a request on creation of the map in the level editor """
    data = json.loads(request.POST['data'])

    if levelId is not None:
        level = get_object_or_404(Level, id=levelId)
    else:
        level = Level(default=False, anonymous=data['anonymous'])

        if permissions.can_create_level(request.user):
            level.owner = request.user.userprofile

    if not permissions.can_save_level(request.user, level):
        return HttpResponseUnauthorized()
    level_management.save_level(level, data)
    # Add the teacher automatically if it is a new level and the student is not independent
    if ((levelId is None) and hasattr(level.owner, 'student') and
            not level.owner.student.is_independent()):
        level.shared_with.add(level.owner.student.class_field.teacher.user.user)
        level.save()
    response = {'id': level.id}
    return HttpResponse(json.dumps(response), content_type='application/javascript')
Exemple #6
0
def save_level_for_editor(request, levelId=None):
    """ Processes a request on creation of the map in the level editor """
    data = json.loads(request.POST['data'])

    if levelId is not None:
        level = get_object_or_404(Level, id=levelId)
    else:
        level = Level(default=False, anonymous=data['anonymous'])

        if permissions.can_create_level(request.user):
            level.owner = request.user.userprofile

    if not permissions.can_save_level(request.user, level):
        return HttpResponseUnauthorized()
    level_management.save_level(level, data)
    # Add the teacher automatically if it is a new level and the student is not independent
    if ((levelId is None) and hasattr(level.owner, 'student') and
            not level.owner.student.is_independent()):
        level.shared_with.add(level.owner.student.class_field.teacher.user.user)
        level.save()
    response = {'id': level.id}
    return HttpResponse(json.dumps(response), content_type='application/javascript')
def save_level_for_editor(request, levelId=None):
    """ Processes a request on creation of the map in the level editor """
    data = json.loads(request.POST["data"])
    if levelId is not None:
        level = get_object_or_404(Level, id=levelId)
    else:
        level = Level(default=False, anonymous=data["anonymous"])
        if permissions.can_create_level(request.user):
            level.owner = request.user.userprofile
    if not permissions.can_save_level(request.user, level):
        return HttpResponseUnauthorized()

    pattern = re.compile("^(\w?[ ]?)*$")
    if pattern.match(data["name"]):
        level_management.save_level(level, data)
        # Add the teacher automatically if it is a new level and the student is not
        # independent
        if (
            (levelId is None)
            and hasattr(level.owner, "student")
            and not level.owner.student.is_independent()
        ):
            level.shared_with.add(level.owner.student.class_field.teacher.user.user)
            level.save()
            if not data["anonymous"]:
                level_management.email_new_custom_level(
                    level.owner.student.class_field.teacher.new_user.email,
                    request.build_absolute_uri(reverse("level_moderation")),
                    request.build_absolute_uri(
                        reverse("play_custom_level", kwargs={"levelId": level.id})
                    ),
                    request.build_absolute_uri(reverse("home")),
                    str(level.owner.student),
                    level.owner.student.class_field.name,
                )
        response = {"id": level.id}
        return HttpResponse(json.dumps(response), content_type="application/javascript")
    else:
        return HttpResponseUnauthorized()