Ejemplo n.º 1
0
def new_studentform(request):
    print(request.META)
    user_form=GenericCreationForm()
    profileinlineformset= inlineformset_factory(User,studentprofile,fields=('image','mobile_number','parents_number','department','semester','dob','address','roll_no','batch','Class','subject'),widgets={'subject':f.CheckboxSelectMultiple(attrs={'class':'checkbox'})})             
    formset=profileinlineformset()
    
    if request.method=='POST':
        user_form=GenericCreationForm(request.POST)
        formset=profileinlineformset(request.POST)
        
        if user_form.is_valid():
            created_user=user_form.save(commit=False)
            created_user.is_student=True
            created_user.is_active=False
            formset = profileinlineformset(request.POST,request.FILES,instance=created_user)
            
            if formset.is_valid():
            
                created_user.save()
                formset.save()
            
                errors=[err(e="Please Reach to Admin and Register Your ID.",link=" "),err(e="Your Account is InActive It will be activated by admin.",link=" ")]
                return render(request,'error.html',{'errors':errors})

    return render(request,'student/signup.html',{"user_form":user_form,"formset":formset,})
def new_teacherform(request):

    user_form = GenericCreationForm()
    profileinlineformset = inlineformset_factory(
        User,
        teacherprofile,
        fields=('image', 'class_TG', 'start_student_rollno',
                'last_student_rollno', 'mobile_number', 'department',
                'address', 'years_of_experience', 'education', 'subject',
                'dob', 'last_lecture'),
        widgets={
            'subject': form.CheckboxSelectMultiple(attrs={'class': 'checkbox'})
        })
    formset = profileinlineformset()
    formset.forms[0].fields['last_lecture'].widget.attrs.update(
        {'class': 'datetime'})

    formset.forms[0].fields['dob'].widget.attrs.update({'class': 'date'})
    if request.method == 'POST':
        user_form = GenericCreationForm(request.POST, request.FILES)
        formset = profileinlineformset(request.POST, request.FILES)

        if user_form.is_valid():
            created_user = user_form.save(commit=False)
            created_user.is_teacher = True
            created_user.is_active = False
            formset = profileinlineformset(request.POST,
                                           request.FILES,
                                           instance=created_user)

            if formset.is_valid():
                #fs=FileSystemStorage()
                #filename=fs.save(request.FILES["image"].name,request.FILES["image"])
                created_user.save()
                formset.save()
                #user=authenticate(username=created_user.username,password=created_user.password)
                #if user is not None:
                #    login(request,user)
                #    return redirect('dashboard',pk=user.pk)

                errors = [
                    err(e="Please Reach to Admin and Register Your ID.",
                        link=" "),
                    err(e=
                        "Your Account is InActive It will be activated by admin.",
                        link=" ")
                ]
                return render(request, 'error.html', {'errors': errors})

    return render(request, 'teacher/signup.html', {
        "pk": None,
        "user_form": user_form,
        "formset": formset,
    })