Ejemplo n.º 1
0
def add_student_save(request):
    if request.method != "POST":
        return HttpResponse("Method Not Allowed")
    else:
        form = AddStudentForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            address = form.cleaned_data["address"]
            session_year_id = form.cleaned_data["session_year_id"]
            course_id = form.cleaned_data["course"]
            sex = form.cleaned_data["sex"]
            dob = form.cleaned_data["dob"]
            mobile = form.cleaned_data["mobile"]
            aaddhar = form.cleaned_data["aaddhar"]

            try:
                user = CustomUser.objects.create_user(username=username,
                                                      password=password,
                                                      email=email,
                                                      last_name=last_name,
                                                      first_name=first_name,
                                                      user_type=3)
                user.students.address = address
                course_obj = Courses.objects.get(id=course_id)
                user.students.course_id = course_obj
                session_year = SessionYearModel.object.get(id=session_year_id)
                user.students.session_year_id = session_year
                user.students.gender = sex
                user.students.mobile = mobile
                user.students.dob = dob
                user.students.aaddhar = aaddhar
                user.save()
                send_mail(
                    'Registration ',
                    "this is your oassword :" + password,
                    settings.EMAIL_HOST_USER,
                    [email],
                    fail_silently=False,
                )
                messages.success(request, "Successfully Added Student")
                return HttpResponseRedirect(reverse("add_student"))
            except Exception as e:
                messages.error(request, "Failed to Add Student {}".format(e))
                return HttpResponseRedirect(reverse("add_student"))
        else:
            form = AddStudentForm(request.POST)
            return render(request, "hod_template/add_student_template.html",
                          {"form": form})
Ejemplo n.º 2
0
def add_student_save(request):
    if request.method != "POST":
        return HttpResponse("<h2>Method Not allowed</h2>")
    else:
        form = AddStudentForm(request.POST, request.FILES)
        if form.is_valid():
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            address = form.cleaned_data["address"]
            session_year_id = form.cleaned_data["session_year_id"]

            course_id = form.cleaned_data["course"]
            gender = form.cleaned_data["gender"]

            # profile_pic = request.FILES['profile_pic']
            # fs=FileSystemStorage()
            # filename=fs.save(profile_pic.name,profile_pic)
            # profile_pic_url=fs.url(filename)

            # try:
            user = CustomUser.objects.create_user(username=username,
                                                  password=password,
                                                  email=email,
                                                  last_name=last_name,
                                                  first_name=first_name,
                                                  user_type=3)
            user.students.address = address
            course_obj = Courses.objects.get(id=course_id)
            user.students.course_id = course_obj
            session_year = SessionYearModel.objects.get(id=session_year_id)
            user.students.session_year_id = session_year
            user.students.gender = gender
            user.students.profile_pic = " "
            user.save()
            messages.success(request, "Suceessufly added student")
            return HttpResponseRedirect(reverse("add_student"))

            # except:
            #     messages.error(request, "Failed to add student")
            #     return HttpResponseRedirect(reverse("add_student"))
        else:
            form = AddStudentForm(request.POST)
            return render(request, "hod_template/add_student_template.html",
                          {"form": form})
Ejemplo n.º 3
0
def add_student_save(request):
    if request.method != "POST":
        return HttpResponse("Method Not Allowed")
    else:

        form = AddStudentForm(request.POST, request.FILES)
        if form.is_valid():
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            address = form.cleaned_data["address"]
            session_year_id = form.cleaned_data["session_year_id"]
            course_id = form.cleaned_data["course"]
            sex = form.cleaned_data["sex"]

            profile_pic = request.FILES['profile_pic']
            fs = FileSystemStorage()
            filename = fs.save(profile_pic.name, profile_pic)
            profile_pic_url = fs.url(filename)

            try:
                user = CustomUser.objects.create_user(username=username,
                                                      password=password,
                                                      email=email,
                                                      last_name=last_name,
                                                      first_name=first_name,
                                                      user_type=3)
                user.student.address = address
                course_obj = Course.objects.get(id=course_id)
                user.student.course_id = course_obj
                session_year = SessionYearModel.object.get(id=session_year_id)
                print(session_year)
                user.student.session_year_id = session_year
                user.student.gender = sex
                user.student.profile_pic = profile_pic_url
                user.save()
                messages.success(request, "Successfully Added Student")
                return HttpResponseRedirect(reverse("add_student"))
            except:
                messages.error(request, "Failed to Add Student")
                return HttpResponseRedirect(reverse("add_student"))
        else:
            form = AddStudentForm()
            return render(request, "hod_template/add_student.html",
                          {"form": form})
Ejemplo n.º 4
0
def add_student_save(request):
    if request.method != "POST":
        return HttpResponse("method not allowed")
    else:
        form = AddStudentForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            address = form.cleaned_data["address"]
            session_year_id = form.cleaned_data["session_year_id"]
            course_id = form.cleaned_data["course"]
            sex = form.cleaned_data["sex"]

            #try:
            user = CustomUser.objects.create_user(username=username,
                                                  password=password,
                                                  email=email,
                                                  first_name=first_name,
                                                  last_name=last_name,
                                                  user_type=3)
            user.students.address = address

            course_obj = Courses.objects.get(id=course_id)
            user.students.course_id = course_obj

            session_year = SessionYearModel.objects.get(id=session_year_id)
            user.students.session_year_id = session_year
            user.students.gender = sex
            user.students.profile_pic = ""
            user.save()
            messages.success(request, "Successfully Added Student")
            return HttpResponseRedirect(reverse("add_student"))
            #except:
            # messages.error(request,"Failed to Add Student")
            # return HttpResponseRedirect(reverse("add_student"))
        else:
            form = AddStudentForm(request.POST)
            return render(request, "hod_template/add_student_template.html",
                          {"form": form})