コード例 #1
0
    def test_error_when_initializing_unmapped_model(self):
        Unmapped = create_deferred_base_class('Unmapped')
        UnmappedModel = deferred.MaterializedModel(Unmapped)

        with self.assertRaisesRegexp(
                ImproperlyConfigured,
                'No class implements abstract base model: `Unmapped`.'):
            UnmappedModel._setup()
コード例 #2
0
        if self.order._fsm_requested_transition == ('status', 'ship_goods') and not self.shipped_at:
            shipping_modifier = cart_modifiers_pool.get_active_shipping_modifier(self.shipping_method)
            shipping_modifier.ship_the_goods(self)

    def get_number(self):
        """
        Hook to get the delivery number.
        A class inheriting from Order may transform this into a string which is better readable.
        """
        if self.order.allow_partial_delivery:
            for part, delivery in enumerate(self.order.delivery_set.all(), 1):
                if delivery.pk == self.pk:
                    return "{} / {}".format(self.order.get_number(), part)
        return self.order.get_number()

DeliveryModel = deferred.MaterializedModel(BaseDelivery)


class BaseDeliveryItem(with_metaclass(deferred.ForeignKeyBuilder, models.Model)):
    """
    Abstract base class to keep track on the delivered quantity for each ordered item. Since the
    quantity can be any numerical value, it has to be defined by the class implementing this model.
    """
    delivery = deferred.ForeignKey(
        BaseDelivery,
        verbose_name=_("Delivery"),
        on_delete=models.CASCADE,
        related_name='items',
        help_text=_("Refer to the shipping provider used to ship this item"),
    )
コード例 #3
0
            '{}/address.txt'.format(app_settings.APP_LABEL),
            'shop/address.txt',
        ]
        template = select_template(template_names)
        return template.render({'address': self})


class BaseShippingAddress(
        with_metaclass(deferred.ForeignKeyBuilder, BaseAddress)):
    address_type = 'shipping'

    class Meta:
        abstract = True


ShippingAddressModel = deferred.MaterializedModel(BaseShippingAddress)


class BaseBillingAddress(
        with_metaclass(deferred.ForeignKeyBuilder, BaseAddress)):
    address_type = 'billing'

    class Meta:
        abstract = True


BillingAddressModel = deferred.MaterializedModel(BaseBillingAddress)

ISO_3166_CODES = [
    ('AF', _("Afghanistan")),
    ('AX', _("Aland Islands")),
コード例 #4
0
        by all external plugins to check, if an Order object has been fully paid.
        """

    @classmethod
    def get_transition_name(cls, target):
        """Return the human readable name for a given transition target"""
        return cls._transition_targets.get(target, target)

    def status_name(self):
        """Return the human readable name for the current transition state"""
        return self._transition_targets.get(self.status, self.status)

    status_name.short_description = pgettext_lazy('order_models', "State")


OrderModel = deferred.MaterializedModel(BaseOrder)


class OrderPayment(with_metaclass(deferred.ForeignKeyBuilder, models.Model)):
    """
    A model to hold received payments for a given order.
    """
    order = deferred.ForeignKey(BaseOrder, verbose_name=_("Order"))
    amount = MoneyField(
        _("Amount paid"),
        help_text=_("How much was paid with this particular transfer."))
    transaction_id = models.CharField(
        _("Transaction ID"),
        max_length=255,
        help_text=_("The transaction processor's reference"))
    created_at = models.DateTimeField(_("Received at"), auto_now_add=True)
コード例 #5
0
        return str(self.user_id)

    def save(self, **kwargs):
        if 'update_fields' not in kwargs:
            self.user.save(using=kwargs.get('using', DEFAULT_DB_ALIAS))
        super(BaseCustomer, self).save(**kwargs)

    def delete(self, *args, **kwargs):
        if self.user.is_active and self.recognized is CustomerState.UNRECOGNIZED:
            # invalid state of customer, keep the referred User
            super(BaseCustomer, self).delete(*args, **kwargs)
        else:
            # also delete self through cascading
            self.user.delete(*args, **kwargs)

CustomerModel = deferred.MaterializedModel(BaseCustomer)


class VisitingCustomer(object):
    """
    This dummy object is used for customers which just visit the site. Whenever a VisitingCustomer
    adds something to the cart, this object is replaced against a real Customer object.
    """
    user = AnonymousUser()

    def __str__(self):
        return 'Visitor'

    @property
    def email(self):
        return ''
コード例 #6
0
        """
        Checks if the product is already in the given cart, and if so, returns the corresponding
        cart_item, otherwise this method returns None.
        The boolean `watched` is used to determine if this check shall only be performed for the
        watch-list.
        Optionally one may pass arbitrary information about the product using `**kwargs`. This can
        be used to determine if a product with variations shall be considered as the same cart item
        increasing it quantity, or if it shall be considered as a separate cart item, resulting in
        the creation of a new cart item.
        """
        from .cart import CartItemModel
        cart_item_qs = CartItemModel.objects.filter(cart=cart, product=self)
        return cart_item_qs.first()


ProductModel = deferred.MaterializedModel(BaseProduct)


class CMSPageReferenceMixin(object):
    """
    Products which refer to CMS pages in order to emulate categories, normally need
    a way to be accessed directly via a URL. Add this mixin to Product classes to
    add a ``get_absolute_url()`` method.
    """
    def get_absolute_url(self):
        """
        Return the absolute URL of a product
        """
        # sorting by highest level, so that the canonical URL
        # associates with the most generic category
        cms_page = self.cms_pages.order_by('depth').last()
コード例 #7
0
ファイル: related.py プロジェクト: SuperStarDev51/Django-Shop
        on_delete=models.CASCADE,
    )

    product = deferred.ForeignKey(
        BaseProduct,
        on_delete=models.CASCADE,
    )

    class Meta:
        abstract = True
        unique_together = ['page', 'product']
        verbose_name = _("Category")
        verbose_name_plural = _("Categories")


ProductPageModel = deferred.MaterializedModel(BaseProductPage)


class BaseProductImage(models.Model, metaclass=deferred.ForeignKeyBuilder):
    """
    ManyToMany relation from the polymorphic Product to a set of images.
    """
    image = image.FilerImageField(on_delete=models.CASCADE)

    product = deferred.ForeignKey(
        BaseProduct,
        on_delete=models.CASCADE,
    )

    order = models.SmallIntegerField(default=0)
コード例 #8
0
ファイル: cart.py プロジェクト: xuxubarca/django-shop
        self.cart._dirty = True

    def update(self, request):
        """
        Loop over all registered cart modifier, change the price per cart item and optionally add
        some extra rows.
        """
        if not self._dirty:
            return
        self.extra_rows = OrderedDict()  # reset the dictionary
        for modifier in cart_modifiers_pool.get_all_modifiers():
            modifier.process_cart_item(self, request)
        self._dirty = False


CartItemModel = deferred.MaterializedModel(BaseCartItem)


class CartManager(models.Manager):
    """
    The Model Manager for any Cart inheriting from BaseCart.
    """
    def get_from_request(self, request):
        """
        Return the cart for current customer.
        """
        if request.customer.is_visitor():
            raise self.model.DoesNotExist(
                "Cart for visiting customer does not exist.")
        cart, created = self.get_or_create(customer=request.customer)
        return cart
コード例 #9
0
 def setUp(self):
     self.OrderModel = deferred.MaterializedModel(DeferredBaseOrder)