本文整理汇总了Python中shuup.utils.analog.define_log_model函数的典型用法代码示例。如果您正苦于以下问题:Python define_log_model函数的具体用法?Python define_log_model怎么用?Python define_log_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了define_log_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_analog
def test_analog():
PseudoPaymentProcessorLogEntry = define_log_model(PseudoPaymentProcessor)
assert PseudoPaymentProcessorLogEntry.__module__ == PseudoPaymentProcessor.__module__
assert PseudoPaymentProcessorLogEntry._meta.get_field("target").rel.to is PseudoPaymentProcessor
assert PseudoPaymentProcessor.log_entries.rel.model is PseudoPaymentProcessor
assert PseudoPaymentProcessor.log_entries.rel.related_model is PseudoPaymentProcessorLogEntry
assert issubclass(PseudoPaymentProcessorLogEntry, BaseLogEntry)
assert isinstance(PseudoPaymentProcessorLogEntry(), BaseLogEntry)
示例2: test_analog
def test_analog():
FakeModelLogEntry = define_log_model(FakeModel)
assert FakeModelLogEntry.__module__ == FakeModel.__module__
assert FakeModelLogEntry._meta.get_field("target").rel.to is FakeModel
assert FakeModel.log_entries.related.model is FakeModel
assert FakeModel.log_entries.related.related_model is FakeModelLogEntry
assert issubclass(FakeModelLogEntry, BaseLogEntry)
assert isinstance(FakeModelLogEntry(), BaseLogEntry)
示例3: test_analog
def test_analog():
PseudoPaymentProcessorLogEntry = define_log_model(PseudoPaymentProcessor)
assert PseudoPaymentProcessorLogEntry.__module__ == PseudoPaymentProcessor.__module__
related_field_name = "related"
# Behavior changs in Django 1.9
if VERSION >= (1, 9):
related_field_name = "rel"
relation_manager = getattr(PseudoPaymentProcessorLogEntry._meta.get_field("target"), related_field_name)
assert relation_manager.to is PseudoPaymentProcessor
relation_manager = getattr(PseudoPaymentProcessor.log_entries, related_field_name)
assert relation_manager.model is PseudoPaymentProcessor
assert relation_manager.related_model is PseudoPaymentProcessorLogEntry
assert issubclass(PseudoPaymentProcessorLogEntry, BaseLogEntry)
assert isinstance(PseudoPaymentProcessorLogEntry(), BaseLogEntry)
示例4: QuantityField
Shipment, related_name='products', on_delete=models.PROTECT, verbose_name=_("shipment")
)
product = models.ForeignKey(
"Product", related_name='shipments', on_delete=models.CASCADE, verbose_name=_("product")
)
quantity = QuantityField(verbose_name=_("quantity"))
# volume is m^3, not mm^3, because mm^3 are tiny. like ants.
unit_volume = MeasurementField(unit="m3", verbose_name=_("unit volume"))
unit_weight = MeasurementField(unit="g", verbose_name=_("unit weight"))
class Meta:
verbose_name = _('sent product')
verbose_name_plural = _('sent products')
def __str__(self): # pragma: no cover
return "%(quantity)s of '%(product)s' in Shipment #%(shipment_pk)s" % {
'product': self.product,
'quantity': self.quantity,
'shipment_pk': self.shipment_id,
}
def cache_values(self):
prod = self.product
self.unit_volume = (prod.width * prod.height * prod.depth) / CUBIC_MM_TO_CUBIC_METERS_DIVISOR
self.unit_weight = prod.gross_weight
ShipmentLogEntry = define_log_model(Shipment)
ShipmentProductLogEntry = define_log_model(ShipmentProduct)
示例5: Copyright
# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.db import models
from django.utils.translation import ugettext_lazy as _
from shuup.core.fields import QuantityField
from shuup.utils.analog import define_log_model
class SuppliedProduct(models.Model):
supplier = models.ForeignKey("Supplier", on_delete=models.CASCADE, verbose_name=_("supplier"))
product = models.ForeignKey("Product", on_delete=models.CASCADE, verbose_name=_("product"))
sku = models.CharField(db_index=True, max_length=128, verbose_name=_('SKU'))
alert_limit = models.IntegerField(default=0, verbose_name=_('alert limit'))
physical_count = QuantityField(editable=False, verbose_name=_('physical stock count'))
logical_count = QuantityField(editable=False, verbose_name=_('logical stock count'))
class Meta:
unique_together = (("supplier", "product", ), )
SuppliedProductLogEntry = define_log_model(SuppliedProduct)
示例6: Payment
from shuup.core.fields import CurrencyField, MoneyValueField
from shuup.utils.analog import define_log_model
from shuup.utils.properties import MoneyProperty, MoneyPropped
__all__ = ("Payment",)
class Payment(MoneyPropped, models.Model):
# TODO: Revise!!!
order = models.ForeignKey("Order", related_name='payments', on_delete=models.PROTECT, verbose_name=_('order'))
created_on = models.DateTimeField(auto_now_add=True, verbose_name=_('created on'))
gateway_id = models.CharField(max_length=32, verbose_name=_('gateway ID')) # TODO: do we need this?
payment_identifier = models.CharField(max_length=96, unique=True, verbose_name=_('identifier'))
amount = MoneyProperty('amount_value', 'order.currency')
foreign_amount = MoneyProperty('foreign_amount_value', 'foreign_currency')
amount_value = MoneyValueField(verbose_name=_('amount'))
foreign_amount_value = MoneyValueField(default=None, blank=True, null=True, verbose_name=_('foreign amount'))
foreign_currency = CurrencyField(default=None, blank=True, null=True, verbose_name=_('foreign amount currency'))
description = models.CharField(max_length=256, blank=True, verbose_name=_('description'))
class Meta:
verbose_name = _('payment')
verbose_name_plural = _('payments')
PaymentLogEntry = define_log_model(Payment)
示例7: delete
Note: `Carrier` objects should never be created on their own but
rather through a concrete subclass.
"""
service_model = ShippingMethod
def delete(self, *args, **kwargs):
ShippingMethod.objects.filter(carrier=self).update(**{"enabled": False})
super(Carrier, self).delete(*args, **kwargs)
def _create_service(self, choice_identifier, **kwargs):
return ShippingMethod.objects.create(
carrier=self, choice_identifier=choice_identifier, **kwargs)
class CustomCarrier(Carrier):
"""
Carrier without any integration or special processing.
"""
class Meta:
verbose_name = _("custom carrier")
verbose_name_plural = _("custom carriers")
def get_service_choices(self):
return [ServiceChoice('manual', _("Manually processed shipment"))]
ShippingMethodLogEntry = define_log_model(ShippingMethod)
CarrierLogEntry = define_log_model(Carrier)
示例8: CustomerTaxGroup
class CustomerTaxGroup(TranslatableShuupModel):
identifier = InternalIdentifierField(unique=True)
translations = TranslatedFields(
name=models.CharField(max_length=100, verbose_name=_('name')),
)
enabled = models.BooleanField(default=True, verbose_name=_('enabled'))
class Meta:
verbose_name = _('customer tax group')
verbose_name_plural = _('customer tax groups')
@classmethod
def get_default_person_group(cls):
obj, c = CustomerTaxGroup.objects.get_or_create(identifier="default_person_customers", defaults={
"name": _("Retail Customers")
})
return obj
@classmethod
def get_default_company_group(cls):
obj, c = CustomerTaxGroup.objects.get_or_create(identifier="default_company_customers", defaults={
"name": _("Company Customers")
})
return obj
TaxLogEntry = define_log_model(Tax)
TaxClassLogEntry = define_log_model(TaxClass)
CustomerTaxGroupLogEntry = define_log_model(CustomerTaxGroup)
示例9: get_unshipped_products
return products
def get_unshipped_products(self):
return dict(
(product, summary_datum)
for product, summary_datum in self.get_product_summary().items()
if summary_datum['unshipped']
)
def get_status_display(self):
return force_text(self.status)
def get_tracking_codes(self):
return [shipment.tracking_code for shipment in self.shipments.all() if shipment.tracking_code]
def can_edit(self):
return (
not self.has_refunds() and
not self.is_canceled() and
not self.is_complete() and
self.shipping_status == ShippingStatus.NOT_SHIPPED and
self.payment_status == PaymentStatus.NOT_PAID
)
OrderLogEntry = define_log_model(Order)
def _round_price(value):
return bankers_round(value, 2) # TODO: To be fixed in SHUUP-1912
示例10: use
def use(self, order):
return CouponUsage.add_usage(order=order, coupon=self)
def increase_customer_usage_limit_by(self, amount):
if self.usage_limit_customer:
new_limit = self.usage_limit_customer + amount
else:
new_limit = self.usages.count() + amount
self.usage_limit_customer = new_limit
def increase_usage_limit_by(self, amount):
self.usage_limit = self.usage_limit + amount if self.usage_limit else (self.usages.count() + amount)
def has_been_used(self, usage_count=1):
""" See if code is used the times given """
return CouponUsage.objects.filter(coupon=self).count() >= usage_count
def save(self, **kwargs):
if Coupon.objects.filter(code__iexact=self.code, active=True).exclude(pk=self.pk).exists():
raise ValidationError(_("Cannot have two same codes active at the same time."))
return super(Coupon, self).save(**kwargs)
def __str__(self):
return self.code
CatalogCampaignLogEntry = define_log_model(CatalogCampaign)
BasketCampaignLogEntry = define_log_model(BasketCampaign)
CouponLogEntry = define_log_model(Coupon)
CouponUsageLogEntry = define_log_model(CouponUsage)
示例11: get_thumbnailer
if self.kind != ProductMediaKind.IMAGE:
return None
return get_thumbnailer(self.file)
def get_thumbnail(self, **kwargs):
"""
Get thumbnail for image
This will return `None` if there is no file or kind is not `ProductMediaKind.IMAGE`
:rtype: easy_thumbnails.files.ThumbnailFile|None
"""
kwargs.setdefault("size", (64, 64))
kwargs.setdefault("crop", True) # sane defaults
kwargs.setdefault("upscale", True) # sane defaults
if kwargs["size"] is (0, 0):
return None
thumbnailer = self.easy_thumbnails_thumbnailer
if not thumbnailer:
return None
return thumbnailer.get_thumbnail(thumbnail_options=kwargs)
ProductMediaLogEntry = define_log_model(ProductMedia)
示例12: OrderLineTax
@python_2_unicode_compatible
class OrderLineTax(MoneyPropped, ShuupModel, LineTax):
order_line = models.ForeignKey(
OrderLine, related_name='taxes', on_delete=models.PROTECT,
verbose_name=_('order line'))
tax = models.ForeignKey(
"Tax", related_name="order_line_taxes",
on_delete=models.PROTECT, verbose_name=_('tax'))
name = models.CharField(max_length=200, verbose_name=_('tax name'))
amount = MoneyProperty('amount_value', 'order_line.order.currency')
base_amount = MoneyProperty('base_amount_value', 'order_line.order.currency')
amount_value = MoneyValueField(verbose_name=_('tax amount'))
base_amount_value = MoneyValueField(
verbose_name=_('base amount'),
help_text=_('Amount that this tax is calculated from'))
ordering = models.IntegerField(default=0, verbose_name=_('ordering'))
class Meta:
ordering = ["ordering"]
def __str__(self):
return "%s: %s on %s" % (self.name, self.amount, self.base_amount)
OrderLineLogEntry = define_log_model(OrderLine)
OrderLineTaxLogEntry = define_log_model(OrderLineTax)
示例13: __str__
def __str__(self):
return self.code
def get_currency_precision(currency):
"""
Get precision by currency code.
Precision values will be populated from the ``decimal_places``
fields of the `Currency` objects in the database.
:type currency: str
:param currency: Currency code as 3-letter string (ISO-4217)
:rtype: decimal.Decimal|None
:return: Precision value for given currency code or None for unknown
"""
cache_key = 'currency_precision:' + currency
precision = cache.get(cache_key)
if precision is None:
currency_obj = Currency.objects.filter(code=currency).first()
precision = (
decimal.Decimal('0.1') ** currency_obj.decimal_places
if currency_obj else None)
cache.set(cache_key, precision)
return precision
CurrencyLogEntry = define_log_model(Currency)
示例14: reply
created_on = models.DateTimeField(auto_now_add=True, editable=False, db_index=True, verbose_name=_("created on"))
modified_on = models.DateTimeField(auto_now=True, editable=False, db_index=True, verbose_name=_("modified on"))
objects = TaskCommentQuerySet.as_manager()
def reply(self, contact, body):
comment = TaskComment(task=self.task, comment_author=contact, body=body)
comment.full_clean()
comment.save()
return comment
def as_html(self):
return mark_safe(force_text(self.body))
def can_see(self, user):
is_admin = user.is_superuser
is_staff = bool(user.is_staff and user in self.task.shop.staff_members.all())
if not (is_admin or is_staff):
return (self.visibility == TaskCommentVisibility.PUBLIC)
elif not is_admin:
return (
self.visibility == TaskCommentVisibility.PUBLIC or
self.visibility == TaskCommentVisibility.STAFF_ONLY
)
return True
TaskLogEntry = define_log_model(Task)
示例15: Manufacturer
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from shuup.core.fields import InternalIdentifierField
from shuup.utils.analog import define_log_model
__all__ = ("Manufacturer",)
@python_2_unicode_compatible
class Manufacturer(models.Model):
created_on = models.DateTimeField(auto_now_add=True, verbose_name=_('added'))
identifier = InternalIdentifierField(unique=True)
name = models.CharField(max_length=128, verbose_name=_('name'))
url = models.CharField(null=True, blank=True, max_length=128, verbose_name=_('URL'))
class Meta:
verbose_name = _('manufacturer')
verbose_name_plural = _('manufacturers')
def __str__(self): # pragma: no cover
return u'%s' % (self.name)
ManufacturerLogEntry = define_log_model(Manufacturer)