Example #1
0
def roster(request, id):
    course = Courses.fetch(id=id)
    bad = restricted(request, 1)
    if bad:
        return bad
    context = {'course': course}
    return render(request, 'reports/rowspan_roster.html', context)
Example #2
0
 def courses_toggle_enrollments(self):
     qset = []
     for enrollment in self.enrollment.all():
         qset.append({
             'widget': enrollment,
             'static': Courses.fetch(id=enrollment.course_id)
         })
     return qset
Example #3
0
def registration(request, **kwargs):
    bad = restricted(request, 1)
    if bad:
        return bad
    year = int(request.GET.copy().setdefault('year', getyear()))
    context = {
        'year': year,
        'now': datetime.datetime.now(),
        'sc': Courses.fetch(year=year, tradition=CourseTrads.fetch(id='SC')),
    }
    context.update(layered_students_and_families(year, enrollments=True))
    return render(request, 'reports/registration.html', context)
Example #4
0
def admin(request, **kwargs):
    bad = restricted(request, 6)
    if bad:
        return bad
    course = Courses.fetch(id=kwargs['id'])
    results = []
    if request.GET.get('enrollment'):
        enrollment = Enrollments.fetch(id=request.GET['enrollment'])
        if request.GET.get('move'):
            new_course = Courses.fetch(id=request.GET['move'])
            enrollment.course = new_course
        if request.GET.get('status'):
            enrollment.status = request.GET['status']
        enrollment.save()
    elif request.GET.get('drop'):
        enrollment = Enrollments.fetch(id=request.GET['drop'])
        enrollment.delete()
    elif request.GET.get('query'):
        results = search_query(request.GET['query'],
                               all_tables=False,
                               student=True)
    elif request.GET.get('add'):
        student = Students.fetch(id=request.GET['add'])
        Enrollments.create(student=student, course=course)
    # if request.GET and not request.GET.get('query'):
    # 	return redirect('/rest/admin/{model}/{id}'.format(**kwargs))
    context = {
        'course':
        course,
        'courses':
        Courses.filter(year=course.year, tradition__e=True,
                       tradition__m=True).order_by('tradition__order'),
        'results':
        results,
        'status_choices':
        Each(status_choices).__getitem__(0),
    }
    return render(request, 'rest/admin.html', context)
Example #5
0
def load_post(request):
	start_import = datetime.now()
	nUsers       = 0
	nFamilies    = 0
	nStudents    = 0
	nParents     = 0
	nAddresses   = 0
	nVenues      = 0
	nCourseTrads = 0
	nCourses     = 0
	nEnrollments = 0

	json_dump = request.POST['json_dump']
	request.session['json_dump'] = ''
	data = json.loads(json_dump)

	for ct in data['coursetrads']:
		if 'alias_id' not in ct:
			already = CourseTrads.fetch(id=ct['id'])
			if already:
				print 'Exists:   '+ct['title'].upper()
			else:
				print 'Importing '+ct['title'].upper()
				ct.setdefault('default','enrolled' if ct['after_tuit'] == 0 else 'need_pay')
				CourseTrads.create(**ct)
				nCourseTrads += 1

	for ct in data['coursetrads']:
		if 'alias_id' in ct:
			already = CourseTrads.fetch(id=ct['id'])
			if already:
				print 'Exists:   '+ct['title'].upper()
			else:
				print 'Importing '+ct['title'].upper()
				ct.setdefault('default','--------')
				alias = CourseTrads.get(id=ct.pop('alias_id'))
				ct['alias'] = alias
				CourseTrads.create(**ct)
				nCourseTrads += 1

	# cts = CourseTrads.filter(e=True)
	# for year in data['years']:
	# 	for ct in cts:
	# 		ct.make(year)
	# 		nCourses += 1

	for fam in data['families']:
		print fam['last']
		family = copy(fam,['last','phone','email'])
		if 'address' in fam:
			address = copy(fam['address'])
			if 'zipcode' not in address:
				address['zipcode'] = 00000
			address = Addresses.create(**address)
			nAddresses += 1
			family['address'] = address
		family = Families.create(**family)
		family.update_name_num()
		nFamilies += 1
		user_obj = fam.get('user')
		if user_obj:
			Users.create(
				owner_type = 'Family',
				owner_id   = family.id,
				username   = user_obj['username'],
				password   = user_obj['password'],
				permission = user_obj['permission'],
			)
			nUsers += 1
		if 'mother' in fam:
			mother = copy(fam['mother'])
			mother['family_id'] = family.id
			family.mother = Parents.create(**mother)
			nParents += 1
		if 'father' in fam:
			father = copy(fam['father'])
			father['family_id'] = family.id
			family.father = Parents.create(**father)
			nParents += 1
		family.save()
		for stu in fam['students']:
			if 'first' in stu:
				print '  '+stu['first']
				student = copy(stu)
				enrollments = student.pop('enrollments') if 'enrollments' in student else []
				student['family'] = family
				newStudent = Students.create(**student)
				for enrollment in enrollments:
					rolled = type(enrollment) in [object,dict]
					course_id = enrollment['course_id'] if rolled else enrollment
					print '    '+course_id
					course = Courses.fetch(id=course_id)
					if not course:
						course = Courses.create_by_id(course_id)
						nCourses += 1
					enrollment_kwargs = {
						'student': newStudent,
						'course' : course,
						'status' : enrollment.setdefault('status','enrolled') if hasattr(enrollment,'setdefault') else 'enrolled'
					}
					if rolled:
						enrollment_kwargs['role']      = enrollment['role']
						enrollment_kwargs['role_type'] = enrollment['role_type']
					Enrollments.create(**enrollment_kwargs)
					nEnrollments += 1
					# if type(enrollment) in [str,unicode]:
					# 	Courses.get(id=enrollment).sudo_enroll(newStudent)
					# else:
					# 	course = Courses.get(id=enrollment['course_id'])
					# 	Enrollments.create(course=course, student=newStudent, role=enrollment['role'], role_type=enrollment['role_type'])
				nStudents += 1

	print "- assign name_num's"
	Each(Families.all()).update_name_num()

	print '- order_coursetrads'
	order_coursetrads()

	# year = getyear()
	# print '- make {}'.format(year)
	# nCourses += make(year)

	# print '- assign developer: Wolf Elkan'
	# elkan = Families.fetch(last='Elkan')
	# if elkan:
	# 	Users.create(
	# 		username='******',
	# 		password='******',
	# 		permission=7,
	# 		owner_type='Family',
	# 		owner_id=elkan.id
	# 		)

	import_duration = datetime.now() - start_import
	
	print '\nIMPORT COMPLETED'
	print 'Users:     ' + str(nUsers).rjust(5)
	print 'Families:  ' + str(nFamilies).rjust(5)
	print 'Students:  ' + str(nStudents).rjust(5)
	print 'Parents:   ' + str(nParents).rjust(5)
	print 'Addresses: ' + str(nAddresses).rjust(5)
	print 'Venues:    ' + str(nVenues).rjust(5)
	print 'Traditions:' + str(nCourseTrads).rjust(5)
	print 'Courses:   ' + str(nCourses).rjust(5)
	print 'Enrollments:'+ str(nEnrollments).rjust(4)
	print 'Time:    '   + str(import_duration)

	return redirect('/seed/load/')
Example #6
0
def overview(request, **kwargs):
    bad = restricted(request, 5)
    if bad:
        return bad
    GET = request.GET.copy()
    year = GET.setdefault('year', getyear())
    if 'repop' in GET:
        all_students = Students.all()
        course = Courses.fetch(id=GET['repop'])
        if course:
            course.repop(all_students=all_students)
            return redirect('/reports/overview/?year=' + year)
    courses = Courses.filter(year=year).order_by('tradition__order')
    nTickets = {
        'SB':
        [len(Courses.fetch(tradition__id='KB', year=year).students), 0, 0],
        'SC':
        [len(Courses.fetch(tradition__id='KC', year=year).students), 0, 0],
        'SG': [
            len(Courses.fetch(tradition__id='KG', year=year).students),
            len(Courses.fetch(tradition__id='KS', year=year).students),
            len(Courses.fetch(tradition__id='KW', year=year).students),
        ],
        'SJ': [
            len(Courses.fetch(tradition__id='KJ', year=year).students),
            len(Courses.fetch(tradition__id='KT', year=year).students),
            len(Courses.fetch(tradition__id='KX', year=year).students),
        ],
        'SH': [
            len(Courses.fetch(tradition__id='KH', year=year).students),
            len(Courses.fetch(tradition__id='KU', year=year).students),
            len(Courses.fetch(tradition__id='KY', year=year).students),
        ],
        'SR': [
            len(Courses.fetch(tradition__id='KR', year=year).students),
            len(Courses.fetch(tradition__id='KV', year=year).students),
            len(Courses.fetch(tradition__id='KZ', year=year).students),
        ],
    }
    tSlots = 0
    tFilled = 0
    tuitionRev = 0
    for course in courses.filter(tradition__e=True, tradition__m=True):
        tSlots += course.tradition.nSlots
        tFilled += len(course.students)
        tuitionRev += course.revenue
    context = {
        'date':
        datetime.datetime.now(),
        'year':
        Year(year),
        'ar':
        '{:02}'.format(int(year) % 100),
        'real':
        courses.filter(tradition__e=True, tradition__m=True),
        'auto':
        courses.filter(tradition__e=True, tradition__m=False),
        'stat':
        Courses.filter(tradition__r=False,
                       year=year).order_by('tradition__order'),
        'rf':
        Courses.fetch(tradition__id='RF', year=year),
        'tSlots':
        tSlots,
        'tFilled':
        tFilled,
        'tuitionRev':
        tuitionRev,
        'total': {
            'SB':
            nTickets['SB'][0] * 10,
            'SC':
            nTickets['SC'][0] * 10,
            'SG':
            nTickets['SG'][0] * 10 + nTickets['SG'][1] * 15 +
            nTickets['SG'][2] * 20,
            'SH':
            nTickets['SH'][0] * 10 + nTickets['SH'][1] * 15 +
            nTickets['SH'][2] * 20,
            'SJ':
            nTickets['SJ'][0] * 10 + nTickets['SJ'][1] * 15 +
            nTickets['SJ'][2] * 20,
            'SR':
            nTickets['SR'][0] * 10 + nTickets['SR'][1] * 15 +
            nTickets['SR'][2] * 20,
            '10':
            sum(Each(nTickets.values()).__getitem__(0)),
            '15':
            sum(Each(nTickets.values()).__getitem__(1)),
            '20':
            sum(Each(nTickets.values()).__getitem__(2)),
            'tt':
            sum(Each(nTickets.values()).__getitem__(0)) * 10 +
            sum(Each(nTickets.values()).__getitem__(1)) * 15 +
            sum(Each(nTickets.values()).__getitem__(2)) * 20,
        },
        'latest_enrollment':
        Enrollments.all().order_by('-updated_at')[0]
    }
    prepaidRev = context['prepaidRev'] = context['total']['tt'] * 10
    context['totalRev'] = prepaidRev + context['tuitionRev'] + context[
        'rf'].revenue
    return render(request, 'reports/overview.html', context)