def email_reminders_teachers_sub_request_open(self):
        """
        Send teachers reminders when a sub for their class hasn't been found yet.
        :return:
        """
        from openstudio.os_class import Class
        from openstudio.os_mail import OsMail
        from openstudio.os_sys_email_reminders import SysEmailReminders

        T = current.T
        db = current.db
        TODAY_LOCAL = current.TODAY_LOCAL

        # Check if reminders configured
        sys_reminders = SysEmailReminders('teachers_sub_request_open')
        reminders = sys_reminders.list()

        mails_sent = 0
        for reminder in reminders:
            # Get list of open classes on reminder date
            reminder_date = TODAY_LOCAL + datetime.timedelta(reminder.Days)

            query = (db.classes_otc.Status == 'open') & \
                    (db.classes_otc.ClassDate == reminder_date)

            rows = db(query).select(db.classes_otc.ALL)
            for row in rows:
                clsID = row.classes_id
                cls = Class(clsID, row.ClassDate)
                regular_teachers = cls.get_regular_teacher_ids()

                if not regular_teachers['error']:
                    auth_teacher_id = regular_teachers['auth_teacher_id']
                    teacher = db.auth_user(auth_teacher_id)

                    os_mail = OsMail()
                    result = os_mail.render_email_template(
                        'teacher_sub_request_open_reminder',
                        classes_otc_id=row.id,
                        return_html=True)

                    send_result = False
                    if not result['error']:
                        send_result = os_mail.send(
                            message_html=result['html_message'],
                            message_subject=T("Reminder - open class"),
                            auth_user_id=auth_teacher_id)

                    if send_result:
                        mails_sent += 1

            # send reminder to teacher

        return "Sent mails: %s" % mails_sent
Exemple #2
0
    def _render_email_template_teacher_sub_request_open_reminder(
            self, template_content, cotcID):
        """
        Render mail template for teacher no sub found yet reminders
        :param cotcID: db.classes_otc.id
        :return: html - mail body for reminder
        """
        from openstudio.os_class import Class

        T = current.T
        db = current.db
        DATE_FORMAT = current.DATE_FORMAT
        TIME_FORMAT = current.TIME_FORMAT

        error = False
        error_msg = ''

        cotc = db.classes_otc(cotcID)

        cls = Class(cotc.classes_id, cotc.ClassDate)
        regular_teachers = cls.get_regular_teacher_ids()
        teacher_name = ''
        if not regular_teachers['error']:
            auth_teacher_id = regular_teachers['auth_teacher_id']
            teacher = db.auth_user(auth_teacher_id)
            teacher_name = teacher.first_name

        class_info = TABLE(TR(
            TH(T('Date'), _align="right"),
            TD(cotc.ClassDate.strftime(DATE_FORMAT), _align="left")),
                           TR(
                               TH(T('Time'), _align="right"),
                               TD(cls.cls.Starttime.strftime(TIME_FORMAT),
                                  ' - ',
                                  cls.cls.Endtime.strftime(TIME_FORMAT),
                                  _align="left")),
                           TR(TH(T('Location'), _align="right"),
                              TD(cls.get_location_name(), _align="left")),
                           TR(TH(T('Class'), _align="right"),
                              TD(cls.get_classtype_name(), _align="left")),
                           _cellspacing="0",
                           _cellpadding='5px',
                           _width='100%',
                           border="0")

        description = class_info
        content = XML(template_content.format(teacher_name=teacher_name, ))

        return dict(error=error,
                    error_msg=error_msg,
                    content=content,
                    description=description)
Exemple #3
0
    def _render_email_template_teacher_sub_requests_daily_summary(
            self, template_content, auth_user_id):
        """
        :param template_content:
        :param auth_user_id:
        :return:
        """
        from openstudio.os_class import Class
        from openstudio.os_teacher import Teacher
        from openstudio.tools import OsTools
        from openstudio.os_classes_otcs import ClassesOTCs

        db = current.db
        T = current.T
        os_tools = OsTools()
        cotcs = ClassesOTCs()
        teacher = Teacher(auth_user_id)
        DATE_FORMAT = current.DATE_FORMAT
        TIME_FORMAT = current.TIME_FORMAT
        error = False
        error_msg = ''

        date_from = current.TODAY_LOCAL + datetime.timedelta(days=1)
        date_until = date_from + datetime.timedelta(days=45)

        # G get list of allowed class types
        query = (db.teachers_classtypes.auth_user_id == auth_user_id)
        classtype_rows = db(query).select(db.teachers_classtypes.ALL)
        ct_ids = []
        for row in classtype_rows:
            ct_ids.append(int(row.school_classtypes_id))

        open_classes_for_teacher = 0
        open_classes = ''
        description = ''
        if ct_ids:
            sys_hostname = os_tools.get_sys_property('sys_hostname')
            description = XML(
                template_content.format(teacher_name=teacher.get_first_name(),
                                        link_employee_portal=URL(
                                            'ep',
                                            'index',
                                            scheme='https',
                                            host=sys_hostname)))

            open_classes = TABLE(
                THEAD(
                    TR(
                        TH(T("Date"), _align="left"),
                        TH(T("Time"), _align="left"),
                        TH(T("Location"), _align="left"),
                        TH(T("Class"), _align="left"),
                        # TH(),
                    )),
                _cellspacing="0",
                _cellpadding='5px',
                _width='100%',
                border="0")

            # Get Open classes in the next 45 days
            rows = cotcs.get_sub_teacher_rows(date_from,
                                              date_until,
                                              school_classtypes_ids=ct_ids,
                                              only_open=True)

            for i, row in enumerate(rows):
                repr_row = list(rows[i:i + 1].render())[0]

                date = row.classes_otc.ClassDate
                clsID = row.classes.id
                cls = Class(clsID, date)
                regular_teachers = cls.get_regular_teacher_ids()

                if regular_teachers['auth_teacher_id'] == auth_user_id:
                    continue

                open_classes.append(
                    TR(
                        TD(repr_row.classes_otc.ClassDate, _align="left"),
                        TD(repr_row.classes.Starttime, _align="left"),
                        TD(repr_row.classes.school_locations_id,
                           _align="left"),
                        TD(repr_row.classes.school_classtypes_id,
                           _align="left"),
                        # TD('Actions here?'),
                    ))

                open_classes_for_teacher += 1

        if not open_classes_for_teacher:
            error = True
            error_msg = T(
                "No upcoming classes with subs required found for this teacher"
            )

        return dict(content=open_classes,
                    description=description,
                    error=error,
                    error_msg=error_msg)