Ejemplo n.º 1
0
def new_prof(request):
    #Prevent unidentified user from accessing any part of the site
    student = get_student(request)
    if student == None:
        return HttpResponseRedirect('/')

    try:
        student = Student.objects.get(netid=request.user.username)
    except Student.DoesNotExist:
        student = None

    if request.method == 'POST':
        profForm = ProfessorForm(request.POST)
        if profForm.is_valid():
            temp_post = profForm.save(commit=False)
            temp_post.user = request.user
            temp_post.save()
            return HttpResponseRedirect('/account/')
    else:
        profForm = ProfessorForm()

    form = StudentForm()

    context = {'form':form, 'profForm':profForm}
    return render(request, 'student.html', context)
Ejemplo n.º 2
0
def student(request):
    #Prevent unidentified user from accessing any part of the site
    isProfessor = True
    try:
        student = Student.objects.get(netid=request.user.username)
    except Student.DoesNotExist:
	    student = None
    research_areas = get_research_areas(get_department(student))
	
    try:
        prof = Professor.objects.get(netid=request.user.username)
    except Professor.DoesNotExist:
	    isProfessor = False
		
    if isProfessor:
        return HttpResponseRedirect('/profile/'+str(request.user.username))
    if student == None:
        return HttpResponseRedirect('/')
    formInvalid = False
    if request.method == 'POST':
        form = StudentForm(request.POST)
        profForm = ProfessorForm(request.POST)
        eForm = EditStudentForm(request.POST, instance=student)
        if 'student' in request.POST:
            if form.is_valid():
                temp_post = form.save(commit=False)
                temp_post.user = request.user
                temp_post.save()
                form.save_m2m()
                return HttpResponseRedirect('/account/')
        elif 'professor' in request.POST:
            if profForm.is_valid():
                temp_post = profForm.save(commit=False)
                temp_post.user = request.user
                temp_post.save()
                profForm.save_m2m()
                me = Professor.objects.get(netid=request.user.username)
                return HttpResponseRedirect('/profile/' + str(me.id))
        elif 'edit' in request.POST:
            if eForm.is_valid():
                eForm.save()
                return HttpResponseRedirect('/account/')
            else:
                formInvalid = True
    else:
        form = StudentForm()
        profForm = ProfessorForm()
        eForm = EditStudentForm(instance=student)
    context = {'research_areas': research_areas,
              'form': form, 'profForm': profForm, 'eForm': eForm, 'student': student, 'formInvalid': formInvalid}
    return render(request, 'student.html', context)