def student_registration(request, by_student=False): message = '' user_message = None form = StudentRegisterForm(request.POST or None) if form.is_valid(): form.save() if by_student: form = None user_message = 'Спасибо за регистрацию. Наш администратор свяжется с Вами в ближайшее время.' else: form = StudentRegisterForm() message = 'Ученик успешно добавлен' return { 'form': form, 'message': message, 'user_message': user_message, 'hours': get_generic_hour_range(), 'days': DAYS_OF_THE_WEEK, }
def edit_student(request, id): #insert code to protect from admins editing wrong students message = '' student = Student.objects.get(pk=id) if request.method == 'POST': form = StudentRegisterForm(request.POST, instance=student) if form.is_valid(): form.save() message = 'Данные сохранены' else: form_initial_data = { 'name': student.name, 'last_name': student.last_name, 'middle_name': student.middle_name, 'phone': student.phone, 'parents_phone': student.parents_phone, 'email': student.email, 'birthday': student.birthday, 'passport_number': student.passport_number, 'passport_authority': student.passport_authority, 'passport_issued_date': student.passport_issued_date, 'passport_unit': student.passport_unit, 'level': student.level, 'subjects': student.subjects.all(), 'offices': student.offices.all(), 'olympiad_participation_plans': student.olympiad_participation_plans, 'foreign_trip_plans': student.foreign_trip_plans, 'registration_date': student.registration_date } form = StudentRegisterForm(initial=form_initial_data) return { 'form': form, 'hours': get_generic_hour_range(), 'days': DAYS_OF_THE_WEEK, 'time': json.dumps(student.free_time), 'student_id': id, 'message': message, }