Exemple #1
0
def create_sit_request():
    form = SitRequestForm(request.form)

    families = Family.query.filter_by(active=True).order_by(Family.name).all()

    form.family.query = [f for f in families if not f.is_bank]
    form.sitter.query = form.family.query

    # Set the default for the user in the admin case to their own family.
    if not form.family.data:
        form.family.data = current_user.family

    if form.validate_on_submit():
        start_date = datetime.combine(form.date.data, form.start.data)
        end_date = datetime.combine(form.date.data, form.end.data)

        # Check for after midnight, set the day to be +1
        if start_date.hour > 12 > end_date.hour:
            end_date = end_date + timedelta(days=1)

        SitRequest.create(start_date, end_date, form.family.data, form.sitter.data)

        flash("Sit Request Created!", 'info')

        return redirect(url_for('create_sit_request'), 303)

    return render_template('www/create_sit_request.html', form=form)
Exemple #2
0
def cancel_sit_request(id):

    sit = SitRequest.cancel(id)

    flash('Cancelled sit request on %s.' % sit.date, category='info')

    return redirect(url_for('sit_requests'), 303)
Exemple #3
0
def accept_sit_request(id):

    sit = SitRequest.accept(id, current_user)

    flash("Accepted sit request on %s, for %s." % (sit.date, sit.family.name), category='info')

    return redirect(url_for('sit_requests'), 303)
Exemple #4
0
def weekly():
    """ Send weekly emails. """

    secretary = Family.query.filter_by(secretary=True).first()
    requests = SitRequest.open_requests()
    url = url_for('sit_requests')

    if requests:
        # Send a combined email with all open sits.
        subject = "Reminder: Unfilled Sits!"
        body = render_template('email/needs-filling.txt', requests=requests, secretary=secretary, subject=subject, url=url)

        send_mail(app.config['EMAIL_FROM'], app.config['EMAIL_LIST'], subject, body)
Exemple #5
0
def decline_sit_request(id):

    sit = SitRequest.decline(id)
    flash('Declined sit request on %s.' % sit.date, category='info')

    return redirect(url_for('sit_requests'), 303)
Exemple #6
0
def daily():
    """ Run daily actions. """

    # Must sit for 5 different families to get off probation.
    # Triggers email to co-chair to determine if off probation.
    co_chair = Family.query.filter(Family.type == FamilyType.co_chair).first()
    secretary = Family.query.filter_by(secretary=True).first()

    for family in Family.query.filter(Family.type == FamilyType.probation):

        sat_for = family.pending_off_probation

        if sat_for:
            subject = '%s might be off probation' % family.name
            body = render_template('email/off-probation.txt', family=family, sat_for=sat_for, secretary=secretary, num_sits=len(sat_for))

            send_mail(app.config['EMAIL_FROM'], co_chair.email_addresses, subject, body)

    ##########################
    # Send new sit emails.
    url = url_for('sit_requests')
    new_requests = list()

    for request in SitRequest.open_requests():

        if not request.sitter and ((datetime.now() - request.ctime) < timedelta(days=1)):
            new_requests.append(request)

    if new_requests:
        subject = "New Sit Requests"
        body = render_template('email/new-sits.txt', requests=new_requests, secretary=secretary, url=url)

        send_mail(app.config['EMAIL_FROM'], app.config['EMAIL_LIST'], subject, body)

    ##########################
    # Send newly accepted sit emails.

    for request in SitRequest.taken_requests():

        if request.atime is None:
            continue

        if ((datetime.now() - request.atime) < timedelta(days=1)):
            request.send_accept_email()

    ##########################
    # Send sit reminder emails.
    days_in_advance = 2

    for request in SitRequest.taken_requests():

        if (request.date - date.today()).days == days_in_advance:

            subject = "You have a sit in %s days for the %s family!" % (days_in_advance, request.family.name)
            body = render_template('email/upcoming-reminder.txt', request=request, secretary=secretary, subject=subject)
            attachments = [parent.vcard_with_filename for parent in request.family.parents]

            send_mail(app.config['EMAIL_FROM'], request.sitter.email_addresses, subject, body, attachments)

    ##########################
    # Send reminder email to secretary if it's 72 hours within a sit & it hasn't been filled.
    call_requests = list()

    for request in SitRequest.open_requests():

        if not request.sitter and (request.date - date.today()).days <= 3:
            call_requests.append(request)

    if call_requests:
        subject = "Unfilled Sit Requests: 72 hours! Please call!"
        body = render_template('email/call-sits.txt', requests=call_requests, secretary=secretary, url=url)

        send_mail(app.config['EMAIL_FROM'], secretary.email_addresses, subject, body)

    ##########################
    # Send email to sitters that still need to report hours.
    days_after_sit = 3

    for request in SitRequest.needs_reports():
        if (date.today() - request.date).days >= days_after_sit:
            subject = "Please submit hours for your sit on %s for the %s family." % (request.date, request.family.name)
            body = render_template('email/needs-report.txt', subject=subject, secretary=secretary, url=url)

            send_mail(app.config['EMAIL_FROM'], request.sitter.email_addresses, subject, body)