Beispiel #1
0
    def update_ag_barcode(self, barcode, login_user, login_email, email_type,
                          sent_date, send_mail, sample_date, sample_time,
                          other_text):
        email_msg = ag_update_msg = None
        if all([send_mail is not None, login_email is not None,
                login_email != '']):
            subject, body_message = self._build_email(
                login_user, barcode, email_type, sample_date, sample_time)
            if body_message != '':
                sent_date = datetime.now()
                email_msg = ("Sent email successfully to kit owner %s" %
                             login_email)
                try:
                    send_email(body_message, subject, login_email)
                except:
                    email_msg = ("Email sending to (%s) failed (barcode: %s)!"
                                 "<br/>" % (login_email, barcode))
        sample_issue = self.get_argument('sample_issue', [])
        moldy = overloaded = other = 'N'
        if 'moldy' in sample_issue:
            moldy = 'Y'
        if 'overloaded' in sample_issue:
            overloaded = 'Y'
        if 'other' in sample_issue:
            other = 'Y'
        ag_update_msg = ("Barcode %s AG info was successfully updated" %
                         barcode)
        try:
            db.updateAKB(barcode, moldy, overloaded, other, other_text,
                         sent_date)
        except:
            ag_update_msg = ("Barcode %s AG update failed!!!" % barcode)

        return email_msg, ag_update_msg
Beispiel #2
0
 def test_send_email_basic(self):
     obs = send_email('test message', 'test subject', debug=True)
     self.assertEqual(obs['mimetext']['To'],
                      '*****@*****.**')
     self.assertEqual(obs['mimetext']['From'], '')
     self.assertEqual(obs['mimetext']['Subject'],
                      'test subject')
     self.assertEqual(obs['recipients'],
                      ['*****@*****.**'])
 def test_send_email_full(self):
     obs = send_email('test message',
                      'test subject',
                      recipient='*****@*****.**',
                      sender='*****@*****.**',
                      bcc=['*****@*****.**'],
                      debug=True)
     self.assertEqual(obs['mimetext']['To'], '*****@*****.**')
     self.assertEqual(obs['mimetext']['From'], '*****@*****.**')
     self.assertEqual(obs['mimetext']['Subject'], 'test subject')
     self.assertEqual(obs['recipients'],
                      ['*****@*****.**', '*****@*****.**'])
Beispiel #4
0
 def test_send_email_full(self):
     obs = send_email('test message', 'test subject',
                      recipient='*****@*****.**',
                      sender='*****@*****.**', bcc=['*****@*****.**'],
                      debug=True)
     self.assertEqual(obs['mimetext']['To'],
                      '*****@*****.**')
     self.assertEqual(obs['mimetext']['From'], '*****@*****.**')
     self.assertEqual(obs['mimetext']['Subject'],
                      'test subject')
     self.assertEqual(obs['recipients'],
                      ['*****@*****.**', '*****@*****.**'])
Beispiel #5
0
    def update_ag_barcode(self, barcode, login_user, login_email, email_type,
                          sent_date, send_mail, sample_date, sample_time,
                          other_text):
        email_msg = ag_update_msg = None
        if all([
                send_mail is not None, login_email is not None,
                login_email != ''
        ]):
            subject, body_message = self._build_email(login_user, barcode,
                                                      email_type, sample_date,
                                                      sample_time)
            if body_message != '':
                sent_date = datetime.now()
                email_msg = ("Sent email successfully to kit owner %s" %
                             login_email)
                try:
                    send_email(body_message, subject, login_email, html=True)
                except:  # noqa
                    email_msg = ("Email sending to (%s) failed (barcode: %s)!"
                                 "<br/>" % (login_email, barcode))
        sample_issue = self.get_argument('sample_issue', [])
        moldy = overloaded = other = 'N'
        if 'moldy' in sample_issue:
            moldy = 'Y'
        if 'overloaded' in sample_issue:
            overloaded = 'Y'
        if 'other' in sample_issue:
            other = 'Y'
        ag_update_msg = ("Barcode %s AG info was successfully updated" %
                         barcode)
        try:
            db.updateAKB(barcode, moldy, overloaded, other, other_text,
                         sent_date)
        except:  # noqa
            ag_update_msg = ("Barcode %s AG update failed!!!" % barcode)

        return email_msg, ag_update_msg
 def test_send_email_basic(self):
     obs = send_email('test message', 'test subject', debug=True)
     self.assertEqual(obs['mimetext']['To'], '*****@*****.**')
     self.assertEqual(obs['mimetext']['From'], '')
     self.assertEqual(obs['mimetext']['Subject'], 'test subject')
     self.assertEqual(obs['recipients'], ['*****@*****.**'])
Beispiel #7
0
    def update_ag_barcode(self, barcode):
        msg2 = msg3 = None
        sent_date = self.get_argument('sent_date', None)
        general_name = "American Gut participant"
        login_user = self.get_argument('login_user', None)  # kit owner name
        if login_user == "None":
            login_user = general_name
        send_mail = self.get_argument('send_mail', None)
        if send_mail is not None:
            email_type = self.get_argument('email_type', None)
            subject = body_message = ""
            sample_time = self.get_argument('sample_time', None)
            sample_date = self.get_argument('sample_date', None)
            if email_type == '0':
                subject = ('Follow up on Your American Gut Sample with '
                           'Barcode %s' % barcode)
                body_message = """
Dear {name},

We have recently received your sample barcode: {barcode}, but we cannot process
your sample until the following steps have been completed online. Please ensure
 that you have completed both steps outlined below:

1). Submit consent form & survey
For human samples, the consent form is mandatory. Please note that the consent
form is located on the first page of the survey. Even if you elect not to
answer the questions on the survey (as every question is optional), please
click through and submit the survey in order to ensure we receive your
completed consent form.
For pet samples, we ask that you fill out a short survey.
No consent form is necessary
For environmental samples, no consent form or survey is necessary.
Please skip to step 2 below.
To begin the consent/survey process, click on the "Add Source & Survey" tab
on the main page. Select the category (human, animal, or environmental) your
intended sample belongs to.
2). Log your sample
Note that for human & pet samples, the survey must be completed before doing
this step

In order to log your sample, please log into your account and click the
"Log Sample" button at the bottom of the left-hand navigation menu.
This will bring you to a screen with the heading "Choose your sample source".
Click on the name that the sample belongs to, then fill out the prompted
fields. To facilitate this process, the details you included on the side of
your sample tube are:
Sample Date: {sample_date}
Sample Time: {sample_time}

Our website is located at www.microbio.me/americangut. If you have any
questions, please contact us at [email protected].

Thank you,
American Gut Team

"""

                body_message = body_message.format(name=login_user,
                                                   barcode=barcode,
                                                   sample_date=sample_date,
                                                   sample_time=sample_time)
            elif email_type == '1':
                subject = ('American Gut Sample with Barcode %s is Received.' %
                           barcode)
                body_message = """
Dear {name},

We have recently received your sample with barcode {barcode} dated
{sample_date} {sample_time} and we have begun processing it.  Please see our
FAQ section for when you can expect results.
(http://www.microbio.me/americangut/FAQ.psp#faq4)

Thank you for your participation!

--American Gut Team--
"""
                body_message = body_message.format(name=login_user,
                                                   barcode=barcode,
                                                   sample_date=sample_date,
                                                   sample_time=sample_time)
            login_email = self.get_argument('login_email', None)
            if login_email != "" or login_email is not None:
                try:
                    send_email(body_message, subject, login_email)
                    sent_date = time.now()
                    msg2 = ("Sent email successfully to kit owner %s" %
                            login_email)
                except:
                    msg2 = ("Email sending to (%s) failed failed "
                            "(barcode: %s)!!!<br/>" % (login_email, barcode))
        sample_issue = self.get_argument('sample_issue', [])
        moldy = overloaded = other = 'N'
        if 'moldy' in sample_issue:
            moldy = 'Y'
        if 'overloaded' in sample_issue:
            overloaded = 'Y'
        if 'other' in sample_issue:
            other = 'Y'
        try:
            db.updateAKB(barcode, moldy, overloaded, other,
                         self.get_argument('other_text', None), sent_date)
            msg3 = ("Barcode %s AG info was sucessfully updated" % barcode)
        except:
            msg3 = ("Barcode %s AG update failed!!!" % barcode)

        return msg2, msg3
Beispiel #8
0
    def update_ag_barcode(self, barcode):
        msg2 = msg3 = None
        sent_date = self.get_argument('sent_date', None)
        general_name = "American Gut participant"
        login_user = self.get_argument('login_user', None)  # kit owner name
        if login_user == "None":
            login_user = general_name
        send_mail = self.get_argument('send_mail', None)
        if send_mail is not None:
            email_type = self.get_argument('email_type', None)
            subject = body_message = ""
            sample_time = self.get_argument('sample_time', None)
            sample_date = self.get_argument('sample_date', None)
            if email_type == '0':
                subject = ('Follow up on Your American Gut Sample with '
                           'Barcode %s' % barcode)
                body_message = """
Dear {name},

We have recently received your sample barcode: {barcode}, but we cannot process
your sample until the following steps have been completed online. Please ensure
 that you have completed both steps outlined below:

1). Submit consent form & survey
For human samples, the consent form is mandatory. Please note that the consent
form is located on the first page of the survey. Even if you elect not to
answer the questions on the survey (as every question is optional), please
click through and submit the survey in order to ensure we receive your
completed consent form.
For pet samples, we ask that you fill out a short survey.
No consent form is necessary
For environmental samples, no consent form or survey is necessary.
Please skip to step 2 below.
To begin the consent/survey process, click on the "Add Source & Survey" tab
on the main page. Select the category (human, animal, or environmental) your
intended sample belongs to.
2). Log your sample
Note that for human & pet samples, the survey must be completed before doing
this step

In order to log your sample, please log into your account and click the
"Log Sample" button at the bottom of the left-hand navigation menu.
This will bring you to a screen with the heading "Choose your sample source".
Click on the name that the sample belongs to, then fill out the prompted
fields. To facilitate this process, the details you included on the side of
your sample tube are:
Sample Date: {sample_date}
Sample Time: {sample_time}

Our website is located at www.microbio.me/americangut. If you have any
questions, please contact us at [email protected].

Thank you,
American Gut Team

"""

                body_message = body_message.format(name=login_user,
                                                   barcode=barcode,
                                                   sample_date=sample_date,
                                                   sample_time=sample_time)
            elif email_type == '1':
                subject = ('American Gut Sample with Barcode %s is Received.'
                           % barcode)
                body_message = """
Dear {name},

We have recently received your sample with barcode {barcode} dated
{sample_date} {sample_time} and we have begun processing it.  Please see our
FAQ section for when you can expect results.
(http://www.microbio.me/americangut/FAQ.psp#faq4)

Thank you for your participation!

--American Gut Team--
"""
                body_message = body_message.format(name=login_user,
                                                   barcode=barcode,
                                                   sample_date=sample_date,
                                                   sample_time=sample_time)
            login_email = self.get_argument('login_email', None)
            if login_email != "" or login_email is not None:
                try:
                    send_email(body_message, subject, login_email)
                    sent_date = time.now()
                    msg2 = ("Sent email successfully to kit owner %s"
                            % login_email)
                except:
                    msg2 = ("Email sending to (%s) failed failed "
                            "(barcode: %s)!!!<br/>" % (login_email, barcode))
        sample_issue = self.get_argument('sample_issue', [])
        moldy = overloaded = other = 'N'
        if 'moldy' in sample_issue:
            moldy = 'Y'
        if 'overloaded' in sample_issue:
            overloaded = 'Y'
        if 'other' in sample_issue:
            other = 'Y'
        try:
            db.updateAKB(barcode, moldy, overloaded, other,
                                     self.get_argument('other_text', None),
                                     sent_date)
            msg3 = ("Barcode %s AG info was sucessfully updated" % barcode)
        except:
            msg3 = ("Barcode %s AG update failed!!!" % barcode)

        return msg2, msg3