Пример #1
0
class OrderReceived(Event):
    identifier = "order_received"

    order = Variable("Order", type=Model("shoop.Order"))
    customer_email = Variable("Customer Email", type=Email)
    customer_phone = Variable("Customer Phone", type=Phone)
    language = Variable("Language", type=Language)
Пример #2
0
class ATestEvent(Event):
    identifier = "test_event"
    log_target_variable = "order"

    order_language = Variable(name="Order Language", type=Language)
    just_some_text = Variable(name="Just Some Text", type=Text)
    order = Variable(name="Order", type=Model("shoop.Order"))
Пример #3
0
class ReservationsOrderReceived(Event):
    identifier = "reservations_order_received"

    order = Variable("Order", type=Model("shoop.Order"))
    order_id = Variable("Order ID", type=Integer)
    order_details = Variable("Order Details", type=Text)
    order_url = Variable("Order URL", type=URL)
    customer_email = Variable("Customer Email", type=Email)
    customer_phone = Variable("Customer Phone", type=Phone)
    customer_name = Variable("Customer Name", type=Text)
    language = Variable("Language", type=Language)
    additional_notes = Variable("Additional Notes", type=Text)
    total_sum = Variable("Total Sum", type=Decimal)
Пример #4
0
class AddNotification(Action):
    identifier = "add_notification"
    recipient_type = Binding("Recipient Type",
                             type=Enum(RecipientType),
                             constant_use=ConstantUse.CONSTANT_ONLY,
                             default=RecipientType.ADMINS)
    recipient = Binding("Recipient",
                        type=Model(settings.AUTH_USER_MODEL),
                        constant_use=ConstantUse.VARIABLE_OR_CONSTANT,
                        required=False)
    priority = Binding("Priority",
                       type=Enum(Priority),
                       constant_use=ConstantUse.CONSTANT_ONLY,
                       default=Priority.NORMAL)
    message = TemplatedBinding("Message",
                               type=Text,
                               constant_use=ConstantUse.CONSTANT_ONLY,
                               required=True)
    message_identifier = Binding("Message Identifier",
                                 Text,
                                 constant_use=ConstantUse.CONSTANT_ONLY,
                                 required=False)
    url = Binding("URL",
                  type=URL,
                  constant_use=ConstantUse.VARIABLE_OR_CONSTANT)

    def execute(self, context):
        """
        :type context: shoop.notify.script.Context
        """
        values = self.get_values(context)
        if values["recipient_type"] == RecipientType.SPECIFIC_USER:
            if not values["recipient"]:
                context.log(
                    logging.WARN,
                    "Misconfigured AddNotification -- no recipient for specific user"
                )
                return
        Notification.objects.create(
            recipient_type=values["recipient_type"],
            recipient=values["recipient"],
            priority=values["priority"],
            identifier=values.get("message_identifier"),
            message=values["message"][:140],
            url=values["url"])
Пример #5
0
class AddOrderLogEntry(Action):
    identifier = "add_order_log_entry"
    order = Binding("Order",
                    Model("shoop.Order"),
                    constant_use=ConstantUse.VARIABLE_ONLY)
    message = Binding("Message",
                      Text,
                      constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    message_identifier = Binding("Message Identifier",
                                 Text,
                                 constant_use=ConstantUse.VARIABLE_OR_CONSTANT)

    def execute(self, context):
        order = self.get_value(context, "order")
        if not order:  # pragma: no cover
            return
        message = self.get_value(context, "message")
        message_identifier = self.get_value(context,
                                            "message_identifier") or None
        assert isinstance(order, Order)
        order.add_log_entry(message=message, identifier=message_identifier)
Пример #6
0
def test_model_type_matching():
    assert empty_iterable(Binding("x", type=Model("shoop.Contact")).get_matching_types(TestEvent.variables))
    assert Binding("x", type=Model("shoop.Order")).get_matching_types(TestEvent.variables) == {"order"}