Esempio n. 1
0
def changepassword_get(request, **kwargs):
    context = copy(request.session, 'pe')
    if 'them_id' in kwargs:
        context.update({
            'me': {
                'login': getme(request, both=True)['login'],
                'sudo': Users.fetch(id=kwargs['them_id']),
            }
        })
    else:
        context.update({'me': getme(request, both=True)})
    return render(request, 'main/changepassword.html', context)
Esempio n. 2
0
def sudochangepassword(request, **kwargs):
	both = getme(request, both=True)
	if 'them_id' in kwargs:
		them = Users.fetch(id=kwargs['them_id'])
	else:
		them = both['sudo']
	me = both['login']
	if not me:
		return redirect('/')
	bad = restricted(request,6,them,allow_sudo=True)
	if bad:
		return bad 
	user = copy(request.POST,['password','pw_confm'])
	valid = Users.isValid(user, partial=True)
	if not valid:
		request.session['e'] = Users.errors(user, partial=True)
	correct = me.password(request.POST['current_pw'])
	if not correct:
		request.session['e']['current_pw'] = "Your password is incorrect"
	if correct and valid:
		if not them:
			return HttpResponse('User not found.', status=404)
		request.session['e'] = {}
		them.password = str(request.POST['password'])
		them.save()
	return redirect(request.META['HTTP_REFERER'])
Esempio n. 3
0
def students_edit(request, ref, id):
    me = getme(request)
    if not me or not me.owner or not (me.owner.mother or me.owner.father):
        return redirect('/register/redirect/')
    student = Students.fetch(id=id)
    if not student:
        return redirect('/{}/students/new/'.format(ref))
    forminit(request, 'student', student_fields, obj=student)
    context = {
        'new':
        False,
        'reg_year':
        getyear(),
        'family':
        me.owner,
        't_shirt_sizes':
        collect(
            Students.model.t_shirt_sizes, lambda obj: dict(
                collect(obj, lambda val, index: ['no' + str(index), val]))),
        'students':
        me.owner.children.all(),
        'ref':
        ref,
        'current_student':
        student,
        'e':
        request.session['e'],
        'p':
        request.session['p'],
    }
    return render(request, 'students2.html', context)
Esempio n. 4
0
def students_new(request, ref):
    me = getme(request)
    if not me or not me.owner or not (me.owner.mother or me.owner.father):
        return redirect('/register/redirect/')
    students = list(me.owner.children.all())
    students.append(new_student)
    print students
    context = {
        'new':
        True,
        'reg_year':
        getyear(),
        'family':
        me.owner,
        't_shirt_sizes':
        collect(
            Students.model.t_shirt_sizes, lambda obj: dict(
                collect(obj, lambda val, index: ['no' + str(index), val]))),
        'students':
        students,
        'ref':
        ref,
        'current_student':
        new_student,
        'e':
        request.session['e'],
        'p':
        request.session['p'],
    }
    return render(request, 'students2.html', context)
Esempio n. 5
0
def family_get(request, ref):
    me = getme(request)
    if me and me.owner:
        request.session['p']['family'].update(
            copyatts(me.owner, ['last', 'phone_type', 'email']))
        request.session['p']['family']['phone'] = str(me.owner.phone)
        request.session['p']['user']['username'] = me.username
        request.session['password_set'] = True
    context = copy(request.session, ['p', 'e', 'password_set'])
    return render(request, 'family.html', context)
Esempio n. 6
0
def courses(request, **kwargs):
	me = getme(request)
	if not me or not me.owner or not me.owner.children_eligible_in(getyear()):
		return redirect('/register')
	if request.GET.get('action') == u'add':
		return add(request, **kwargs)
	elif request.GET.get('action') == u'defer':
		return defer(request, **kwargs)
	current_id = kwargs.setdefault('id',0)
	if 'id' in kwargs:
		current_id = kwargs['id']
		current_student = me.owner.children.fetch(id=current_id)
		if not current_student:
			return redirect('/')
	else:
		current_student = me.owner.children_eligible_in(getyear())[0]
	reg_year = getyear()
	cart = me.owner.enrollments_in(reg_year).filter(course__tradition__e=True)
	cart = cart.filter(status__in=['aud_pass','aud_pend','invoiced','deferred','maydefer','enrolled','need_pay','pend_pub','aud_lock'])
	cart_pend = cart.filter(status__in=['aud_pend','invoiced','deferred'])
	cart_paid = cart.filter(status='enrolled')
	# cart_unpaid = cart.difference(cart_pend,cart_paid) # Use this line instead of next in Django 1.11+
	cart_unpaid = cart.exclude(status__in=['aud_pend','invoiced','deferred','enrolled'])
	volunteer_total = me.owner.volunteer_total_in(reg_year)
	context = {
		'ref':kwargs.get('ref'),
		'invoiceable' : bool(cart_unpaid), # TODO: This is simple enough now to be calculated in the HTML page
		'reg_year': reg_year,
		'family'  : me.owner,
		'students': equip(me.owner.children_eligible_in(getyear()), lambda student: student.hst_age_in(reg_year), attr='age'),
		'current_student' : current_student,
		'menu'    : current_student.course_menu(year=reg_year),
		'cart'    : cart,
		'nCourses': {
			'total' : len(cart),
			'pend'  : len(cart_pend),
			'paid'  : len(cart_paid),
			'unpaid': len(cart_unpaid),
		},
		'tuition' : {
			'total' : sum(collect(cart,        lambda enr: enr.course.tuition())),
			'pend'  : sum(collect(cart_pend,   lambda enr: enr.course.tuition())),
			'paid'  : sum(collect(cart_paid,   lambda enr: enr.course.tuition())),
			'unpaid': sum(collect(cart_unpaid, lambda enr: enr.course.tuition())),
		},
		'hours' : {
			'total' : me.owner.volunteer_total_in(reg_year),
			'pend'  : me.owner.hours_signed_in(reg_year),
			'paid'  : me.owner.hours_worked_in(reg_year),
			'unpaid': me.owner.volunteer_total_in(reg_year) 
					- me.owner.hours_signed_in(reg_year) 
					- me.owner.hours_worked_in(reg_year),
		},
	}
	return render(request, 'courses.html', context)
Esempio n. 7
0
def audition_results(request, **kwargs):
	course = Courses.fetch(id=kwargs['id'])
	bad = restricted(request,5,course,4)
	if bad:
		return bad
	context = {
		'course'  : course,
		'students': Enrollments.filter(course=course,status__in=['aud_pend','pendpass','pendfail']).order_by('student__family__last','student__birthday'),
		'me' : getme(request),
	}
	return render(request, 'audition_results.html', context)
Esempio n. 8
0
def account(request):
    me = getme(request)
    if not me:
        return redirect('/')
    password = unicode(me.password.html)
    context = {
        'me': me,
        'password': password,
        'year': getyear(),
        'policy': Policies.current,
    }
    return render(request, 'main/account.html', context)
Esempio n. 9
0
def run(request):
	bad = restricted(request,7,allow_sudo=True)
	if bad:
		return bad
	me = getme(request)
	command = str(request.POST.get('command'))
	modified_command = command.replace('log(','log(request,')
	request.session['command'] = command
	request.session['log'] = []
	start = datetime.datetime.now()
	exec(modified_command)
	request.session['runtime'] = str(datetime.datetime.now()-start)
	return redirect('/hot/')
Esempio n. 10
0
def sudo(request):
	sudo_id = request.GET.get('sudo')
	if sudo_id:
		request.session['sudo'] = int(sudo_id)
		return redirect('/sudo/')
	else:
		context = {
			'users':Users.all(),
			'current_sudo':Users.fetch(id=request.session.get('sudo')),
			'current_me':Users.fetch(id=request.session.get('meid')),
			'me':getme(request),
		}
		return render(request, 'radmin/sudo.html', context)
Esempio n. 11
0
def audition_process(request, **kwargs):
	me = getme(request)
	course = Courses.fetch(id=kwargs['id'])
	bad = restricted(request,5,course,4)
	if bad:
		return bad
	for key in request.POST:
		if key.isdigit():
			student = Students.fetch(id=int(key))
			enrollment = student.enrollments.filter(course=course)[0]
			if request.POST[key] == u'accept':
				enrollment.accept(me)
			if request.POST[key] == u'reject':
				enrollment.reject(me)
	return redirect('/admin/auditions/')
Esempio n. 12
0
def family_post(request, ref):
    me = getme(request)
    if me:
        me.username = request.POST['username']
        if me.owner:
            me.owner.save()
    new_family = copy(request.POST, ['last', 'phone', 'phone_type', 'email'])
    new_family['last'] = namecase(new_family['last'])
    new_user = copy(request.POST, ['username', 'password', 'pw_confm'])
    new_user['permission'] = 2
    ouu = me and str(new_user['username']) == str(me.username)
    if Families.isValid(new_family) and Users.isValid(
            new_user, override_unique_username=ouu):
        new_user.pop('pw_confm')
        if not me:
            new_family = Families.create(**new_family)
            new_user['owner'] = new_family
            me = Users.create(**new_user)
        elif me and not me.owner:
            me.username = new_user['username']
            new_family = Families.create(**new_family)
            me.owner = new_family
            me.save()
        elif me and me.owner:
            me.username = new_user['username']
            family = me.owner
            family.last = new_family['last']
            family.phone = new_family['phone']
            family.email = new_family['email']
            family.phone_type = new_family['phone_type']
            print new_family['email']
            print family.email
            family.save()
            me.save()
        request.session['e'] = {}
        request.session['meid'] = me.id
        return redirect('/register/parents')
    else:
        request.session['p'] = {
            'family': new_family,
            'user': new_user,
        }
        request.session['e'] = {
            'family': Families.errors(new_family),
            'user': Users.errors(new_user)
        }
        return redirect('/register/family')
Esempio n. 13
0
def invoice_show(request, ref, id):
    me = getme(request, both=True)['login']
    invoice = Invoices.fetch(id=id)
    bad = restricted(request, 5, invoice)
    if bad:
        return bad
    context = {
        'invoice': invoice,
        'ref':
        ref,  # Note: There are two 'ref' variables here.  They mean different things.
        'email': PAYPAL_BUSINESS_EMAIL,
        'host': 'https://{}'.format(CURRENT_HOST),
        'waiting': invoice.status == 'N'
        and request.GET.get('ref') == 'paypal',
        'sudo': me.owner.id != invoice.family.id,
    }
    return render(request, 'invoice.html', context)
Esempio n. 14
0
def reg(request, ref, step, id=None):
    me = getme(request)
    if step == 'family':
        return family(request, ref)
    elif step == 'parents':
        return parents(request, ref)
    elif step == 'students':
        return students(request, ref, id)
    elif step == 'policy':
        return policy(request, ref, id)
    elif step == 'redirect':
        if not me or not me.owner:
            return redirect('/register/family/')
        elif not me.owner.mother and not me.owner.father:
            return redirect('/register/parents/')
        else:
            return redirect('/register/students/')
Esempio n. 15
0
def hot(request):
	bad = restricted(request,7,allow_sudo=True)
	if bad:
		return bad
	me = getme(request)
	seshinit(request,'command')
	seshinit(request,'runtime', '0:00:00.000000')
	seshinit(request, 'log', [])
	context = {
		'log':request.session['log'],
		'command': request.session['command'],
		'runtime': request.session['runtime'],
		'session': divs(request.session.__dict__['_session_cache']),
		'request': divs(request.__dict__.copy()),
		'get': divs(request.GET.__dict__.copy()),
		'post': divs(request.POST.__dict__.copy()),
	}
	return render(request, 'main/hot.html', context)
Esempio n. 16
0
def policy_post(request, ref, page):
    page = int(page)
    if page != int(request.POST.get('page')):
        return HttpResponse('Page numbers do not match', status=409)
    year = int(request.POST.get('year'))
    me = getme(request)
    path = re.match(r'(.*)(policy/\d+/?)', request.path_info)
    if path:
        path = path.groups()[0]
    if request.POST.get('accept'):
        family = me.owner
        family.policyYear = year
        family.policyPage = page
        family.policyDate = datetime.now()
        family.save()
        return redirect('{}policy/{}/'.format(path, page + 1))
    elif str(path) == '/register/':
        return redirect('/')
    else:
        return redirect(path)
Esempio n. 17
0
def students_create(request, ref):
    me = getme(request)
    data = copy(request.POST, student_fields)
    if not Students.isValid(data):
        if request.POST['next'] == 'new':
            request.session['e'] = Students.errors(data)
            request.session['p'] = data.copy()
            return redirect('/{}/students/new/'.format(ref))
        else:
            request.session['e'] = {}
            return redirect('/{}/students/{}/'.format(ref,
                                                      request.POST['next']))
    else:
        data['family'] = me.owner
        new_student = Students.create(**data)
        request.session['e'] = {}
        if request.POST['next'] == 'new':
            return redirect('/{}/students/{}/'.format(ref, new_student.id))
        else:
            return redirect('/{}/students/{}/'.format(ref,
                                                      request.POST['next']))
Esempio n. 18
0
def changepassword_post(request, **kwargs):
    ref = kwargs.setdefault('ref', None)
    both = getme(request, both=True)
    me = both['login']
    if not me:
        return redirect('/')
    if 'them_id' in kwargs or both['sudo']:
        return sudochangepassword(request, **kwargs)
    user = copy(request.POST, ['password', 'pw_confm'])
    valid = Users.isValid(user, partial=True)
    if not valid:
        request.session['e'] = {}
        request.session['e'] = Users.errors(user, partial=True)
    correct = me.password(request.POST['current_pw'])
    if not correct:
        request.session['e']['current_pw'] = "Your password is incorrect"
    if correct and valid:
        request.session['e'] = {}
        me.password = request.POST['password']
        me.save()
        return redirect('/{}/'.format(ref))
    return redirect(request.META['HTTP_REFERER'])
Esempio n. 19
0
def parents_get(request, ref):
    me = getme(request)
    if not me or not me.owner:
        return redirect('/register/family')
    if me and me.owner.mother:
        request.session['p']['mom'].update({
            'mom_first':
            me.owner.mother.first,
            'mom_alt_last':
            me.owner.mother.alt_last,
            'mom_alt_phone':
            me.owner.mother.alt_phone,
            'mom_alt_email':
            me.owner.mother.alt_email,
            'mom_alt_phone_type':
            me.owner.mother.phone_type,
        })
    if me and me.owner.father:
        request.session['p']['dad'].update({
            'dad_first':
            me.owner.father.first,
            'dad_alt_last':
            me.owner.father.alt_last,
            'dad_alt_phone':
            me.owner.father.alt_phone,
            'dad_alt_email':
            me.owner.father.alt_email,
            'dad_alt_phone_type':
            me.owner.father.phone_type,
        })
    context = {
        'last': me.owner.last,
        'phone': me.owner.phone,
        'email': me.owner.email,
        'p': request.session['p'],
        'e': request.session['e'],
    }
    return render(request, 'parents.html', context)
Esempio n. 20
0
def policy_get(request, ref, page=None):
    if not page:
        return redirect(request.path_info + '1/')
    page = int(page)
    me = getme(request)
    policy = Policies.current
    if not policy:
        return HttpResponse(
            "We're sorry.  We are unable to register you at this time as we have not yet finalized this year's policy agreement.  Please check back soon."
        )
    elif page <= policy.nPages:
        context = {
            'page': page,
            'full': policy,
            'content': policy.html(page),
        }
        return render(request, 'policy.html', context)
    else:
        if me.owner.children:
            return redirect('/{}/classes/{}/'.format(ref,
                                                     me.owner.children[0].id))
        else:
            return redirect('/{}/students/new/'.format(ref))
Esempio n. 21
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)
Esempio n. 22
0
def oldest_student(request, ref):
	me = getme(request)
	if me.owner.children_eligible_in(getyear()):
		return redirect('/{}/classes/{}/'.format(ref,me.owner.children_eligible_in(getyear())[0].id))
Esempio n. 23
0
def parents_post(request, ref):
    me = getme(request)
    # Create new Parent objects
    mom = copy(request.POST, [
        'mom_skipped', 'mom_first', 'mom_alt_last', 'mom_alt_phone',
        'mom_phone_type', 'mom_alt_email'
    ])
    dad = copy(request.POST, [
        'dad_skipped', 'dad_first', 'dad_alt_last', 'dad_alt_phone',
        'dad_phone_type', 'dad_alt_email'
    ])
    mother = copy(mom, trunc=4)
    father = copy(dad, trunc=4)
    # Convert 'skipped' booleans from JavaScript strings, to Python bools.
    mother['skipped'] = mother['skipped'] == 'true'
    father['skipped'] = father['skipped'] == 'true'
    # May it be many years before we have to change these two lines of code.
    mother['sex'] = 'F'
    father['sex'] = 'M'
    # Assign Parents to Family
    mother['family_id'] = me.owner.id
    father['family_id'] = me.owner.id
    # Return sarcastic condescending message if both parents were somehow skipped.
    if mother['skipped'] and father['skipped']:
        return HttpResponse('''
			Congratulations!  You figured out how to hack JavaScript and skip both parents!
			Seriously though, we do need at least one first name.  Sorry.
			''')
    # Validate new Parent objects
    mother_valid = mother['skipped'] or Parents.isValid(mother)
    father_valid = father['skipped'] or Parents.isValid(father)
    if mother_valid and father_valid:
        request.session['e'] = {}
        # Add parents to Database if they have not been skipped
        if not mother.pop('skipped'):
            if me.owner.mother:
                mother_proxy = me.owner.mother
                mother_proxy.first = mother['first']
                mother_proxy.alt_last = mother['alt_last']
                mother_proxy.alt_phone = mother['alt_phone']
                mother_proxy.alt_email = mother['alt_email']
                mother_proxy.save()
            else:
                family = me.owner
                family.mother = Parents.create(**mother)
                family.save()
        if not father.pop('skipped'):
            if me.owner.father:
                father_proxy = me.owner.father
                father_proxy.first = father['first']
                father_proxy.alt_last = father['alt_last']
                father_proxy.alt_phone = father['alt_phone']
                father_proxy.alt_email = father['alt_email']
                father_proxy.save()
            else:
                family = me.owner
                family.father = Parents.create(**father)
                family.save()
        return redirect('/register/students')
    else:
        request.session['p'] = {
            'mom': mom,
            'dad': dad,
        }
        request.session['e'] = {
            'mom': Parents.errors(mother),
            'dad': Parents.errors(father),
        }
        return redirect('/register/parents')
Esempio n. 24
0
def invoice_create(request, ref):
    me = getme(request)
    invoice = Invoices.create(family=me.owner)
    return redirect('/{}/invoice/{}'.format(ref, invoice.id))