Ejemplo n.º 1
0
def add_hids(**kwargs):
	for family in Families.filter(**kwargs):
		match = re.match(r'^([a-z])[^a-z]*([a-z])[^a-z]*([a-z])',family.last,flags=re.I)
		las = ''.join(match.groups()).upper()
		if not family.hid:
			# print las
			clash3 = Families.filter(hid__startswith=las)
			num = 1
			for x in clash3:
				clashnum = int(x.hid[3:5])
				if clashnum >= num:
					num = clashnum + 1
			fhid = '{}{:0>2}'.format(las,num)
			if not Families.filter(hid=hid):
				family.hid = fhid
				family.save()
		print family.hid, family
		if family.father and not family.father.hid:
			family.father.hid = '{}{:0>2}'.format(las,'FA')
		if family.mother and not family.mother.hid:
			family.mother.hid = '{}{:0>2}'.format(las,'MO')
		for student in family.children.all():
			if student.hid:
				continue
			num = student.birthday.year
			while True: # First time I've ever needed to use a do-while loop, and it's Python. Sigh.
				num %= 100
				shid = '{}{:0>2}'.format(family.hid,num)
				num += 1
				if not Students.filter(hid=shid):
					break
			student.hid = shid
			student.save()
			print student.hid, student
Ejemplo 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/')
Ejemplo n.º 3
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
Ejemplo n.º 4
0
	def students(self):
		return Students.filter(enrollment__course=self,enrollment__status='enrolled').order_by('family__last','birthday').distinct()
Ejemplo n.º 5
0
def check_word(trad, student, word, **kwargs):
    # Set defaults for omitted keyword arguments
    year = kwargs.setdefault('year', None)
    aud = kwargs.setdefault('aud', False)
    cur = kwargs.setdefault('cur', False)
    debug = kwargs.setdefault('debug', TRACE)

    if kwargs.get('debug'):
        if str(type(kwargs['debug'])
               ) == "<class 'django.core.handlers.wsgi.WSGIRequest'>":
            request = kwargs['debug']
            log(
                request, " ".join([
                    'CHECK WORD:',
                    str(trad),
                    str(student),
                    str(word),
                    kwargle(kwargs)
                ]))
        else:
            print 'CHECK WORD:', trad, student, word, kwargle(kwargs)

    # Boolean literals
    if '#' in word:
        return True
    elif '~' in word:
        return False

    # Sex literals
    elif 'm' in word:
        return student.sex == 'M'
    elif 'f' in word:
        return student.sex == 'F'

    # Check age
    elif 'a' in word:
        old_enough = student.hst_age_in(year) >= trad.min_age - word.count('y')
        young_enough = student.hst_age_in(
            year) <= trad.max_age + word.count('o')
        return old_enough and young_enough

    # Check grade
    elif 'g' in word:
        if not student.grad_year:
            return True
        old_enough = student.grade_in(year) >= trad.min_grd - word.count('y')
        young_enough = student.grade_in(year) <= trad.max_grd + word.count('o')
        return old_enough and young_enough

    # If you get this far, you're going to query the database
    else:
        query = {
            'student':
            student,
            'status__in':
            ["enrolled", "invoiced", "need_pay", "aud_pass", "maydefer"],
        }

        # Check for auditions
        if word == '@':
            if aud:
                return True
            else:
                query.update({
                    'status': "aud_pass",
                    'course__tradition': trad,
                    'course__year': year,
                })
            if kwargs.get('debug'):
                if str(type(kwargs['debug'])
                       ) == "<class 'django.core.handlers.wsgi.WSGIRequest'>":
                    request = kwargs['debug']
                    log(request, query)
                else:
                    print query
            return bool(
                Enrollments.filter(**query).exclude(student=student,
                                                    course__tradition=trad,
                                                    course__year=year))

        if 'e' in word:
            query['course__tradition__e'] = True
        if 'u' in word:
            query['course__tradition__m'] = True

        # If the word is '**', then you don't care what course it is, as long as it's this year.
        if word.count('*') == 2:
            if kwargs['cur']:
                return True
            query['course__year'] = year
            if kwargs.get('debug'):
                if str(type(kwargs['debug'])
                       ) == "<class 'django.core.handlers.wsgi.WSGIRequest'>":
                    request = kwargs['debug']
                    log(request, query)
                else:
                    print query
            return bool(
                Enrollments.filter(**query).exclude(student=student,
                                                    course__tradition=trad,
                                                    course__year=year))

        # Support * for representing any character
        if '*' not in word:
            query['course__tradition__id'] = word[0:2]
        elif word[0] != '*':
            query['course__tradition__id__startswith'] = word[0]
        elif word[1] != '*':
            query['course__tradition__id__endswith'] = word[1]

        if not kwargs['cur'] and '/' not in word:
            query['course__year'] = year
        if '/' in word:
            query['course__year__lt'] = year
        if '$' in word:
            query.pop('status__in')
            query['status'] = "enrolled"
        if '+' in word:
            query.pop('student')
            query['student__family'] = student.family
        query_result = Enrollments.filter(**query).exclude(
            student=student, course__tradition=trad, course__year=year)
        if kwargs.get('debug'):
            if str(type(kwargs['debug'])
                   ) == "<class 'django.core.handlers.wsgi.WSGIRequest'>":
                request = kwargs['debug']
                log(request, query)
                log(request, query_result)
            else:
                print query
                print query_result
        if '+' in word:
            return len(
                Students.filter(
                    enrollment__in=query_result).distinct()) >= word.count('+')
        else:
            return bool(query_result)
Ejemplo n.º 6
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