Exemplo n.º 1
0
def progress(request):
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        progress = []
        records = dict([(r.course.id, r) for r in profile.records.all()])

        credit_records = [(r.date, r.course.credits) for r in profile.records.all()]
        credit_records.sort()
    
        credit_count = 0
        graph_entries = []
        if credit_records:
            for entry in credit_records:
                credit_count += entry[1]
                graph_entries.append([entry[0], credit_count])
                
        for degree in profile.degrees.all():
            evaluator = parse_degree(degree)
            print evaluator.credit_worth()
            evaluator.eval(records)
            completion = (float(evaluator.creditcount) / float(evaluator.credit_worth())) * 100
            progress.append({
                                'degree': degree,
                                'evaluator': evaluator,
                                'completion': completion
                            })
        return render_to(request, 'student/progress.html', {
                'progress': progress,
                'graph_entries': graph_entries
            })
    else:
        return render_to(request, 'student/anon.html')
def courses_manage(request):
    profile = request.user.get_profile()
    if profile:
        records = profile.record_set.all()
	data = { 'records': profile.record_set.all()  }
	return render_to(request, 'student/courses/manage.html', data)
    else:
        # NOT IMPLEMENNTED
        pass
        
    return render_to(request, 'student/courses/manage.html')
Exemplo n.º 3
0
def create_admin(request):
    output = {}
    if request.user.is_authenticated() and request.user.is_superuser:
        if request.method == 'POST':
            errors = {}
        
            # extract values from POST, will be None if not present
            username, pw1, pw2 = extract(request.POST, 'username', 'password1', 'password2')
        
            # begin validation...
            if username is None or len(username) == 0:
                errors['username'] = '******'
            else:
                try:
                    user = User.objects.get(username=username)
                    #user.delete()
                    errors['username'] = '******'
                except User.DoesNotExist:
                    # good
                    pass

            if pw1 is None or len(pw1) == 0:
                errors['password1'] = 'Required'

            if pw2 is None  or len(pw2) == 0:
                errors['password2'] = 'Required'

            if pw1 != pw2:
                errors['password1'] = 'Passwords must match'

            # ... end of validation
            
            if len(errors) == 0:
                user = User(username=username)
                user.set_password(pw1)
                user.is_active = True
                user.is_superuser = True
                user.is_staff = True
                user.save()
                
                return render_to(request, 'administrator/register_success.html', {
                	'username':username
                })
                
            output['errors'] = errors
            output['username'] = username
                
        # fall through if errors
        return render_to(request, 'administrator/register.html', output)
def progress(request):
    profile = request.user.get_profile()
    progress = []
    for degree in profile.degrees.all():
        progress.append( {'degree': degree,
                          'passed': evaluate(request.user, degree) } )
    return render_to(request, 'student/progress.html', { 'progress': progress })
Exemplo n.º 5
0
def courses_manage(request):
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        if profile:
            data = { 'records': profile.records.all()  }
        return render_to(request, 'student/courses/manage.html', data)
    else:
        # redirect to main
        return redirect('/student/')
Exemplo n.º 6
0
def degrees_manage(request):
    if request.user.is_authenticated():
        user = request.user.get_profile()
        degrees = UserProfile.objects.get(id=user.id).degrees.all()
        degree_dict = {'degrees': degrees}
        return render_to(request, 'student/degrees/manage.html', degree_dict)
    else:
        # redirect to main
        return redirect('/student/')
Exemplo n.º 7
0
def edit_degree(request, id):
    try:
        degree = Degree.objects.get(pk=id)
    except Degree.DoesNotExist:
        print 'DEGREE DOES NOT EXIST'
        raise Http404
        
    if request.method == 'POST':
        return json_response(degree.xml_to_json())
    else:
        return render_to(request, 'administrator/edit_degree.html', {})
Exemplo n.º 8
0
def register_user(request):
    output = {}
    if request.method == 'POST':
        errors = {}
        
        # extract values from POST, will be None if not present
        username, pw1, pw2 = extract(request.POST, 'username', 'password1', 'password2')
        
        # begin validation...
        if username is None  or len(username) == 0:
            errors['username'] = '******'
        else:
            try:
                user = User.objects.get(username=username)
                #user.delete()
                errors['username'] = '******'
            except User.DoesNotExist:
                # good
                pass

        if pw1 is None or len(pw1) == 0:
            errors['password1'] = 'Required'

        if pw2 is None  or len(pw2) == 0:
            errors['password2'] = 'Required'

        if pw1 != pw2:
            errors['password1'] = 'Passwords must match'

        # ... end of validation
        
        if len(errors) == 0:
            user = User(username=username)
            user.set_password(pw1)
            user.is_active = True
            user.save()
            
            # SUCCESS, redirect...
            if REQUIRE_ACTIVATION:
                # set active flag to false until email verified
                user.is_active = False
                user.save()
                return redirect('/activate')
            else:
                # don't need to verify. log user in and go to home 
                user.backend='django.contrib.auth.backends.ModelBackend' 
                login(request, user)
                return redirect('/')
            
        output['errors'] = errors
        output['username'] = username
            
    # fall through if errors
    return render_to(request, 'profiles/register.html', output)
def transcript_import(request):
    user_input = request.POST.get('transcript', None)
        
    # POST REQUEST
    if user_input:
        courses = []
	dne = []
	multiple = []
	
	for match in re.finditer(TRANSCRIPT_RE, user_input):
            section, number = (str(match.group(1)), int(match.group(2)))
                        
	    try:
                course = Course.objects.get(section__abbreviation=section, 
                                                            number=number)
		grade = match.group(6)
		date = datetime.date(int(match.group(11)) + 2000, 
				     int(match.group(9)), 
				     int(match.group(10)))
		courses.append( (course, grade, str(date)) )
                                
	    except Course.DoesNotExist:
                dne.append( (section, number) )
                        
	    except Course.MultipleObjectsReturned:
                # email administrators about the error
                # don't add any, but tell the student something broke
                multiple.append( (section, number) )
                        
	data = { 'courses': courses,
		 'dne': dne,
		 'multiple': multiple }
                
	return render_to(request, 'student/transcript/verify.html', data)
        
    # GET REQUEST
    else:
        return render_to(request, 'student/transcript/import.html')
Exemplo n.º 10
0
def courses_add(request, id):
    if request.method == 'GET':
        return render_to(request, 'student/courses/getgradedate.html', {
                'course': Course.objects.get(id=int(id))
            })
    elif request.method == 'POST':
        grade = request.POST.get('grade', None)
        date = request.POST.get('date', None)
        date = datetime.date(int(request.POST.get('year')), 
                             int(request.POST.get('month')), 
                             int(request.POST.get('day')))
        profile = request.user.get_profile()
        course = Course.objects.get(id=id)
        
        try:
            Record.objects.get(profile=profile, course=course, grade=grade, date=date)
        except Record.DoesNotExist:
            Record.objects.create(profile=profile, course=course, grade=grade, date=date)
        except ValueError:
            pass

    return redirect('/student/courses/manage/')
Exemplo n.º 11
0
def new_degree(request):
    if request.method == 'POST':
        args = ['name', 'degree_type', 'college_id', 'year']
        
        if not contains(request.POST, *args):
            print request.POST
            print 'MISSING KEY IN POST DICT'
            raise Http404
        
        name, degree_type, college_id, year = extract(request.POST, *args)
        
        # ensure it doesn't exist
        try:
            degree = Degree.objects.get(name=name, 
                                        college__id=college_id, 
                                        degree_type=degree_type,
                                        year=year)
                                        
        except Degree.DoesNotExist:
            # we need to create it
            degree = Degree(name=name, degree_type=degree_type, year=year)
            degree.college_id = college_id
            degree.save()
            # create xml file
            open(degree.xml(), "w")
            
        # go edit the degree
        return redirect('administrator.views.edit_degree', id=degree.id)
                        
    # GET request:
    colleges = College.objects.all()
    return render_to(request, 'administrator/new_degree.html', {
            'colleges': colleges,
            'degree_types': Degree.DEGREE_TYPES,
            'years': range(2000, datetime.now().year + 3),
    })
Exemplo n.º 12
0
def open_degree(request):
    degrees = Degree.objects.all()
    return render_to(request, 'administrator/open_degree.html', {
            'degrees': degrees,
    })
Exemplo n.º 13
0
def courses_list(request):
    return render_to(request, 'student/courses/list.html', {
        'sections': Section.objects.all()
    })
Exemplo n.º 14
0
def degrees_list(request):
    return render_to(request, 'student/degrees/list.html', {
            'colleges': College.objects.all(),
    })
def courses_list(request):
    print "hello"
    print Course.objects.all()
    return render_to(request, 'student/courses/list.html', {
        'sections': Section.objects.all()
    })
def degrees_manage(request):
    return render_to(request, 'student/degrees/manage.html')
Exemplo n.º 17
0
def home(request):
    return render_to(request, 'profiles/home.html')
Exemplo n.º 18
0
def import_transcript(request):
    return render_to(request, 'profiles/import.html')
def degrees_list(request):
    return render_to(request, 'student/degrees/list.html')