def annual(): """ Run annual actions (January 1st). """ # -3 hours per family, except if on probation. for family in Family.query: if family.is_bank or family.on_probation or not family.active: continue Family.bank_transaction(3, "Yearly Dues", family=family) db.session.commit()
def admin_officers(): form = AdminOfficersForm(request.form) families = Family.query.order_by(Family.name).all() chair = next(f for f in families if f.type is FamilyType.chair) co_chair = next(f for f in families if f.type is FamilyType.co_chair) tech = next(f for f in families if f.type is FamilyType.tech) secretary = next(f for f in families if f.secretary is True) form.chair.query = [f for f in families if f.active and not f.on_probation] form.co_chair.query = [f for f in families if f.active and not f.on_probation] form.tech.query = [f for f in families if f.active and not f.on_probation] form.secretary.query = [f for f in families if f.active and not f.on_probation] # Set defaults if request.method == 'GET': form.chair.data = chair form.co_chair.data = co_chair form.tech.data = tech form.secretary.data = secretary if form.validate_on_submit(): Family.set_officer(FamilyType.chair, chair, form.chair.data) Family.set_officer(FamilyType.co_chair, co_chair, form.co_chair.data) Family.set_officer(FamilyType.tech, tech, form.tech.data) Family.set_officer('secretary', secretary, form.secretary.data) if db.session.dirty: db.session.commit() flash("Updated Officer Data!", 'info') return redirect(url_for(request.endpoint), 303) return render_template('www/admin/officers.html', form=form)
def quarterly(): """ Run quarterly actions. """ # +10 hours to Chair # +4 hours to Co-Chair # +4 hours to Roster/Tech chair = Family.query.filter_by(type=FamilyType.chair).first() co_chair = Family.query.filter_by(type=FamilyType.co_chair).first() tech = Family.query.filter_by(type=FamilyType.tech).first() for hours, family in [(10, chair), (4, co_chair), (4, tech)]: Family.bank_transaction(hours, "Quarterly Hours", sitter=family) db.session.commit()
def main(filename): for row in csv.DictReader(open(filename)): family = Family.create(*_extract_values(row, ( "Parent 1 Last Name", "Parent 2 Last Name", "Street Address", "City", "Zip Code", "Phone", "Pets" ))) for i in range(1, 3): if row.get('Parent {0} First Name'.format(i)): Parent.create(family, *_extract_values(row, [x.format(i) for x in "Parent {0} First Name", "Parent {0} Last Name", "Parent {0} email", "Parent {0} best phone number"])) for i in range(1, 4): if row.get('Child {0} Name'.format(i)): Child.create(family, *_extract_values(row, ("Child {0} Name".format(i), "Child {0} Birthdate".format(i)))) print "Created family '{0}'".format(family.name) db.session.add(family) db.session.commit()
def admin_add_submit(): family_form = FamilyForm(request.form, prefix='family') parent1_form = ParentForm(request.form, prefix='parent1') parent2_form = ParentForm(request.form, prefix='parent2') child1_form = ChildForm(request.form, prefix='child1') child2_form = ChildForm(request.form, prefix='child2') child3_form = ChildForm(request.form, prefix='child3') # TODO: Figure out how to dynamically add the forms. if not family_form.validate_on_submit(): if family_form.errors: return jsonify(errors=family_form.errors) family = Family.create(*[family_form.data.get(k, None) for k in [ 'name', 'name', 'address', 'city', 'zipcode', 'phone', 'pets' ]]) db.session.add(family) # Not great, but WTForms and rendering fields doesn't work well with dynamically added javascript. for form in (parent1_form, parent2_form): # Parent 2 might not exist. if not form.data.get('first_name'): continue if not form.validate_on_submit(): if form.errors: return jsonify(errors=form.errors) parent = Parent.create(family, *[form.data.get(k, None) for k in [ 'first_name', 'last_name', 'email', 'cell_phone', 'work_phone' ]]) db.session.add(parent) for form in (child1_form, child2_form, child3_form): if not form.data.get('name'): continue print form.data if not form.validate_on_submit(): if form.errors: return jsonify(errors=form.errors) child = Child.create(family, form.data.get('name'), form.data.get('birthday')) db.session.add(child) db.session.commit() flash("Added the {0} family!".format(family.name), 'info') return redirect(url_for(request.endpoint), 303)
def admin_probation(): form = AdminProbationForm(request.form) families = Family.query.order_by(Family.name).all() form.probation.query = [f for f in families if f.pending_off_probation and f.active] # Set defaults if request.method == 'GET': form.probation.data = form.probation.query if form.validate_on_submit(): Family.set_probation(form.probation.query, form.probation.data) if db.session.dirty: db.session.commit() flash("Updated Admin Data!", 'info') return redirect(url_for(request.endpoint), 303) return render_template('www/admin/probation.html', form=form)
def admin_retire(): form = AdminRetireForm(request.form) form.family.query = [f for f in Family.query.order_by(Family.name) if not f.is_bank and f.active] # Set defaults if request.method == 'GET': form.family.data = form.family.query if form.validate_on_submit(): family = Family.retire(form.family.data) db.session.add(family) db.session.commit() flash("Retired the {0} family!".format(family.name), 'info') return redirect(url_for(request.endpoint), 303) return render_template('www/admin/retire.html', form=form)