Esempio n. 1
0
    def send_decline_email(self, sitter):
        secretary = Family.query.filter_by(secretary=True).first()
        addresses = self.family.email_addresses
        addresses.extend(sitter.email_addresses)

        subject = "The sit on %s has been declined by the %s family." % (self.date, sitter.name)
        body = render_template('email/declined.txt', request=self, secretary=secretary)

        send_mail(app.config['EMAIL_FROM'], addresses, subject, body)
Esempio n. 2
0
    def send_cancel_email(self):
        secretary = Family.query.filter_by(secretary=True).first()
        addresses = list()
        addresses.extend(self.family.email_addresses)
        addresses.extend(self.sitter.email_addresses)

        subject = "The sit on %s has been cancelled!" % self.date
        body = render_template('email/cancelled.txt', request=self, secretary=secretary)

        send_mail(app.config['EMAIL_FROM'], addresses, subject, body)
Esempio n. 3
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)
Esempio n. 4
0
def monthly():
    """ Send monthly balances email to list (on the 25th) & change the secretary. """

    # Update the current secretary.
    families = [f for f in Family.query.order_by(Family.name) if not f.is_bank and not f.on_probation and f.active]
    secretary = 0

    for i, family in enumerate(families):
        if family.secretary is True:

            if i + 1 >= len(families):
                secretary = 0
            else:
                secretary = i + 1

            family.secretary = False
            families[secretary].secretary = True
            break

    db.session.commit()

    # Send out monthly emails.
    secretary = Family.query.filter_by(secretary=True).first()
    balances = list()
    month = (date.today() - timedelta(days=1)).strftime('%B')

    for family in Family.query:
        if family.is_bank or not family.active:
            continue

        balances.append((family.current_balance, family))

    subject = "End of %s Sit Balances" % month
    body = render_template('email/monthly.txt', balances=sorted(balances), month=month, secretary=secretary)

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

    # Send email to the new secretary, with the new month, as this script is run at 11:59pm of the previous month.
    month = (date.today() + timedelta(days=1)).strftime('%B')
    subject = "You are the secretary for the month of %s!" % month
    body = render_template('email/secretary.txt', month=month)
    emails = sorted([parent.email for parent in secretary.parents])
    chair = sorted([parent.email for parent in Family.query.filter_by(type=FamilyType.chair).first().parents])

    send_mail(app.config['EMAIL_FROM'], emails, subject, body, cc=chair)
Esempio n. 5
0
    def send_accept_email(self):
        """ Send an email to the requester & acceptee with contact information. """

        secretary = Family.query.filter_by(secretary=True).first()

        # First to the acceptee.
        subject = "Sit confirmation for the %s family on %s" % (self.family.name, self.date)
        body = render_template('email/accept-sitter.txt', request=self, secretary=secretary)
        attachments = [self.ical_with_filename(self.family)]

        for parent in self.family.parents:
            attachments.append(parent.vcard_with_filename)

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

        # Now to the requesting family.
        subject = "Your sit on %s has been accepted by the %s family." % (self.date, self.sitter.name)
        body = render_template('email/accept-family.txt', request=self, secretary=secretary)
        attachments = [self.ical_with_filename(self.family)]

        for parent in self.sitter.parents:
            attachments.append(parent.vcard_with_filename)

        send_mail(app.config['EMAIL_FROM'], self.family.email_addresses, subject, body, attachments)
Esempio n. 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)