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.")
class BaseEntityFile(with_metaclass(deferred.ForeignKeyBuilder, models.Model)): """ ENG: ManyToMany relation from the polymorphic Entity to a set of files. RUS: Связь многие-ко многим от полиморфной Сущности к файлам. """ file = FilerFileField(verbose_name=_('File')) entity = deferred.ForeignKey('BaseEntity', verbose_name=_('Entity')) order = models.SmallIntegerField(default=0, blank=False, null=False, db_index=True) class Meta: """ RUS: Метаданные класса. """ abstract = True verbose_name = _("Entity File") verbose_name_plural = _("Entity Files") ordering = ('order', ) unique_together = (('file', 'entity'), ) def __str__(self): """ RUS: Строковое представление данных. """ return "{}".format(self.file) EntityFileModel = deferred.MaterializedModel(BaseEntityFile)
#============================================================================== # BaseEntityImage #============================================================================== @python_2_unicode_compatible class BaseEntityImage(with_metaclass(deferred.ForeignKeyBuilder, models.Model)): """ ENG: ManyToMany relation from the polymorphic Entity to a set of images. RUS: Связь многие-ко многим от полиморфной Сущности к изображениям. """ image = image.FilerImageField(verbose_name=_('Image')) entity = deferred.ForeignKey('BaseEntity', verbose_name=_('Entity')) order = models.SmallIntegerField(default=0, blank=False, null=False, db_index=True) class Meta: """ RUS: Метаданные класса. """ abstract = True verbose_name = _("Entity Image") verbose_name_plural = _("Entity Images") ordering = ('order',) def __str__(self): """ RUS: Строковое представление данных. """ return "{}".format(self.image) EntityImageModel = deferred.MaterializedModel(BaseEntityImage)
""" return "{}: {}".format(self.term.name, self.value) def save(self, force_insert=False, force_update=False, *args, **kwargs): """ RUS: Сохраняет объект в базе данных. """ if not force_update: self.view_class = ' '.join([ x.lower() for x in self.view_class.split() ]) if self.view_class else None return super(BaseAdditionalEntityCharacteristicOrMark, self).save(force_insert, force_update, *args, **kwargs) AdditionalEntityCharacteristicOrMarkModel = deferred.MaterializedModel( BaseAdditionalEntityCharacteristicOrMark) #============================================================================== # BaseEntityRelation #============================================================================== @python_2_unicode_compatible class BaseEntityRelation( with_metaclass(deferred.ForeignKeyBuilder, models.Model)): """ ENG: Allows to be attached related entities. RUS: Позволяет присоединять связанные сущности. """ from_entity = deferred.ForeignKey('BaseEntity', related_name='forward_relations', verbose_name=_('From Entity'))
its country code or language. """ return [(True, datetime.max) ] # Infinite number of products available until eternity def is_in_cart(self, cart, watched=False, **kwargs): """ Checks if the current product is already in the given cart, and if so, returns the corresponding cart_item. Args: watched (bool): This is used to determine if this check shall only be performed for the watch-list. **kwargs: Optionally one may pass arbitrary information about the product being looked up. This can be used to determine if a product with variations shall be considered equal to the same cart item, resulting in an increase of it's quantity, or if it shall be considered as a separate cart item, resulting in the creation of a new item. Returns: The cart_item containing the product considered as equal to the current one, or ``None`` if it is not available. """ from .cart import CartItemModel cart_item_qs = CartItemModel.objects.filter(cart=cart, product=self) return cart_item_qs.first() ProductModel = deferred.MaterializedModel(BaseProduct)
""" return cls.status.field.get_all_transitions(OrderModel) @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) @python_2_unicode_compatible 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."),
template = select_template(template_names) context = {'address': self} return template.render(context) as_text.short_description = _("Address") 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")),
class BaseDataMartImage( with_metaclass(deferred.ForeignKeyBuilder, models.Model)): """ ENG: ManyToMany relation from the polymorphic Datamart to a set of images. RUS: Связь многие-ко многим от полиморфной Витрины данных к изображениям. """ image = image.FilerImageField(verbose_name=_('Image')) data_mart = deferred.ForeignKey('BaseDataMart', verbose_name=_('DataMart')) order = models.SmallIntegerField(default=0, blank=False, null=False, db_index=True) class Meta: """ RUS: Метаданные класса. """ abstract = True verbose_name = _("DataMart Image") verbose_name_plural = _("DataMart Images") ordering = ('order', ) def __str__(self): """ RUS: Строковое представление данных. """ return "{}".format(self.image) DataMartImageModel = deferred.MaterializedModel(BaseDataMartImage)
return _("Delivery ID: {}").format(self.id) @classmethod def perform_model_checks(cls): canceled_field = [ f for f in OrderItemModel._meta.fields if f.attname == 'canceled' ] if not canceled_field or canceled_field[0].get_internal_type( ) != 'BooleanField': msg = ( "Class `{}` must implement a `BooleanField` named `canceled`, " + "if used in combination with a Delivery model.") raise ImproperlyConfigured(msg.format(OrderItemModel.__name__)) 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"), help_text=_("Refer to the shipping provider used to ship this item"), ) item = deferred.ForeignKey(