def childcare_create(request): if request.method == 'POST': form = ChildcareCreateForm(request.POST) if form.is_valid(): #managers = form.cleaned_data['managers'] childcare = form.save(commit=False) # check if there is a default theme try: theme = get_object_or_404(Theme, pk=1) theme_exist = True except: theme_exist = False if theme_exist: childcare.theme = get_object_or_404(Theme, pk=1) # set 1st theme as default else: theme = Theme(title='Default theme', computer_name='default', description='Default theme') theme.save() childcare.theme = theme childcare = form.save(commit=True) # automatically add current user as manager and give him permissions childcare.managers.add(request.user) managers = list(childcare.managers.all()) # add manager permissions group = Group.objects.get(name='Childcare %s: Manager' % childcare.pk) for manager in managers: manager.groups.add(group) # create default classroom classroom = Classroom(name='%s classroom' % childcare, childcare=childcare) classroom.save() log.info(log_prefix+'Childcare created (childcare: %s, user: %s)' % (childcare.name, request.user)) return HttpResponseRedirect(reverse('childcare:childcare_info', kwargs={'childcare_slug': childcare.slug})) else: form = ChildcareCreateForm() return render(request, 'childcare/childcare_create.html', {'form': form})
def create(self, validated_data): room_number = validated_data.get('room_number') course_name = validated_data.get('course_name') joining_permission = validated_data.get('joining_permission') teacher_id = validated_data.get('user') classroom_id = uuid.uuid4() class_instance = Classroom(id=classroom_id, room_number=room_number, course_name=course_name, teacher_id=teacher_id, joining_permission=joining_permission) class_instance.save() return class_instance
def post(self, request, format=None): data_request = request.data participated_users_list = data_request.pop("participated_user") classroom = Classroom.get_by_id(data_request.pop("classroom")) serializer = MeetingSerializer(data=data_request) if serializer.is_valid(): serializer.save(owner_user=request.user, classroom=classroom) for participated_user in participated_users_list: user_instance = UserAccount.objects.get(pk=participated_user) meeting_instance = Meeting.get_by_id(serializer.data.get("id")) participated_user_instance = ParticipatedUser.objects.create(participated_user=user_instance, meeting=meeting_instance) participated_user_instance.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
buildingID = room[1] roomname = room[2] roomID = room[3] floor = cul_level(buildingID,roomname) if buildingID =='016' or buildingID == '025' or buildingID == '002' or\ buildingID == '027' or buildingID == '033' or buildingID == '032' or buildingID == '042': if len(roomname) <= 10: c = Classroom.objects.filter(roomid__exact = roomID) if c:#若存在则更新并使用该对象 c.update(campus = campusID, building = buildingID,\ floor = floor, room = roomname) c = c[0] c.save() else:#若不存在则插入一个项 c = Classroom(campus = campusID,building = buildingID,floor = floor,\ room = roomname,roomid = roomID) c.save() print c.roomid #更新week表 if time[0]: for j in range(1,19):#周数 time[j-1] = time[j-1].split('|') for k in range(1,8):#星期几 p = (k-1)*6#基址 weekid = str(j)+str(k)+c.roomid w = Week.objects.filter(weekid__exact = weekid) if w:#若存在则使用该对象,更新status表 w = w[0] s = w.status s.class12 = time[j-1][p] s.class34 = time[j-1][p+1]