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 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()