Exemplo n.º 1
0
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})
Exemplo n.º 2
0
def student_status(request):
    errors = []
    if 'student_id' not in request.POST or not request.POST['student_id']:
        errors.append('Please enter your student ID.')
    if 'school' not in request.POST or not request.POST['school']:
        errors.append('Please select your school.')
    if 'teacher' not in request.POST or not request.POST['teacher']:
        errors.append('Please select your teacher.')
    if 'section' not in request.POST or not request.POST['section']:
        errors.append('Please select your current section.')
    if 'assessment_set' not in request.POST or not request.POST['assessment_set']: 
        errors.append('Please select the assessment set you want to take.')
    if 'location' not in request.POST or not request.POST['location']: 
        errors.append('Please specifcy your current location.')

    ua = request.META.get('HTTP_USER_AGENT', '').lower()
    is_ipad = ua.find("ipad") > 0

    if errors:
        #TODO: figure out how to reuse the student_login method
        schools = Teacher.objects.values('school').distinct()
        teachers = Teacher.objects.all().order_by("last_name")
        return render(request, 'student_login.html', {'schools':schools, 'teachers':teachers, 'errors':errors, 'assessments': sorted(ASSESSMENTS.values(), cmp=lambda x,y: cmp(x.name, y.name)), 'is_ipad': is_ipad})

    try:
        student_id = request.POST['student_id']
        section = Section.objects.get(id=request.POST['section'])
        student = Student.objects.get(student_id=student_id, school=section.teacher.school)        

        assessmevent = AssessEvent (
            student = student,
            section = section,
            date = datetime.datetime.now(),
            location = request.POST['location'],
            assessment_set = request.POST['assessment_set']
            )
        assessmevent.save()

        return render(request, 'sets/' + ASSESSMENTS[assessmevent.assessment_set].url, {'assessment': ASSESSMENTS[assessmevent.assessment_set], 'assessmevent': assessmevent})

    except Student.DoesNotExist:
        registration_form = StudentRegistrationForm(
            initial={'student_id' : student_id, 'school' : section.teacher.school, 'section_id' : section.id, 'assessment_set': request.POST['assessment_set'], 'location' : request.POST['location']}
            )
        return render(request, 'student_registration.html', {'form': registration_form, 'section': section})
    except Exception as e:
        errors.append("An error occured, please verify your information and try again.")
        schools = Teacher.objects.values("school").distinct().order_by("school")
        return render(request, 'student_login.html', {'errors': errors, 'e':e, 'schools':schools, 'assessments': sorted(ASSESSMENTS.values(), cmp=lambda x,y: cmp(x.name, y.name)), 'is_ipad': is_ipad})
Exemplo n.º 3
0
def continuation_assessment(request):
    if request.method == 'POST':
        old_assessmevent_id = request.POST['assessmevent_id']
        old_assessmevent = AssessEvent.objects.get(id=old_assessmevent_id)

        new_assessmevent = AssessEvent (
                student = old_assessmevent.student,
                section = old_assessmevent.section,
                date = datetime.datetime.now(),
                location = old_assessmevent.location,
                assessment_set = request.POST['assessment_set']
                )
        new_assessmevent.save() 
        return render(request, 'sets/' + ASSESSMENTS[new_assessmevent.assessment_set].url, {'assessment': ASSESSMENTS[new_assessmevent.assessment_set], 'assessmevent': new_assessmevent})

    return HttpResponse('something went wrong')    
Exemplo n.º 4
0
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))})