Exemple #1
0
	def subid(self):
		return sub(self.id, {
			'SB':'TT',
			'SG':'GB',
			'SJ':'JR',
			'P1':'BT1',
			'P2':'BT2',
			'Z1':'BJ1',
			'Z2':'BJ2',
		})
Exemple #2
0
def update_existing_student(already, student):
    already.oid = student.id
    already.hid = student.studentid
    if student.dob:
        already.birthday = student.dob
    if not already.grad_year:
        already.grad_year = est_grad(student)
    if not already.tshirt:
        already.tshirt = sub(student.tshirt, {'AXL': 'XL'})
    already.needs = student.needsdescribe
    already.save()
Exemple #3
0
def update_existing_family(already, family):
    if not already.hid:
        already.hid = family.accessid
    if not already.phone:
        already.phone = family.home
    if not already.email:
        already.email = family.email
    if not already.address:
        already.address = Addresses.create(
            line1=family.street,
            line2='Apt. ' + family.apt if family.apt else '',
            city=family.city.title(),
            state=family.state.upper(),
            zipcode=family.zip,
        )
    if not already.mother:
        already.mother = Parents.create(
            first=family.mfirst,
            # alt_first = family.mnick,
            alt_last='' if family.mlast == family.family else family.mlast,
            sex='F',
            alt_phone=0 if family.mcell == family.home else family.mcell,
            family_id=already.id,
        )
    if not already.father:
        already.father = Parents.create(
            first=family.ffirst,
            # alt_first = family.fnick,
            alt_last='' if family.flast == family.family else family.flast,
            sex='M',
            alt_phone=0 if family.fcell == family.home else family.fcell,
            family_id=already.id,
        )
    for student in OldStudents.filter(familyid=family.accessid):
        alreadyStudent = find_existing_student(already, student)
        if alreadyStudent:
            update_existing_student(alreadyStudent, student)
        else:
            stu = Students.create(
                oid=student.id,
                hid=student.studentid,
                created_at=student.creationdate,
                updated_at=student.moddate,
                family=already,
                first=namecase(student.first),
                alt_last='' if (not already) or already.last == student.last
                else student.last,
                alt_email='' if (not already) or already.email == student.email
                else student.email,
                sex=student.sex,
                birthday=student.dob if student.dob else '2020-12-31',
                grad_year=est_grad(student),
                tshirt=sub(student.tshirt, {'AXL': 'XL'}),
                needs=student.needsdescribe)
Exemple #4
0
def index(request, model):
    bad = restricted(request)
    if bad:
        return bad
    columns = []
    for ftp in FIELDS[model]:
        field = ftp['field']
        columns.append(field)
    query = collect(request.GET, str)
    order_by = query.get('order_by')
    if order_by:
        query.pop('order_by')
    limit = query.get('limit')
    offset = query.get('offset')
    limit = int(limit) if limit else None
    offset = int(offset) if offset else None
    if limit and offset:
        query.pop('limit')
        query.pop('offset')
        qset = MODELS[model].filter(**query)[offset:offset + limit]
    elif limit:
        query.pop('limit')
        qset = MODELS[model].filter(**query)[:limit]
    elif offset:
        query.pop('offset')
        qset = MODELS[model].filter(**query)[offset:]
    else:
        qset = MODELS[model].filter(**query)
    if order_by:
        qset = qset.order_by(order_by)
    display = []
    for thing in qset:
        dthing = [
            '<a href="/rest/show/{}/{}">{}</a>'.format(model, thing.id,
                                                       thing.id)
        ]
        for ftp in FIELDS[model]:
            field = ftp['field']
            value = thing.__getattribute__(field)
            template = ftp['template']
            value = value if value else template.default
            dthing.append(template.static(field, value))
        display.append(dthing)
    context = {
        'columns': columns,
        'display': display,
        'model': model,
        'Model': sub(model, {
            'coursetrad': 'Course Tradition'
        }).title()
    }
    return render(request, 'rest/index.html', context)
Exemple #5
0
def new(request, model, **kwargs):
    bad = restricted(request, 5)
    if bad:
        return bad
    if 'foreign_model' in kwargs:
        old_model = model
        model = kwargs['foreign_model']
    else:
        old_model = None
    manager = MODELS[model]
    neutral = sub(model, {'mother': 'parent', 'father': 'parent'})
    tempset = FIELDS[neutral]
    display = []
    for ftp in tempset:
        field = ftp['field']
        template = ftp['template']
        value = template.default
        if str(model) == 'mother' and field == 'sex':
            value = 'F'
        if str(field) == str(old_model):
            value = MODELS[old_model].get(id=kwargs['id'])
        # print kwargs
        value = template.widget(field, value)
        display.append({
            'field': template.field if template.field else field,
            'input': value
        })
    context = {
        'display': display,
        'model': model,
        'neutral': neutral,
        'Model': sub(neutral, {
            'coursetrad': 'Course Tradition'
        }).title()
    }
    return render(request, 'rest/new.html', context)
Exemple #6
0
def enrollment_matrix(request, **kwargs):
    bad = restricted(request, 5)
    if bad:
        return bad
    year = int(kwargs['year']) if 'year' in kwargs else getyear()
    kwargs.update(request.GET)
    everyone = kwargs.setdefault('everyone', False) == [u'True']
    siblings = kwargs.setdefault('siblings', False) == [u'True']
    siblings |= everyone
    families = Families.all()
    if not everyone:
        families = families.filter(
            children__enrollment__course__year=year).distinct()
    families = families.order_by('last', 'name_num')
    table = []
    blank = {'content': '', 'rowspan': 1, 'class': 'enr'}
    ctids = {'SB': 'TT', 'SG': 'GB', 'SJ': 'JR'}
    for family in families:
        oldest = True
        children = family.children.all(
        ) if siblings else family.children_enrolled_in(year)
        for student in children:
            row = {
                'family': family,
                'last': family.unique_last_in(year),
                'student': student,
                'age': student.hst_age_in(year),
                'nchild': len(children),
                'oldest': oldest,
                'XW': [],
            }
            oldest = False
            for enrollment in student.enrollments_in(year):
                ctid = enrollment.course.tradition.id
                row[enrollment.course.genre] = {
                    'enr': enrollment,
                    'ctid': sub(ctid, ctids)
                }
                if ctid[0] in 'XW':
                    row['XW'].append(enrollment)
            table.append(row)
    context = {
        'year': year,
        'table': table,
    }
    return render(request, 'reports/enrollment_matrix_edit.html', context)
Exemple #7
0
def show_or_edit(request, model, id, isEdit):
    manager = MODELS[model]
    thing = manager.get(id=id)
    bad = restricted(request, 5) if isEdit else restricted(
        request, 4, thing, 1)
    if bad:
        return bad
    method = request.GET.get('method')
    if method:
        call = thing.__getattribute__(method)
        if hasattr(call, '__call__'):
            call()
        return redirect('/rest/{}/{}/{}/'.format('edit' if isEdit else 'show',
                                                 model, id))
    tempset = FIELDS[model]
    display = []
    for ftp in tempset:
        field = ftp['field']
        value = thing.__getattribute__(field)
        value = value if value else ''
        template = ftp['template']
        if isEdit:
            value = template.widget(field, value)
        else:
            value = template.static(field, value)
        if value == None:
            value = ''
        display.append({
            'field':
            template.field
            if hasattr(template, 'field') and template.field else field,
            'input':
            value
        })
    context = {
        'thing': thing,
        'display': display,
        'model': model,
        'Model': sub(model, {
            'coursetrad': 'Course Tradition'
        }).title()
    }
    return render(request, 'rest/edit.html' if isEdit else 'rest/show.html',
                  context)
Exemple #8
0
	def enroll(self, student, **kwargs):
		enrollment = Enrollments.fetch(course=self,student=student)
		if enrollment:
			enrollment.status = sub(enrollment.status, {
				'aud_drop':'aud_pass',
				'deferred':'maydefer',
				'eligible':'need_pay',
				'aud_need':'aud_pend',
				'nonexist':'need_pay',
			})
			enrollment.save()
		else:
			if eligible(self, student) and self.slots_open:
				enrollment = Enrollments.create(course=self, student=student, status="need_pay")
			elif kwargs.get('passed_audition'):
				enrollment = Enrollments.create(course=self, student=student, status="aud_pass")
			elif audible(self, student) and self.slots_open:
				return Enrollments.create(course=self, student=student, status="aud_pend")
		if self.tradition.action == 'trig':
			self.trig(student)
		return enrollment
Exemple #9
0
 def __getitem__(self, key):
     key = str(key)
     key = sub(key, self.subs)
     return self.fields[key]
Exemple #10
0
	def public_status(self):
		return sub(self.status, {"pendpass":"******","pendfail":"aud_pend","aud_fail":"fail_pub"})