Exemplo n.º 1
0
def index(request, **kwargs):
    bad = restricted(request, 5)
    if bad:
        return bad
    context = {
        'courses': Courses.filter(year=getyear()).order_by('tradition__order'),
        'year': getyear(),
    }
    return render(request, 'reports/index.html', context)
Exemplo n.º 2
0
def refresh_summary(request, **kwargs):
    bad = restricted(request, 5)
    if bad:
        return bad
    kwargs.setdefault('year', getyear())
    for course in Courses.filter(year__in=[kwargs['year'], kwargs['year'] - 1],
                                 tradition__action='trig'):
        for student in Students.filter(enrollment__course=course):
            course.trig(student)
    return redirect('/reports/summary/')
Exemplo n.º 3
0
 def course_menu(self, year=getyear()):
     courses = Courses.filter(year=year,
                              tradition__e=True,
                              tradition__m=True)
     courses = courses.order_by('tradition__order')
     for course in courses:
         enrollment = Enrollments.fetch(student=self, course=course)
         if not enrollment or enrollment.status == 'nonexist':
             enrollment = Enrollments.model(student=self, course=course)
             enrollment.status = calc_status(enrollment)
         yield enrollment
Exemplo n.º 4
0
def historical(request, **kwargs):
    bad = restricted(request, 1)
    if bad:
        return bad
    history = []
    for year in gethist():
        history.append({
            'year': year,
            'courses': Courses.filter(year=year),
        })
    context = {'history': history}
    return render(request, 'reports/historical.html', context)
Exemplo n.º 5
0
def search_number(number, all_tables=True, **kwargs):
    results = set([])
    if all_tables or kwargs.get('family'):
        results |= set(
            Families.filter(Q(Q(id=word) | Q(oid=word) | Q(name_num=word))))
    if all_tables or kwargs.get('parent'):
        results |= set(Parents.filter(id=word))
    if all_tables or kwargs.get('student'):
        results |= set(
            Students.filter(Q(Q(id=word) | Q(oid=word) | Q(grad_year=word))))
    if all_tables or kwargs.get('invoice'):
        results |= set(Invoices.filter(Q(Q(id=word) | Q(amount=word))))
    if all_tables or kwargs.get('course'):
        results |= set(Courses.filter(year=word))
    if all_tables or kwargs.get('address'):
        results |= set(Addresses.filter(id=word))
    return results
Exemplo n.º 6
0
def mass_enroll(request, **kwargs):
    bad = restricted(request, 5)
    if bad:
        return bad
    year = kwargs.setdefault('year', getyear())
    courses = Courses.filter(year=kwargs['year'])
    students = []
    for x in request.POST:
        if x.isdigit():
            students.append(Students.fetch(id=int(x)))
    students.sort(key=lambda student: student.last)
    context = {
        'students': students,
        'courses': courses,
        'status_choices': dict(status_choices).keys(),
    }
    return render(request, 'reports/mass_enroll.html', context)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def index(request):
    if 'course' in request.GET:
        course = request.GET['course']
        if course:
            return redirect('/reports/roster/{}'.format(course))
        else:
            return redirect('/')
    me = getme(request)
    context = {
        'year':
        getyear(),
        'me':
        me,
        'name':
        me.owner if me else None,
        'incomplete_registration':
        me and me.owner and not me.owner.children,
        'sudo':
        Users.fetch(id=request.session.get('sudo')),
        'courses':
        Courses.filter(year=getyear(),
                       tradition__m=True).order_by('tradition__order')
    }
    return render(request, 'main/index.html', context)
Exemplo n.º 9
0
 def courses(self):
     return Courses.filter(enrollment__in=self.enrollment.all())
Exemplo n.º 10
0
 def trigger(self, year):
     for course in Courses.filter(year=year, tradition__action='auto'):
         course.enroll(self)
Exemplo n.º 11
0
def new(request, method=None):
	bad = restricted(request,5)
	if bad:
		return bad
	context = {
		'year': getyear(),
	}
	if 'year' in request.GET:
		year = request.GET['year']
		context.update({
			'year'   : year,
			'year2'  : year[-2:],
			'courses': equip(CourseTrads.filter(alias=None).order_by('order'), lambda trad: bool(Courses.filter(year=year,tradition=trad)), attr='already'),
		})
	elif request.GET:
		for key in request.GET:
			if request.GET[key] == 'on':
				Courses.create_by_id(key)
		return redirect('/admin/year/')
	return render(request, 'radmin/newyear/year.html', context)
Exemplo n.º 12
0
def search_word(word, all_tables=True, **kwargs):
    results = set([])
    if all_tables or kwargs.get('family'):
        results |= set(
            Families.filter(
                Q(
                    Q(hid=word) | Q(last__icontains=word)
                    | Q(phone__icontains=word) | Q(phone_type=word)
                    | Q(email__icontains=word))))
    if all_tables or kwargs.get('parent'):
        results |= set(
            Parents.filter(
                Q(
                    Q(hid=word) | Q(first__icontains=word)
                    | Q(alt_last__icontains=word)
                    | Q(alt_phone__icontains=word) | Q(phone_type=word)
                    | Q(alt_email__icontains=word))))
    if all_tables or kwargs.get('student'):
        results |= set(
            Students.filter(
                Q(
                    Q(hid=word) | Q(first__icontains=word)
                    | Q(alt_first__icontains=word)
                    | Q(family__last__icontains=word)
                    | Q(alt_last__icontains=word)
                    | Q(alt_phone__icontains=word)
                    | Q(alt_email__icontains=word)
                    | Q(needs__icontains=word))))
    if all_tables or kwargs.get('coursetrad'):
        results |= set(
            CourseTrads.filter(
                Q(
                    Q(id=word) | Q(oid=word) | Q(title__icontains=word)
                    | Q(alias_id=word) | Q(eligex__icontains=word)
                    | Q(default=word) | Q(action=word))))
    if all_tables or kwargs.get('course'):
        results |= set(
            Courses.filter(
                Q(
                    Q(id=word) | Q(tradition__id=word) | Q(tradition__oid=word)
                    | Q(title__icontains=word)
                    | Q(tradition__title__icontains=word)
                    | Q(tradition__alias_id=word)
                    | Q(tradition__eligex__icontains=word)
                    | Q(tradition__default=word)
                    | Q(tradition__action__icontains=word))))
    if all_tables or kwargs.get('address'):
        results |= set(
            Addresses.filter(
                Q(
                    Q(line1__icontains=word) | Q(line2__icontains=word)
                    | Q(city__icontains=word) | Q(state__icontains=word)
                    | Q(zipcode__icontains=word))))
    if all_tables or kwargs.get('venue'):
        results |= set(Venues.filter(name__icontains=word))
    if all_tables or kwargs.get('enrollment'):
        results |= set(Enrollments.filter(role__icontains=word))
    if all_tables or kwargs.get('user'):
        results |= set(Users.filter(username__icontains=word))
    if all_tables or kwargs.get('teacher'):
        results |= set(
            Teachers.filter(
                Q(
                    Q(first__icontains=word) | Q(last__icontains=word)
                    | Q(phone__icontains=word) | Q(email__icontains=word))))
    if all_tables or kwargs.get('invoice'):
        results |= set(
            Invoices.filter(
                Q(
                    Q(family__last__icontains=word)
                    | Q(enrollment__course__title__icontains=word)
                    | Q(paypal__txn_id__icontains=word))))
    return results
Exemplo n.º 13
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)