Exemplo n.º 1
0
def signup_teacher(request):

    teacher_form = TeacherForm(request.POST or None)
    user_form = UserForm(request.POST or None)

    if request.method == "POST":
        if teacher_form.is_valid() and user_form.is_valid():
            user = user_form.save()
            teacher = teacher_form.save(commit=False)
            teacher.user = user
            teacher.save()
            return redirect("index")

    return render(request, "signup_teacher.html", {"form": user_form, "teacher_form": teacher_form})
Exemplo n.º 2
0
def edit(request):
    teacher = is_teacher(request.user)

    if teacher:
        custom_form = TeacherForm(request.POST or None, instance=Teacher.objects.get(user=request.user))
    else:
        custom_form = StudentForm(request.POST or None, instance=Student.objects.get(user=request.user))

    user_form = EditUserForm(request.POST or None, instance=request.user)

    if request.method == "POST":
        if custom_form.is_valid() and user_form.is_valid():
            user = user_form.save()
            custom_form.save()
            messages.success(request, "Configurações editadas com sucesso")

    return render(request, "accounts/edit.html", {"form": user_form, "custom_form": custom_form, "is_teacher": teacher})
Exemplo n.º 3
0
def signup_teacher(request):

    teacher_form = TeacherForm(request.POST or None)
    user_form = UserForm(request.POST or None)

    if request.method == 'POST':
        if teacher_form.is_valid() and user_form.is_valid():
            user = user_form.save()
            teacher = teacher_form.save(commit=False)
            teacher.user = user
            teacher.save()
            return redirect('index')

    return render(request, 'signup_teacher.html', {
        'form': user_form,
        'teacher_form': teacher_form
    })
Exemplo n.º 4
0
def edit(request):
    teacher = is_teacher(request.user)

    if teacher:
        custom_form = TeacherForm(
            request.POST or None,
            instance=Teacher.objects.get(user=request.user))
    else:
        custom_form = StudentForm(
            request.POST or None,
            instance=Student.objects.get(user=request.user))

    user_form = EditUserForm(request.POST or None, instance=request.user)

    if request.method == 'POST':
        if custom_form.is_valid() and user_form.is_valid():
            user = user_form.save()
            custom_form.save()
            messages.success(request, 'Configurações editadas com sucesso')

    return render(request, 'accounts/edit.html', {
        'form': user_form,
        'custom_form': custom_form,
        'is_teacher': teacher
    })
Exemplo n.º 5
0
    def post(self, request):
        form = TeacherForm(request.POST)
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        date_of_birth = request.POST.get('date_of_birth')
        qualifications = request.POST.get('qualifications')
        email_address = request.POST.get('email_address')
        phone_number = request.POST.get('phone_number')
        facebook = request.POST.get('facebook')

        subject = 'New Teacher Applied'
        message = ('Teacher Application....' + first_name + '\n' + last_name +
                   '\n' + email_address + '\n' + phone_number + '\n' +
                   qualifications)
        from_email = settings.EMAIL_HOST_USER
        to_email = [from_email, '*****@*****.**']
        send_mail(subject, message, from_email, to_email, fail_silently=False)

        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            date_of_birth = form.cleaned_data['date_of_birth']
            qualifications = form.cleaned_data['qualifications']
            email_address = form.cleaned_data['email_address']
            phone_number = form.cleaned_data['phone_number']
            facebook = form.cleaned_data['facebook']

        args = {
            'form': form,
            'first_name': first_name,
            'last_name': last_name,
            'date_of_birth': date_of_birth,
            'qualifications': qualifications,
            'email_address': email_address,
            'phone_number': phone_number,
            'facebook': facebook
        }
        return TemplateResponse(request, self.template_name, args)
Exemplo n.º 6
0
 def get(self, request):
     form = TeacherForm()
     return render(request, self.template_name, {'form': form})