Ejemplo n.º 1
0
def register_student(request):
    user_group = check_user_group(request)
    if not request.user.is_authenticated() or user_group == 'Not specified':
        if request.method == "POST":
            form = UserRegistrationForm(data=request.POST)
            if form.is_valid():
                form.save()
                u = User.objects.get(username=request.POST.get('username'))
                gid = Group.objects.get(name='Student')
                u.groups.add(gid.id)
                s = Student(user = u)
                s.save()
                return HttpResponseRedirect('/students/')
            else:
                return render_to_response('tuition/student_register.html', {'user_group': user_group,'form': form,
                    'do_not_show_nav': 1, 'current_student': "current"}, context_instance = RequestContext(request))
        else:	
            form = UserRegistrationForm()
            return render_to_response('tuition/student_register.html', {'user_group': user_group,'form': form,
                    'do_not_show_nav': 1, 'current_student': "current"}, context_instance = RequestContext(request))
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 2
0
def register_tutor(request):
    user_group = check_user_group(request)
    authentic = False
    success = False
    tform = ""
    uform = ""
    if not request.user.is_authenticated() or user_group == 'Not specified':
        authentic = True

        if request.method == "POST":

            uform = UserRegistrationForm(request.POST)
            if uform.is_valid():
                success = True
                user = uform.save()
                tutor = Tutor(user=user)
                tform = TutorForm(request.POST, instance = tutor)

                if tform.is_valid():
                    tutor = tform.save(commit = False)
                    tutor.sex = tform.cleaned_data['sex']
                    tutor.cgpa = tform.cleaned_data['cgpa']
                    tutor.proficient_areas = tform.cleaned_data['proficient_areas']
                    tutor.fees_per_hour = tform.cleaned_data['fees_per_hour']
                    tutor.experience = tform.cleaned_data['experience']
                    tutor.save()
                    tutor.race = tform.cleaned_data['race']
                    tutor.year = tform.cleaned_data['year']
                    tutor.school = tform.cleaned_data['school']
                    tutor.subject = tform.cleaned_data['subject']
                    tutor.days = tform.cleaned_data['days']
                    tutor.time_slots = tform.cleaned_data['time_slots']
                    gid = Group.objects.get(name='Tutor')
                    user.groups.add(gid.id)
                    tutor.save()

        else:
            uform = UserRegistrationForm()
            tform = TutorForm()

    return render_to_response('tuition/tutor_register.html', {'authentic':authentic, 'success': success, 'uform': uform, 'tform': tform, 'user_group': user_group,
                        'do_not_show_nav': 1, 'current_tutor': "current"}, context_instance = RequestContext(request))