Ejemplo n.º 1
0
def update(request, id):
    student = Student.objects.get(id=id)
    form = StudentForm(request.POST, instance=student)
    if form.is_valid():
        form.save()
        return redirect("/show")
    return render(request, 'edit.html', {'student': student})
def save_student(request):
    student = Student.objects.get(pk=1)
    form = StudentForm(request.POST, instance=student)
    form.save()
    args = {}
    args.update(csrf(request))
    args['form'] = form
    return render(request, 'students/student_add.html', args)
Ejemplo n.º 3
0
def store(request):
    if request.method == "POST":
        form = StudentForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except Exception as e:
                pass
    return redirect('/students')
Ejemplo n.º 4
0
 def post(self, request, pk):
     import ipdb;ipdb.set_trace()
     self.object = Group.objects.get(id=pk)
     context = self.get_context_data()
     form = StudentForm(data=request.POST)
     if form.is_valid():
         form.save()
         return self.render_to_response(context)
     context['student_form'] = form
     return self.render_to_response(context)
Ejemplo n.º 5
0
def update_student(request, roll_no=None):
    if roll_no:
        student = Student.objects.get(s_roll = roll_no)
        form = StudentForm(data=request.POST or None, files=request.FILES or None, instance=student)

        if form.is_valid():
            form.save()
            return redirect('/home/')
        

        return render(request, 'students/update.html', {'form': form})
Ejemplo n.º 6
0
def student_edit(request, student_id):
    student = get_object_or_404(Student, pk=student_id)
    if request.method == 'POST':
        form = StudentForm(request.POST, request.FILES, instance=student)
        if form.is_valid():
            form.save()
            return redirect(student.group)
    else:
        form = StudentForm(instance=student)
    c = {'form': form, 'breadcrumbs':
         breadcrumbs('student_edit', student.group)}
    return render(request, 'students/student_manage.html', c)
Ejemplo n.º 7
0
def add_student(request):
    form = StudentForm(request.POST, request.FILES)

    # print(request.POST, request.FILES,  form.is_valid(), form)

    if form.is_valid():
        print(form, 'a')
        form.save()
        return redirect('/home/')
    
    
    return render(request, 'students/student-form.html', {'form': form})
Ejemplo n.º 8
0
def student_add(request, group_id):
    c = {}
    c.update(csrf(request))
    c['title'] = u'Добавление нового студента'
    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/' + group_id)
    else:
        form = StudentForm(initial={'student_group': group_id})
    c['form'] = form
    return render_to_response('form.html', c)
Ejemplo n.º 9
0
def student_edit(request, group_id, student_id):
    c = {}
    c.update(csrf(request))
    c['title'] = u'Редактирование данных студента'
    student = Student.objects.get(id=student_id)
    if request.method == 'POST':
        form = StudentForm(request.POST, instance=student)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/' + group_id)
    else:
        form = StudentForm(instance=student)
    c['form'] = form
    return render_to_response('form.html', c)
Ejemplo n.º 10
0
def new_student(request):
    if request.method == "POST":
        # s = Student.objects.get(id=1)
        f = StudentForm(request.POST)
        # f = StudentForm(request.POST, instance=s)
        if f.is_valid():
            st = f.save(commit=False)  # not saving
            # st = f.save(commit=False) #not savin
            st.save()
            return HttpResponse("Saved")
        return HttpResponse(f.errors)
    elif request.method == "GET":
        f = StudentForm()
        # f = StudentForm(instance=Student.objects.get(id=1))
        context = {"f": f}
        return render(request, "students/new_student.html", context)
Ejemplo n.º 11
0
def student_add(request):
    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            print form.cleaned_data
            student = Student(
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                email=form.cleaned_data['email'],
                phone_number=form.cleaned_data['phone_number'],
                package=form.cleaned_data['package'],
                # courses=form.cleaned_data['courses'], ???????????????????
            )
            student.save()
            return redirect('students_list')
    else:
        form = StudentForm()
    return render(request, 'student_edit.html', {'form': form, 'title': 'Add student'})
Ejemplo n.º 12
0
def create(request):
    form = StudentForm()
    if (request.method == "POST"):
        form = StudentForm(request.POST)
        if (form.is_valid()):
            form.save()
            return redirect('/')

    data = {"form": form}
    return render(request, 'students/create.html', data)
Ejemplo n.º 13
0
def student_cru(request, uuid=None):

    if uuid:
        student = get_object_or_404(Student, uuid=uuid)
        if student.owner != request.user:
            return HttpResponseForbidden()
    else:
        student = Student(owner=request.user)

    if request.POST:
        form = StudentForm(request.POST, instance=student)
        if form.is_valid():
            student = form.save(commit=False)
            student.owner = request.user
            student.save()
            redirect_url = reverse('student_detail', args=(student.uuid, ))
            return HttpResponseRedirect(redirect_url)
    else:
        form = StudentForm(instance=student)

    variables = {'form': form, 'student': student}

    if request.is_ajax():
        template = 'students/student_item_form.html'
    else:
        template = 'students/student_cru.html'

    return render(request, template, variables)
Ejemplo n.º 14
0
def students(request):
    if request.method == "POST":
        form = StudentForm(request.POST)
        newstudent = ""
        if form.is_valid():
            student = Student.objects.filter(teacher=request.user)

            if form.cleaned_data["name"] in student.values_list("name", flat=True):
                newstudent = "Student was already added to roster"
            else:
                form.save()
                form = StudentForm(initial={"teacher": request.user})

                # Get the name of the most recent student instance.
                student = Student.objects.all().order_by("-pk")[0]
                newstudent = str(student.name) + " added to roster"
                newscore = Score(points=0, student_id=student.pk)
                newscore.save()

    else:

        form = StudentForm(initial={"teacher": request.user})
        newstudent = ""

    return render_to_response(
        "student_form.html", {"form": form, "newstudent": newstudent}, context_instance=RequestContext(request)
    )
Ejemplo n.º 15
0
def update(request):

    try:
        GET = request.GET
        name = GET["name"]
        request.session["name"] = name
    except:
        pass

    name = request.session["name"]

    x = Student.objects.get(name=name, teacher=request.user)

    if request.method == "POST":
        form = StudentForm(request.POST, instance=x)
        form.save()
        return HttpResponseRedirect("thanks.html")
    else:

        form = StudentForm(instance=x)

        return render_to_response("update.html", {"form": form}, context_instance=RequestContext(request))
Ejemplo n.º 16
0
def student_edit(request, student_id):
    print locals()
    student = Student.objects.get(id=student_id)
    if request.method == 'POST':
        form = StudentForm(request.POST)
        if form.is_valid():
            student.first_name = form.cleaned_data['first_name']
            student.last_name = form.cleaned_data['last_name']
            student.email = form.cleaned_data['email']
            student.phone_number = form.cleaned_data['phone_number']
            student.courses = form.cleaned_data['courses']
            student.package = form.cleaned_data['package']
            student.save()
            return redirect('students_list')
    else:
        form = StudentForm(initial={'first_name': student.first_name,
                                    'last_name': student.last_name,
                                    'email': student.email,
                                    'phone_number': student.phone_number,
                                    'courses': student.courses.all(),
                                    'package': student.package, })
    return render(request, 'student_edit.html', {'form': form, 'title': 'Edit student'})
Ejemplo n.º 17
0
def update(request, pk):
    student = Student.objects.get(id=pk)
    form = StudentForm(instance=student)

    if (request.method == "POST"):
        form = StudentForm(request.POST, instance=student)
        if (form.is_valid()):
            form.save()
            return redirect('/')

    data = {"student": student, "form": form}
    return render(request, 'students/update.html', data)
Ejemplo n.º 18
0
def stud(request):
    if request.method == "POST":
        form = StudentForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                return redirect('/show')
            except:
                pass
    else:
        form = StudentForm()
    return render(request, 'create.html', {'form': form})
Ejemplo n.º 19
0
def edit_form(request,student_usn):
    student=Student.objects.get(usn=student_usn)
    if request.method == "POST":
        form=StudentForm(request.POST,instance=student)
        if form.is_valid():
            form.save()
            msg_html = render_to_string('email_template.html', {'student': student})
            send_mail('Hostel Management System','hey','*****@*****.**',(student.email,),html_message=msg_html)
            return HttpResponse('<script type="text/javascript">window.close();window.opener.parent.location.reload() ;</script>')
    else:
        form=StudentForm(instance=student)
    return render_to_response('edit_form.html',{"form":form,"student":student},context_instance=RequestContext(request))
Ejemplo n.º 20
0
def online_admission(request):
    if request.method == 'POST':
        form = StudentForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.save()
            return redirect('pages:online_admission_payment', pk=data.pk)
    else:
        form = StudentForm()
    return render(request, 'pages/students/admission.html', {'form': form})
def add_student(request):
    if not request.user.username in request.session:
        return HttpResponseRedirect(reverse('accounts:login'))

    if request.method == "POST":
        form = StudentForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('students:studentlist'))
    else:
        form = StudentForm()
    args = {}
    args.update(csrf(request))
    args['form'] = form
    return render(request, 'students/student_add.html', args)
Ejemplo n.º 22
0
def addstudent(request):
    created = False
    if request.method == "POST":
        student_form = StudentForm(data = request.POST)
        if student_form.is_valid():
            try:
		    student = student_form.save(commit=False)
		    student.save()
		    created = True
		    print "student added"
            except Exception, Arguement:
                    print Exception, Arguement
        else:
            print student_form.errors()
Ejemplo n.º 23
0
    def dispatch(self, request, *args, **kwargs):
        form = StudentForm()

        group_id = kwargs["group_id"]
        group = Group.objects.get(id=group_id)

        if request.method == "POST":
            form = StudentForm(request.POST)

            if form.is_valid():
                form.instance.group = group
                form.save()
                messages.success(request, "Студент успешно создан")
                return redirect("/")
        return render(request, self.template_name, {
            "form": form,
            "group": group
        })
Ejemplo n.º 24
0
def add_Student(request):
    form = StudentForm()
    if request.method == 'POST':
        form = StudentForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            # Step 1 complete. Return student id, etc. Move to success page.
            context_dict = {
                'student_id': form['student_id'].value,
                'first_name': form['first_name'].value,
                'last_name': form['last_name'].value
            }
            return render(request, 'students/add_student_success.html',
                          context_dict)
        else:
            print(form.errors)

    return render(request, 'students/add_student.html', {'form': form})
Ejemplo n.º 25
0
def new_student(request):
    if request.method == "POST":
        # s = Student.objects.get(id=1)
        f = StudentForm(request.POST)
        #f = StudentForm(request.POST, instance=s)
        if f.is_valid():
            st = f.save(commit=False)  #not saving
            #st = f.save(commit=False) #not savin
            st.save()
            return HttpResponse("Saved")
        return HttpResponse(f.errors)
    elif request.method == "GET":
        f = StudentForm()
        #f = StudentForm(instance=Student.objects.get(id=1))
        context = {"f": f}
        return render(request, 'students/new_student.html', context)
Ejemplo n.º 26
0
def add_student_view(request):
    """
    :param request:
    :return: admission form to
    logged in user.
    """
    if request.method == 'POST':
        form = StudentForm(request.POST, request.FILES)
        if form.is_valid():
            student = form.save(commit=False)
            # check student as offline registration
            student.application_type = '2'
            student.save()
            return redirect('students:all_applicants')
    else:
        form = StudentForm()
    context = {'form': form}
    return render(request, 'students/addstudent.html', context)
Ejemplo n.º 27
0
def create(request):
    form = StudentForm()
    return render(request, 'students/add.html', {'form': form})
Ejemplo n.º 28
0
def student_registration(request, *args, **kwargs):
    if not request.user.is_anonymous:
        userEmail = request.user.email
        user = Staff.objects.filter(email=userEmail, isPending=False)
        if user:
            if user[0].isAdmin:
                return redirect('../college-admin/home/')
            else:
                return redirect('../staff/home/')
        else:
            user = Student.objects.filter(email=userEmail, isPending=False)
            if user:
                return redirect('../students/home/')
            else:
                return render(request, "common/no_permission.html")
    if request.method == "POST":
        form = StudentForm(request.POST or None)
        if form.is_valid():
            details = form.cleaned_data
            new_passwd = details['passwd']
            new_username = details['username']
            new_fName = details['firstName']
            new_mName = details['middleName']
            new_lName = details['lastName']
            new_email = details['email']
            new_enrolment = details['enrolment']
            new_dob = details['date']
            new_gender = details['gender']
            new_mobile = details['mobile']
            new_branch = details['branch']
            new_sem = details['sem']
            new_account_id = id_generator()

            try:
                validate_password(new_passwd, form)
            except ValidationError as e:
                form.add_error('passwd', e)
                return render(request, "common/studentregistration.html",
                              {'form': form})

            # try:
            #     user_credentials = [new_username, new_fName, new_lName, new_mName, new_mobile, new_enrolment]
            #     for item in user_credentials:
            #         if item.lower() in new_passwd.lower():
            #             raise ValidationError('Password too similar to credentials...')
            # except ValidationError as e:
            #     form.add_error('passwd', e)
            #     return render(request, "common/studentregistration.html", {'form': form})

            newStudent = Student(firstName=str(new_fName.capitalize()),
                                 middleName=str(new_mName.capitalize()),
                                 lastName=str(new_lName.capitalize()),
                                 username=str(new_username),
                                 passwd=str(new_passwd),
                                 account_id=str(new_account_id),
                                 enrolment=str(new_enrolment),
                                 date=str(new_dob),
                                 mobile=str(new_mobile),
                                 branch=str(new_branch),
                                 sem=str(new_sem),
                                 email=str(new_email.lower()),
                                 gender=str(new_gender),
                                 isPending=True)

            newUser = User.objects.create_user(
                username=str(new_username),
                password=str(new_passwd),
                first_name=str(new_fName.capitalize()),
                last_name=str(new_lName.capitalize()),
                email=str(new_email.lower()),
            )

            newUser.save()
            newStudent.save()
            return redirect("../pending-account")
    else:
        form = StudentForm(request.POST or None)
        for field in form.errors:
            form[field].field.widget.attrs['class'] += 'error'

    return render(request, "common/studentregistration.html", {'form': form})
Ejemplo n.º 29
0
def student_registration(request, *args, **kwargs):
    if request.method == "POST":
        form = StudentForm(request.POST or None)
        if form.is_valid():
            details = form.cleaned_data
            new_passwd = details['passwd']
            new_username = details['username']
            new_fName = details['firstName']
            new_mName = details['middleName']
            new_lName = details['lastName']
            new_email = details['email']
            new_enrolment = details['enrolment']
            new_dob = details['date']
            new_gender = details['gender']
            new_mobile = details['mobile']
            new_branch = details['branch']
            new_sem = details['sem']
            new_account_id = id_generator()

            try:
                validate_password(new_passwd, form)
            except ValidationError as e:
                form.add_error('passwd', e)
                return render(request, "common/studentregistration.html",
                              {'form': form})

            # try:
            #     user_credentials = [new_username, new_fName, new_lName, new_mName, new_mobile, new_enrolment]
            #     for item in user_credentials:
            #         if item.lower() in new_passwd.lower():
            #             raise ValidationError('Password too similar to credentials...')
            # except ValidationError as e:
            #     form.add_error('passwd', e)
            #     return render(request, "common/studentregistration.html", {'form': form})

            newStudent = Student(firstName=str(new_fName.capitalize()),
                                 middleName=str(new_mName.capitalize()),
                                 lastName=str(new_lName.capitalize()),
                                 username=str(new_username),
                                 passwd=str(new_passwd),
                                 account_id=str(new_account_id),
                                 enrolment=str(new_enrolment),
                                 date=str(new_dob),
                                 mobile=str(new_mobile),
                                 branch=str(new_branch),
                                 sem=str(new_sem),
                                 email=str(new_email.lower()),
                                 gender=str(new_gender),
                                 isPending=True)

            # newUser = AppUser(
            #             firstName=str(new_fName.capitalize()),
            #             lastName=str(new_lName.capitalize()),
            #             username=str(new_username),
            #             passwd=str(new_passwd),
            #             email=str(new_email.lower()),
            #             category='Student',
            #             isAdmin=False,
            #             isPending=True
            # )

            newUser = User.objects.create_user(
                username=str(new_username),
                password=str(new_passwd),
                first_name=str(new_fName.capitalize()),
                last_name=str(new_lName.capitalize()),
                email=str(new_email.lower()),
            )

            # newDjangoUser.save()
            newUser.save()
            newStudent.save()
            # Student.objects.create(**form.cleaned_data)
            return redirect("../pending-account")
    else:
        form = StudentForm(request.POST or None)
        for field in form.errors:
            form[field].field.widget.attrs['class'] += 'error'

    return render(request, "common/studentregistration.html", {'form': form})
Ejemplo n.º 30
0
def edit_student(request, student_id=None):
    if request.method == 'POST':
        if student_id is None:
            form = StudentForm(request.POST)
        else:
            edit_student = get_object_or_404(Student, id=student_id)
            form = StudentForm(request.POST, instance=edit_student)
        if form.is_valid():
            form.save()
            return redirect(reverse('students:students_list', args={}))
    else:
        if student_id is None:
            form = StudentForm()
        else:
            student = get_object_or_404(Student, id=student_id)
            form = StudentForm(instance=student)
        return render(request, 'students/edit_student.html', {
            'form': form,
        })