def add_participant(request, host_id): host_id = host_id username = request.user.get_username() if request.method == "POST": form = ParticipantForm(request.POST) if form.is_valid(): School_Name = form.cleaned_data.get("School_Name") School_Phone_no = form.cleaned_data.get("School_Phone_no") School_Email_address = form.cleaned_data.get( "School_Email_address") School_Address = form.cleaned_data.get("School_Address") State = form.cleaned_data.get("State") Student_Name_1 = form.cleaned_data.get("Student_Name_1") Contact_no = form.cleaned_data.get("Contact_no ") Email_address = form.cleaned_data.get("Email_address") House_Address = form.cleaned_data.get("House_Address") Gender = form.cleaned_data.get("Gender") Student_Name_2 = form.cleaned_data.get("Student_Name_2") Contact_no_2 = form.cleaned_data.get("Contact_no_2") Email_address_2 = form.cleaned_data.get("Email_address_2") House_Address_2 = form.cleaned_data.get("House_Address_2") Gender_2 = form.cleaned_data.get("Gender_2") Title_of_your_project = form.cleaned_data.get( "Title_of_your_project") Question_or_Problem = form.cleaned_data.get("Question_or_Problem") Hypothesis_or_possible_solution = form.cleaned_data.get( "Hypothesis_or_possible_solution") Materials_needed = form.cleaned_data.get("House_Address") Results = form.cleaned_data.get("Results") Image_of_Project = form.cleaned_data.get("Image_of_Project") Link_of_your_project = form.cleaned_data.get( "Link_of_your_project") Participant.objects.create( username=username, School_Name=School_Name, School_Phone_no=School_Phone_no, School_Email_address=School_Email_address, School_Address=School_Address, State=State, Student_Name_1=Student_Name_1, Contact_no_1=Contact_no, Email_address_1=Email_address, House_Address_1=House_Address, Gender_1=Gender, Student_Name_2=Student_Name_2, Contact_no_2=Contact_no_2, Email_address_2=Email_address_2, House_Address_2=House_Address_2, Gender_2=Gender_2, Title_of_your_project=Title_of_your_project, Question_or_Problem=Question_or_Problem, Hypothesis_or_possible_solution=Hypothesis_or_possible_solution, Materials_needed=Materials_needed, Results=Results, Image_of_Project=Image_of_Project, Link_of_your_project=Link_of_your_project, host_id=host_id, ) return redirect("projects")
def new(request, lang): if request.method == 'POST': participant_form = ParticipantForm(request.POST) if participant_form.is_valid(): participant = participant_form.save(commit=False) participant.ip = get_client_ip(request), participant.ua = get_client_ua(request), participant.save() sequences = Sequence.objects.all() pairs = Pair.objects.all() if len(sequences) > len(pairs): generate_pairs(len(sequences) - len(pairs) + 1) pairs = Pair.objects.all() send_email(template='email/pairs_empty.html') pairs = pairs[:len(sequences)] for sequence, pair in zip(sequences, pairs): question = Question(participant=participant, left=pair.left, right=pair.right, sequence=sequence, answered=False) question.save() pair.delete() request.session['participant_id'] = participant.id #messages.add_message(request, messages.SUCCESS, u'Новый участник создан') return redirect(reverse('core.views.index', kwargs={'lang': lang})) #messages.add_message(request, messages.ERROR, u'Не удалось создать участника') return redirect(reverse('core.views.index', kwargs={'lang': lang}))
def participant(request, host_id): host_id = host_id template_name = "core/participant.html" form = ParticipantForm() context = {"form": form, "host_id": host_id} return render(request, template_name, context=context)
def new(request, lang): if request.method == 'POST': participant_form = ParticipantForm(request.POST) if participant_form.is_valid(): participant = participant_form.save(commit=False) participant.ip = get_client_ip(request), participant.ua = get_client_ua(request), participant.save() sequences = Sequence.objects.all() pairs = Pair.objects.all() if len(sequences) > len(pairs): generate_pairs(len(sequences) - len(pairs) + 1) pairs = Pair.objects.all() send_email(template='email/pairs_empty.html') pairs = pairs[:len(sequences)] for sequence, pair in zip(sequences, pairs): question = Question( participant=participant, left=pair.left, right=pair.right, sequence=sequence, answered=False ) question.save() pair.delete() request.session['participant_id'] = participant.id #messages.add_message(request, messages.SUCCESS, u'Новый участник создан') return redirect(reverse('core.views.index', kwargs={'lang': lang})) #messages.add_message(request, messages.ERROR, u'Не удалось создать участника') return redirect(reverse('core.views.index', kwargs={'lang': lang}))
def index(request, lang): template_name = 'core/{}/index.html'.format(lang if lang else 'ru') participant_id = request.session.get('participant_id') participant = get_or_none(Participant, pk=participant_id) participant_form = ParticipantForm() questions = Question.objects.filter(participant=participant, answered=False) forms = [] for question in questions: forms.append({ 'question': question, 'answer_left_form': AnswerForm(initial={ 'best': question.left, 'question': question }), 'answer_right_form': AnswerForm(initial={ 'best': question.right, 'question': question }), 'answer_none_form': AnswerForm(initial={ 'best': None, 'question': question }), }) return render( request, template_name, { 'video_path': settings.VIDEO_CORE_PATH, 'participant': participant, 'questions': questions, 'participant_form': participant_form, 'forms': forms, 'lang': lang, })