示例#1
0
文件: manage.py 项目: dsully/sitter
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)
示例#2
0
文件: manage.py 项目: dsully/sitter
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)