Ejemplo n.º 1
0
def newstudent(request, idshift):
    if (
            len(request.user.teacher_set.all()) > 0
    ):  # if an authenticated user "accidentally" access this section, he doesn't get an exception
        if (request.method == 'POST'):
            form = StudentForm(request.POST)
            if (form.is_valid()):
                user = User()
                user.username = form.data['uid']
                user.set_password(form.data['passwd'])
                user.email = form.data['email']
                user.first_name = form.data['first_name']
                user.last_name = form.data['last_name']
                user.save()
                form.instance.user = user
                form.save()

                mail = Mail()
                mail.save_mail(
                    SUBJECTMAILCREATE,
                    BODYMAILCREATE % (user.username, form.data['passwd']),
                    user.email)
                return HttpResponseRedirect(PATHOK % str(idshift))
        else:
            form = StudentForm(initial={'shifts': [idshift]})
        return render(request,
                      'student/new-student.html', {
                          'form': form,
                          'idshift': idshift
                      },
                      context_instance=RequestContext(request))
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Ejemplo n.º 2
0
def edit_unenrolled_student(request, idstudent):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        student = Student.objects.get(pk=idstudent)     
        if (request.method == 'POST'):
            form = StudentForm(request.POST, instance=student)
            if (form.is_valid()):
                form.save()
                return HttpResponseRedirect(PATHOKENROLED)
        else:
            form = StudentForm(instance=student)
        return render(request, 'student/editstudent.html', {'form': form}, context_instance=RequestContext(request))
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Ejemplo n.º 3
0
def edit_unenrolled_student(request, idstudent):
    if (
            len(request.user.teacher_set.all()) > 0
    ):  # if an authenticated user "accidentally" access this section, he doesn't get an exception
        student = Student.objects.get(pk=idstudent)
        if (request.method == 'POST'):
            form = StudentForm(request.POST, instance=student)
            if (form.is_valid()):
                form.save()
                return HttpResponseRedirect(PATHOKENROLED)
        else:
            form = StudentForm(instance=student)
        return render(request,
                      'student/editstudent.html', {'form': form},
                      context_instance=RequestContext(request))
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Ejemplo n.º 4
0
def editstudent(request, idshift, idstudent):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        student = Student.objects.get(pk=idstudent)     
        if (request.method == 'POST'):
            form = StudentForm(request.POST, instance=student,
                               initial={'email': student.user.email, 'first_name': student.user.first_name, 'last_name': student.user.last_name})
            
            if (form.is_valid()):
                if (form.data['passwd'] != ''):
                    student.user.set_password(form.data['passwd'])
                student.user.email = form.data['email']
                student.user.first_name = form.data['first_name']
                student.user.last_name = form.data['last_name']
                student.user.save()
                form.save()
                return HttpResponseRedirect(PATHOK % str(idshift))
        else:
            form = StudentForm(instance=student, initial={'email': student.user.email, 'first_name': student.user.first_name, 'last_name': student.user.last_name})
        return render(request, 'student/editstudent.html', {'form': form, 'idshift': idshift}, context_instance=RequestContext(request))
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Ejemplo n.º 5
0
def editstudent(request, idshift, idstudent):
    if (
            len(request.user.teacher_set.all()) > 0
    ):  # if an authenticated user "accidentally" access this section, he doesn't get an exception
        student = Student.objects.get(pk=idstudent)
        if (request.method == 'POST'):
            form = StudentForm(request.POST,
                               instance=student,
                               initial={
                                   'email': student.user.email,
                                   'first_name': student.user.first_name,
                                   'last_name': student.user.last_name
                               })

            if (form.is_valid()):
                if (form.data['passwd'] != ''):
                    student.user.set_password(form.data['passwd'])
                student.user.email = form.data['email']
                student.user.first_name = form.data['first_name']
                student.user.last_name = form.data['last_name']
                student.user.save()
                form.save()
                return HttpResponseRedirect(PATHOK % str(idshift))
        else:
            form = StudentForm(instance=student,
                               initial={
                                   'email': student.user.email,
                                   'first_name': student.user.first_name,
                                   'last_name': student.user.last_name
                               })
        return render(request,
                      'student/editstudent.html', {
                          'form': form,
                          'idshift': idshift
                      },
                      context_instance=RequestContext(request))
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Ejemplo n.º 6
0
def newstudent(request, idshift):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        if (request.method == 'POST'):
            form = StudentForm(request.POST)
            if (form.is_valid()):
                user = User()
                user.username = form.data['uid']
                user.set_password(form.data['passwd'])
                user.email = form.data['email']
                user.first_name = form.data['first_name']
                user.last_name = form.data['last_name']
                user.save()
                form.instance.user = user
                form.save()
                
                mail = Mail()
                mail.save_mail(SUBJECTMAILCREATE, BODYMAILCREATE % (user.username, form.data['passwd']), user.email)
                return HttpResponseRedirect(PATHOK % str(idshift))
        else:
            form = StudentForm(initial={'shifts': [idshift]})
        return render(request, 'student/new-student.html', {'form': form, 'idshift': idshift}, context_instance=RequestContext(request))
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE