def timeslots(request): if request.method == 'GET': slots = TimeSlot.objects.order_by("-date", "-start_time") # If the method is get, then just display the suggestion page return render(request, 'professor_view/add_time_slots.html', { 'title': 'Add time slot', "timeslots": slots }) else: # slots = json.loads(request.POST.get("slots", "")) startTimes = request.POST.getlist("startTimes[]") endTimes = request.POST.getlist("endTimes[]") professor_email = request.POST.get("professor_email") prof = None try: prof = Professor.objects.get(email=professor_email) except Professor.DoesNotExist: return JsonResponse({'result': "Erro"}) date = request.POST.get("date") professor_name = request.user.first_name + " " + request.user.last_name if prof != None: professor_name = prof.title + " " + professor_name for i in range(len(startTimes)): start = startTimes[i] end = endTimes[i] timeslot = TimeSlot() timeslot.save_data(professor_name, professor_email, start, end, date) timeslot.save() return JsonResponse({'result': 'Ok'})
def delete_appointment(request, id): app = Appointment.objects.get(id=id) app.delete() slot = TimeSlot() slot.save_data(app.professor_name, app.professor_email, app.start_time, app.end_time, app.date) slot.save() return redirect('/all_appointments/')
def add_time_slot(self, order, start, end): one_time_slot = TimeSlot(order=order, start=start, end=end) one_time_slot.save()
def setUp(self): self.assertTrue(settings.FAKE_SMS_SERVER) # 创建老师 teacher_user = User.objects.create(username=self.teacher_name) teacher_user.password = make_password(self.teacher_password, self.teacher_salt) teacher_user.email = self.teacher_email teacher_user.save() profile = Profile(user=teacher_user, phone=self.teacher_phone) profile.save() teacher = Teacher(user=teacher_user) teacher.save() teacher_group = Group.objects.get(name="老师") teacher_user.groups.add(teacher_group) teacher_user.save() profile.save() teacher.save() teacher_account = Account(user=teacher_user) teacher_account.save() # 为老师创建能力 grade = Grade.objects.get(name="高三") subject = Subject.objects.get(name="英语") ability = Ability.objects.get(grade=grade, subject=subject) teacher.abilities.add(ability) # 设置面试记录 teacher.status = Teacher.INTERVIEW_OK teacher.status_confirm = True # 设置性别 profile.gender = "f" profile.save() # 设置区域 other_region = Region.objects.get(name="其他") teacher.region = other_region # 设置老师级别 teacher_level = Level.objects.all()[0] teacher.level = teacher_level # 为老师创建对应价格 price = Price(region=other_region, ability=ability, level=teacher_level, price=1, salary=2, commission_percentage=3) price.save() # 设置老师名称 teacher.name = self.teacher_name teacher.save() # 创建家长 parent_user = User.objects.create(username=self.parent_name) parent_user.password = make_password(self.parent_password, self.parent_salt) parent_user.email = self.parent_email parent_user.save() parent_profile = Profile(user=parent_user, phone=self.parent_phone) parent_profile.save() parent_group = Group.objects.get(name="家长") parent_user.groups.add(parent_group) parent_user.save() parent_profile.save() parent = Parent(user=parent_user) parent.save() # 创建订单 school = School(name="逗比中学", address="逗比路", region=Region.objects.get(name="其他"), center=True, longitude=0, latitude=0, opened=False) school.save() school.init_prices() # 为老师添加学校 teacher.schools.add(school) order = Order(parent=parent, teacher=teacher, school=school, grade=Grade.objects.get(name="一年级"), subject=Subject.objects.get(name="数学"), coupon=None, price=200, hours=50, total=100, paid_at=make_aware(datetime.datetime.now()), status=Order.PAID) order.save() # 创建订单里的课程 one_time_slot = TimeSlot( order=order, start=make_aware(datetime.datetime(2016, 1, 1, 8, 0, 0)), end=make_aware(datetime.datetime(2016, 1, 1, 10, 0, 0))) one_time_slot.save() one_time_slot = TimeSlot( order=order, start=make_aware(datetime.datetime(2015, 12, 30, 15, 0, 0)), end=make_aware(datetime.datetime(2015, 12, 30, 17, 0, 0))) one_time_slot.save() one_time_slot = TimeSlot( order=order, start=make_aware(datetime.datetime(2015, 12, 20, 11, 0, 0)), end=make_aware(datetime.datetime(2015, 12, 20, 12, 0, 0))) one_time_slot.save() # 检查订单的数目是否正确 order = Order.objects.get(teacher=teacher) self.assertEqual(3, len(order.timeslot_set.filter(deleted=False)))