コード例 #1
0
def offers():
    """
    Page to accept and decline substitution requests
    :return:
    """
    from openstudio.os_class import Class
    from openstudio.os_classes_otc_sub_availables import ClassesOTCSubAvailables

    cotcID = request.vars['cotcID']
    cotc = db.classes_otc(cotcID)
    cls = Class(cotc.classes_id, cotc.ClassDate)

    response.title = T('Classes')
    response.subtitle = T('Sub teachers')
    response.view = 'general/tabs_menu.html'

    subs_avail = ClassesOTCSubAvailables()
    table = subs_avail.list_formatted(cotcID)

    content = DIV(
        H4(T('Sub offers')),
        H5(cls.get_name()),
        table
    )

    back = os_gui.get_button(
        'back',
        URL('index')
    )

    return dict(
        content=content,
        menu=get_menu('index'),
        back=back
    )
コード例 #2
0
    def render_email_template(self,
                              email_template,
                              title='',
                              subject='',
                              description='',
                              comments='',
                              template_content=None,
                              auth_user_id=None,
                              customers_orders_id=None,
                              customer_subscriptions_id=None,
                              customers_classcards_id=None,
                              invoices_id=None,
                              invoices_payments_id=None,
                              classes_attendance_id=None,
                              classes_otc_id=None,
                              classes_otc_sub_avail_id=None,
                              workshops_products_customers_id=None,
                              return_html=False):
        """
            Renders default email template
            uses the render function from gluon.template instead of response.render
            response throws a RestrictedError when run from the scheduler or shell...
            and we do want scheduled emails to be rendered :)
        """
        # from gluon.template import parse_template
        from gluon.template import render

        db = current.db
        T = current.T
        DATETIME_FORMAT = current.DATETIME_FORMAT
        error = False
        error_msg = ''

        request = current.request

        logo = self._render_email_template_get_logo()

        template_name = 'default.html'
        template_path = os.path.join(request.folder, 'views', 'templates', 'email')
        # Get template
        if template_content is None:
            # Get email template from db
            template_content = self.get_email_template(email_template)

        # Render template
        if email_template == 'order_received':
            subject = T('Order received')
            # do some pre-processing to show the correct order info
            content = self._render_email_template_order(template_content, customers_orders_id)

            # Check for order message
            from .os_order import Order
            order = Order(customers_orders_id)
            if order.order.CustomerNote:
                comments = DIV(
                    T("We received the following message with your order:"), BR(), BR(),
                    XML(order.order.CustomerNote.replace('\n', '<br>'))
                )

        elif email_template == 'order_delivered':
            subject = T('Order delivered')
            # do some pre-processing to show the correct order info
            content = self._render_email_template_order(template_content, customers_orders_id)

        elif email_template == 'payment_recurring_failed':
            subject = T('Recurring payment failed')
            content = self._render_email_template_payment_recurring_failed(template_content)

        elif email_template == "subscription_created":
            subject = T("Subscription activated")
            result = self._render_email_template_subscription_created(
                template_content,
                customer_subscriptions_id
            )
            title = T("Your subscription has been activated!")
            description = result['description']
            content = result['content']

        elif email_template == 'teacher_sub_requests_daily_summary':
            result = self._render_email_template_teacher_sub_requests_daily_summary(
                template_content,
                auth_user_id
            )
            title = T("Daily summary - open classes")
            description = result['description']
            content = result['content']
            error = result['error']
            error_msg = result['error_msg']

        elif email_template == 'teacher_sub_request_open_reminder':
            result = self._render_email_template_teacher_sub_request_open_reminder(
                template_content,
                classes_otc_id
            )
            title = T("A friendly reminder")
            description = result['description']
            content = result['content']
            error = result['error']
            error_msg = result['error_msg']

        elif email_template == 'teacher_sub_offer_declined':
            result = self._render_email_template_teacher_sub_offer(
                template_content,
                classes_otc_sub_avail_id
            )
            title = T("Substitute offer declined")
            description = result['description']
            content = result['content']

        elif email_template == 'teacher_sub_offer_accepted':
            result = self._render_email_template_teacher_sub_offer(
                template_content,
                classes_otc_sub_avail_id
            )
            title = T("Thank you for teaching this class")
            description = result['description']
            content = result['content']

        elif email_template == "trial_follow_up":
            result = self._render_email_trial_follow_up(
                template_content,
                classes_attendance_id=classes_attendance_id,
                customers_classcards_id=customers_classcards_id,
            )

            subject = T("Trial follow up")
            content = result['content']

        elif email_template == 'classes_info_mail':
            from .os_class import Class
            from .os_class_attendance import ClassAttendance
            clatt = ClassAttendance(classes_attendance_id)
            cls = Class(clatt.row.classes_id, clatt.row.ClassDate)
            class_name = cls.get_name()

            subject = T("Class booking") + " " + class_name
            title = T("We've reserved your spot!")
            result = self._render_email_class_info_mail(classes_attendance_id)
            content = result['content']
            description = result['description']

        elif email_template == 'workshops_info_mail':
            wspc = db.workshops_products_customers(workshops_products_customers_id)
            wsp = db.workshops_products(wspc.workshops_products_id)
            ws = db.workshops(wsp.workshops_id)
            subject = ws.Name
            title = ws.Name
            result = self._render_email_workshops_info_mail(wspc, wsp, ws)
            content = result['content']
            description = result['description']
            
        elif (email_template == 'sys_verify_email' or
              email_template == 'sys_reset_password'):
            template_name = 'default_simple.html'
            content = XML(template_content)
            subject = subject

        else:
            template_name = 'default.html'
            content = XML(template_content)
            subject = subject

        footer = XML(self.get_email_template('sys_email_footer'))

        template = os.path.join(
            template_path,
            template_name
        )

        context = dict(
            logo = logo,
            title = title,
            description = description,
            content = content,
            comments = comments,
            footer = footer,
            request = request
        )

        html_message = render(
            filename = template,
            path = template_path,
            context = context
        )

        if return_html:
            return dict(
                msg_subject = subject or "",
                html_message = html_message,
                error = error,
                error_msg = error_msg
            )
        else:
            msgID = db.messages.insert(
                msg_content = html_message,
                msg_subject = subject
            )

            return msgID
コード例 #3
0
def edit():
    """
        :return: shows order
    """
    from openstudio.os_class import Class

    response.title = T('Order #') + request.vars['coID']
    response.subtitle = T('Edit')
    response.view = 'general/only_content.html'

    coID = request.vars['coID']

    order = Order(coID)
    cuID = order.order.auth_customer_id
    customer = Customer(cuID)
    # Info table
    info = TABLE(THEAD(TR(TH(T('Customer')),
                          TH(T('Ordered on')),
                          TH(T('Status')),
                          TH(),
                          )),
                 _class='table')

    # Display status
    for field in db.customers_orders:
        field.readable = False
        field.writable = False

    db.customers_orders.Status.readable = True
    db.customers_orders.Status.writable = True

    crud.messages.record_updated = T('Saved')
    form = crud.update(db.customers_orders, coID)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    form = DIV(XML('<form id="MainForm" action="#" enctype="multipart/form-data" method="post">'),
               form.custom.widget.Status,
               form.custom.end)

    #status = form

    # status = represent_customers_orders_status(order.order.Status, order.order)
    # Display ordered on
    ordered_on = represent_datetime(order.order.DateCreated, order.order)
    customer_link = A(customer.get_name(),
                      _href=URL('customers', 'edit', args=customer.row.id))
    info.append(TR(
        TD(customer_link),
        TD(ordered_on),
        TD(form),
        TD()
    ))

    # Info content
    content = DIV(DIV(info, _class='col-md-8 no-padding-left'))

    # Display items
    rows = order.get_order_items_rows()

    header = THEAD(TR(TH(T('Product')),
                      TH(T('Description')),
                      TH(SPAN(T('Amount incl. VAT'), _class='right')),
                      TH(T("G/L Account")),
                      TH(T("Cost center")),
                      TH(T("Class check-in")),
                      TH(),
                        )
                     )
    table = TABLE(header, _class='table table-striped table-hover order-items')


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

        class_name = ""
        if row.customers_orders_items.classes_id and row.customers_orders_items.ClassDate:
            cls = Class(row.customers_orders_items.classes_id,
                        row.customers_orders_items.ClassDate)
            class_name = cls.get_name()


        table.append(TR(
            TD(repr_row.customers_orders_items.ProductName),
            TD(repr_row.customers_orders_items.Description),
            TD(SPAN(repr_row.customers_orders_items.TotalPriceVAT, _class='right')),
            TD(repr_row.customers_orders_items.accounting_glaccounts_id),
            TD(repr_row.customers_orders_items.accounting_costcenters_id),
            TD(class_name),
            TD(),
        ))

    # Display totals
    amounts = order.get_amounts()

    footer = TFOOT(TR(TD(),
                    TD(B(T('Subtotal'))),
                    TD(SPAN(CURRSYM, ' ', format(amounts.TotalPrice, '.2f'), _class='bold right')),
                    TD()
                    ),
                  TR(TD(),
                    TD(B(T('VAT'))),
                    TD(SPAN(CURRSYM, ' ', format(amounts.VAT, '.2f'), _class='bold right')),
                    TD()
                    ),
                  TR(TD(),
                    TD(B(T('Total'))),
                    TD(SPAN(CURRSYM, ' ', format(amounts.TotalPriceVAT, '.2f'), _class='bold right')),
                    TD()
                    ))
    table.append(footer)

    content.append(table)

    # Customer message
    customer_message = ''
    if order.order.CustomerNote:
        customer_message = DIV(
            B(T('Customer message')), BR(), BR(),
            XML(order.order.CustomerNote.replace("\n", "<br>")),
        )
    content.append(customer_message)

    back = os_gui.get_button('back', edit_get_return_url(cuID))

    return dict(content=content, back=back, save=submit)