def add_project(request): form = ProjectForm(**json.loads(request.body)) if not form.validate(): raise Http400 project = ProjectModel( title=form.title.data, description=form.description.data, root_ids=[request.user.key().id()], member_ids=[request.user.key().id()], floor_lowest=form.floor_lowest.data, floor_highest=form.floor_highest.data, room_options=form.room_options.data, ) project.put() return JsonResponse(project)
def update_project(request, project_id): form = ProjectForm(**json.loads(request.body)) if not form.validate(): raise Http400 project = ProjectModel.get_by_id(long(project_id)) if project is None: raise Http404 if request.user.permission != UserPermission.root and\ request.user.key().id() not in project.root_ids: raise Http403 project.title = form.title.data project.description = form.description.data project.member_ids = form.member_ids.data project.root_ids = form.root_ids.data project.floor_lowest = form.floor_lowest.data project.floor_highest = form.floor_highest.data project.room_options = form.room_options.data project.put() return JsonResponse(project)