示例#1
0
文件: views.py 项目: k-jin/ct-stem
def student_register(request):
    if request.method == 'POST':
        form = StudentRegistrationForm(request.POST)
        if form.is_valid():
            in_data = form.cleaned_data

            if ( not Student.objects.filter(student_id=in_data['student_id'], school=in_data['school'])):
                #create student!
                student = Student(
                    student_id=in_data['student_id'],
                    first_name=in_data['first_name'],
                    last_name=in_data['last_name'],
                    grade=in_data['grade'],
                    sex=in_data['sex'],
                    dob=in_data['date_of_birth'],
                    school=in_data['school'],
                    email=in_data['email'],
                    ethnicity=in_data['ethnicity'])

                student.save()
            else:
                student = Student.objects.get(student_id=in_data['student_id'], school=in_data['school'])

            section = Section.objects.get(id=in_data['section_id'])
            assessmevent = AssessEvent (
                student = student,
                section = section,
                date = datetime.datetime.now(),
                location = in_data['location'],
                assessment_set = in_data['assessment_set']
                )
            assessmevent.save()
            return render(request, 'sets/' + ASSESSMENTS[assessmevent.assessment_set].url, {'assessment': ASSESSMENTS[assessmevent.assessment_set], 'assessmevent': assessmevent})
        else:
            return render(request, 'student_registration.html', {'form': form})
示例#2
0
文件: views.py 项目: k-jin/ct-stem
def guest_register(request):
    if request.method == 'POST':
        form = GuestRegistrationForm(request.POST)
        if form.is_valid():
            in_data = form.cleaned_data

            # for guests - make the email address the natural key (to keep for getting guest dups)
            #   yes this conditional is goofy, but it needs to be due to falsy-ness of strings and filter method
            if ( not in_data['email'] or not Student.objects.filter(email=in_data['email'], student_id='GUEST')):
                student = Student(
                        student_id='GUEST',
                        first_name=in_data['first_name'],
                        last_name=in_data['last_name'],
                        grade='0',
                        sex='-',
                        dob=datetime.date.today(),
                        school=in_data['school'],
                        email=in_data['email'],
                        ethnicity=in_data['ethnicity'])
            else:
                student = Student.objects.get(email=in_data['email'], student_id='GUEST')

            student.save()

            section = Section.objects.get(name='Guest Section')

            assessmevent = AssessEvent (
                student = student,
                section = section,
                date = datetime.datetime.now(),
                location = 'guest',
                assessment_set = in_data['assessment_set']
                )

            assessmevent.save()
            return render(request, 'sets/' + ASSESSMENTS[assessmevent.assessment_set].url, {'assessment': ASSESSMENTS[assessmevent.assessment_set], 'assessmevent': assessmevent})
        else:
            return render(request, 'guest_registration.html', {'form': form, 'assessments': sorted(ASSESSMENTS.values(), cmp=lambda x,y: cmp(x.name, y.name))})

    return render(request, 'guest_registration.html', {'form': GuestRegistrationForm(), 'assessments': sorted(ASSESSMENTS.values(), cmp=lambda x,y: cmp(x.name, y.name))})