示例#1
0
class AlertLimitReached(Event):
    cache_key_fmt = "stock_alert_%s_%s"

    identifier = "alert_limit_reached"
    name = _("Alert Limit Reached")

    supplier = Variable(_("Supplier"), type=Model("shuup.Supplier"))
    product = Variable(_("Product"), type=Model("shuup.Product"))
    dispatched_last_24hs = Variable(
        _("Fired in the last 24 hours?"),
        type=Boolean,
        help_text=_(
            "This will be True if this event was already dispatched "
            "in the last 24 hours for the same product and supplier. "
            "This is useful to prevent sending identical notifications in a short "
            "period of time."))

    def __init__(self, **variable_values):
        cache_key = self.cache_key_fmt % (variable_values["supplier"].pk,
                                          variable_values["product"].pk)
        last_dispatch_time = cache.get(cache_key)

        if last_dispatch_time:
            last_dispatch = int((time() - last_dispatch_time) / 60 / 60)
            variable_values["dispatched_last_24hs"] = (last_dispatch < 24)
        else:
            variable_values["dispatched_last_24hs"] = False

        super(AlertLimitReached, self).__init__(**variable_values)

    def run(self, shop):
        cache_key = self.cache_key_fmt % (self.variable_values["supplier"].pk,
                                          self.variable_values["product"].pk)
        cache.set(cache_key, time(), timeout=(60 * 60 * 24))
        super(AlertLimitReached, self).run(shop=shop)
class ShipmentDeleted(Event):
    identifier = "shipment_deleted"
    name = _("Shipment Deleted")

    order = Variable(_("Order"), type=Model("shuup.Order"))
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    language = Variable(_("Language"), type=Language)

    shipment = Variable(_("Shipment"), type=Model("shuup.Shipment"))
    shipping_status = Variable(_("Order Shipping Status"), type=Enum(ShippingStatus))
class PaymentCreated(Event):
    identifier = "payment_created"
    name = _("Payment Created")

    order = Variable(_("Order"), type=Model("shuup.Order"))
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    language = Variable(_("Language"), type=Language)

    payment_status = Variable(_("Order Payment Status"), type=Enum(PaymentStatus))
    payment = Variable(_("Payment"), type=Model("shuup.Payment"))
示例#4
0
class OrderStatusChanged(Event):
    identifier = "order_status_changed"
    name = _("Order Status Changed")

    order = Variable(_("Order"), type=Model("shuup.Order"))
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    shop_email = Variable(_("Shop Email"), type=Email)
    shop_phone = Variable(_("Shop Phone"), type=Phone)
    old_status = Variable(_("Old Status"), type=Model("shuup.OrderStatus"))
    new_status = Variable(_("New Status"), type=Model("shuup.OrderStatus"))
    language = Variable(_("Language"), type=Language)
示例#5
0
class PaymentCreated(Event):
    identifier = "payment_created"

    order = Variable("Order", type=Model("shuup.Order"))
    customer_email = Variable("Customer Email", type=Email)
    customer_phone = Variable("Customer Phone", type=Phone)
    language = Variable("Language", type=Language)

    payment_status = Variable(
        "Order Payment Status",
        type=Enum(PaymentStatus),
        help_text=_("Possible values: {0}").format(", ".join(
            ["{0}".format(choice) for choice in PaymentStatus])))
    payment = Variable("Order", type=Model("shuup.Payment"))
示例#6
0
class ShipmentDeleted(Event):
    identifier = "shipment_deleted"

    order = Variable("Order", type=Model("shuup.Order"))
    customer_email = Variable("Customer Email", type=Email)
    customer_phone = Variable("Customer Phone", type=Phone)
    language = Variable("Language", type=Language)

    shipment = Variable("Shipment", type=Model("shuup.Shipment"))
    shipping_status = Variable(
        "Order Shipping Status",
        type=Enum(ShippingStatus),
        help_text=_("Possible values: {0}").format(", ".join(
            ["{0}".format(choice) for choice in ShippingStatus])))
示例#7
0
class ShipmentCreated(Event):
    identifier = "shipment_created"
    name = _("Shipment Created")

    order = Variable(_("Order"),
                     type=Model("shuup.Order"),
                     attributes=ORDER_ATTRIBUTES)
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    language = Variable(_("Language"), type=Language)

    shipment = Variable(_("Shipment"), type=Model("shuup.Shipment"))
    shipping_status = Variable(_("Order Shipping Status"),
                               type=Enum(ShippingStatus))
    shipment_status = Variable(_("Shipment Status"), type=Enum(ShipmentStatus))
示例#8
0
class RegistrationReceived(Event):
    identifier = "registration_received"
    name = _("Registration Received")
    customer = Variable(_("Customer"), type=Model("shuup.Contact"))
    customer_email = Variable(_("Customer Email"), type=Email)
    activation_url = Variable(_("Activation URL"), type=URL, required=False)
    user_is_active = Variable(_("Is User Active"), type=Boolean)
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("shuup.Order"))
示例#10
0
class OrderReceived(Event):
    identifier = "order_received"

    order = Variable("Order", type=Model("shuup.Order"))
    customer_email = Variable("Customer Email", type=Email)
    customer_phone = Variable("Customer Phone", type=Phone)
    language = Variable("Language", type=Language)
示例#11
0
class TaskCreated(Event):
    identifier = "task_created"
    name = _("Task Created")

    task = Variable(_("Task"), type=Text)
    type = Variable(_("Type"), type=Model("shuup_tasks.TaskType"))
    status = Variable(_("Status"), type=Enum(TaskStatus))
    priority = Variable(_("Priority"), type=Integer)
示例#12
0
class OrderReceived(Event):
    identifier = "order_received"
    name = _("Order Received")

    order = Variable(_("Order"), type=Model("shuup.Order"))
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    shop_email = Variable(_("Shop Email"), type=Email)
    shop_phone = Variable(_("Shop Phone"), type=Phone)
    language = Variable(_("Language"), type=Language)
class VendorReviewCreated(Event):
    identifier = "vendor_review_created"
    name = _("Vendor Review Created")

    vendor_review = Variable(_("Vendor Review"),
                             type=Model("shuup_vendor_reviews.VendorReview"))

    reviewer_email = Variable(_("Customer Email"), type=Email)
    reviewer_phone = Variable(_("Customer Phone"), type=Phone)

    shop_email = Variable(_("Shop Email"), type=Email)
    shop_phone = Variable(_("Shop Phone"), type=Phone)
示例#14
0
class PagSeguroPaymentStatusChanged(Event):
    identifier = "pagseguro_payment_status_changed"
    name = _("PagSeguro: Payment Status Changed")

    order = Variable(_("Order"), type=Model("shuup.Order"))
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    language = Variable(_("Language"), type=Language)

    old_status = Variable(_("Old Status"),
                          type=Enum(PagSeguroTransactionStatus))
    new_status = Variable(_("New Status"),
                          type=Enum(PagSeguroTransactionStatus))
示例#15
0
class RefundCreated(Event):
    identifier = "refund_created"
    name = _("Refund Created")

    order = Variable(_("Order"),
                     type=Model("shuup.Order"),
                     attributes=ORDER_ATTRIBUTES)
    customer_email = Variable(_("Customer Email"), type=Email)
    customer_phone = Variable(_("Customer Phone"), type=Phone)
    language = Variable(_("Language"), type=Language)

    payment_status = Variable(_("Order Payment Status"),
                              type=Enum(PaymentStatus))
class ProductReviewCreated(Event):
    identifier = "product_review_created"
    name = _("Product Review Created")

    product_review = Variable(
        _("Product Review"), type=Model("shuup_product_reviews.ProductReview"))

    reviewer_email = Variable(_("Customer Email"), type=Email)
    reviewer_phone = Variable(_("Customer Phone"), type=Phone)

    shop_email = Variable(_("Shop Email"), type=Email)
    shop_phone = Variable(_("Shop Phone"), type=Phone)

    language = Variable(_("Language"), type=Language)
示例#17
0
class PasswordReset(Event):
    identifier = "shuup_notify_password_reset"
    name = _("Password Reset")
    description = _("This event is triggered when password reset is requested.")

    site_name = Variable(_("Site name"), type=Text)
    uid = Variable(_("User secret"), type=Text)
    user_to_recover = Variable(_("User to recover"), type=Model(settings.AUTH_USER_MODEL))
    token = Variable(_("Token"), type=Text)
    recovery_url = Variable(_("Recovery URL"), type=Text)

    # Attribut name so email sending works with generic template
    # See: https://github.com/shuup/shuup/blob/master/shuup/notify/script_template/generic.py#L89
    customer_email = Variable(_("To Email"), type=Email)
示例#18
0
class AddOrderLogEntry(Action):
    identifier = "add_order_log_entry"
    order = Binding("Order", Model("shuup.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)
示例#19
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: shuup.notify.script.Context
        """
        values = self.get_values(context)
        if values["recipient_type"] == RecipientType.SPECIFIC_USER:
            if not values["recipient"]:
                context.log(
                    logging.WARN,
                    "Warning! 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"],
            shop=context.shop,
        )
示例#20
0
def test_model_type_matching():
    assert empty_iterable(
        Binding("x", type=Model("shuup.Contact")).get_matching_types(
            ATestEvent.variables))
    assert Binding("x", type=Model("shuup.Order")).get_matching_types(
        ATestEvent.variables) == {"order"}
示例#21
0
class RegistrationReceived(Event):
    identifier = "registration_received"
    name = _("Registration Received")
    customer = Variable(_("Customer"), type=Model("shuup.Contact"))
    customer_email = Variable(_("Customer Email"), type=Email)
示例#22
0
class CompanyAccountCreated(Event):
    identifier = "company_account_created"

    contact = Variable("CompanyContact", type=Model("shuup.CompanyContact"))
    customer_email = Variable("Customer Email", type=Email)
示例#23
0
class AlertLimitReached(Event):
    identifier = "alert_limit_reached"

    supplier = Variable("Supplier", type=Model("shuup.Supplier"))
    product = Variable("Product", type=Model("shuup.Product"))