def post(self, request): name = request.POST.get("name") class_time = request.POST.get("class_time") teacher_name = request.POST.get("teacher_name") description = request.POST.get("description") if not name or not class_time or not teacher_name or not description: return render(request, 'app/lesson_add.html', {'error': 'wrong input'}) else: LessonModel.objects.create( name=name, class_time=DateUtil.str_to_datetime(class_time), teacher_name=teacher_name, description=description) return HttpResponseRedirect(reverse('lesson-list'))
def post(self, request): lesson_id = request.GET.get("id") lesson = LessonModel.objects.get(id=lesson_id) name = request.POST.get("name") class_time = request.POST.get("class_time") teacher_name = request.POST.get("teacher_name") description = request.POST.get("description") if not name or not class_time or not teacher_name or not description: return render(request, 'app/lesson_add.html', {'error': 'Wrong input '}) else: lesson.name = name lesson.teacher_name = teacher_name lesson.class_time = DateUtil.str_to_datetime(class_time) lesson.description = description lesson.save() return HttpResponseRedirect(reverse('lesson-list'))
def test_str_to_datetime3(self): str_datetime = "2019-10-10 8:1" datetime_obj = DateUtil.str_to_datetime(str_datetime) assert datetime_obj == datetime.strptime(str_datetime, '%Y-%m-%d %H:%M')
def test_str_to_datetime2(self): str_datetime = "2019-01-03 08:01" datetime_obj = DateUtil.str_to_datetime(str_datetime) assert datetime_obj == datetime.strptime(str_datetime, '%Y-%m-%d %H:%M')