• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python analog.define_log_model函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shuup.utils.analog.define_log_model函数的典型用法代码示例。如果您正苦于以下问题:Python define_log_model函数的具体用法?Python define_log_model怎么用?Python define_log_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了define_log_model函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:suutari,项目名称:shoop,代码行数:8,代码来源:test_analog.py


示例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)
开发者ID:NamiStudio,项目名称:shuup,代码行数:8,代码来源:test_analog.py


示例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)
开发者ID:gurch101,项目名称:shuup,代码行数:18,代码来源:test_analog.py


示例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)
开发者ID:suutari-ai,项目名称:shuup,代码行数:30,代码来源:_shipments.py


示例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)
开发者ID:shawnadelic,项目名称:shuup,代码行数:27,代码来源:_supplied_products.py


示例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)
开发者ID:shawnadelic,项目名称:shuup,代码行数:29,代码来源:_payments.py


示例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)
开发者ID:suutari,项目名称:shoop,代码行数:29,代码来源:_service_shipping.py


示例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)
开发者ID:shawnadelic,项目名称:shuup,代码行数:29,代码来源:_taxes.py


示例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
开发者ID:dragonsg,项目名称:shuup-1,代码行数:30,代码来源:_orders.py


示例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)
开发者ID:gurch101,项目名称:shuup,代码行数:30,代码来源:campaigns.py


示例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)
开发者ID:suutari,项目名称:shoop,代码行数:29,代码来源:_product_media.py


示例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)
开发者ID:suutari,项目名称:shoop,代码行数:29,代码来源:_order_lines.py


示例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)
开发者ID:ruqaiya,项目名称:shuup,代码行数:29,代码来源:_currencies.py


示例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)
开发者ID:ruqaiya,项目名称:shuup,代码行数:30,代码来源:models.py


示例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)
开发者ID:shawnadelic,项目名称:shuup,代码行数:30,代码来源:_manufacturers.py


示例16: soft_delete

    def soft_delete(self, user=None):
        if not self.status == CategoryStatus.DELETED:
            for shop_product in self.primary_shop_products.all():
                shop_product.categories.remove(self)
                shop_product.primary_category = None
                shop_product.save()
            for shop_product in self.shop_products.all():
                shop_product.categories.remove(self)
                shop_product.primary_category = None
                shop_product.save()
            for child in self.children.all():
                child.parent = None
                child.save()
            self.status = CategoryStatus.DELETED
            self.add_log_entry("Deleted.", kind=LogEntryKind.DELETION, user=user)
            self.save()
            category_deleted.send(sender=type(self), category=self)

    def save(self, *args, **kwargs):
        rv = super(Category, self).save(*args, **kwargs)
        generate_multilanguage_slugs(self, self._get_slug_name)

        # bump children cache
        from shuup.core import cache
        cache.bump_version("category_cached_children")

        return rv


CategoryLogEntry = define_log_model(Category)
开发者ID:ruqaiya,项目名称:shuup,代码行数:30,代码来源:_categories.py


示例17: TranslatedFields

    translations = TranslatedFields(
        name=models.CharField(max_length=64, verbose_name=_("name")),
        public_name=models.CharField(max_length=64, verbose_name=_("public name")),
        maintenance_message=models.CharField(max_length=300, blank=True, verbose_name=_("maintenance message"))
    )

    def __str__(self):
        return self.safe_translation_getter("name", default="Shop %d" % self.pk)

    def create_price(self, value):
        """
        Create a price with given value and settings of this shop.

        Takes the ``prices_include_tax`` and ``currency`` settings of
        this Shop into account.

        :type value: decimal.Decimal|int|str
        :rtype: shuup.core.pricing.Price
        """
        if self.prices_include_tax:
            return TaxfulPrice(value, self.currency)
        else:
            return TaxlessPrice(value, self.currency)

    def _are_changes_protected(self):
        return Order.objects.filter(shop=self).exists()


ShopLogEntry = define_log_model(Shop)
开发者ID:shawnadelic,项目名称:shuup,代码行数:29,代码来源:_shops.py


示例18: EnumIntegerField

    """
    owner = models.ForeignKey("Contact", on_delete=models.CASCADE, verbose_name=_("owner"))
    address = models.ForeignKey(
        MutableAddress, verbose_name=_('address'),
        related_name="saved_addresses", on_delete=models.CASCADE)
    role = EnumIntegerField(SavedAddressRole, verbose_name=_('role'), default=SavedAddressRole.SHIPPING)
    status = EnumIntegerField(SavedAddressStatus, default=SavedAddressStatus.ENABLED, verbose_name=_('status'))
    title = models.CharField(max_length=255, blank=True, verbose_name=_('title'))
    objects = SavedAddressManager()

    class Meta:
        verbose_name = _('saved address')
        verbose_name_plural = _('saved addresses')
        ordering = ("owner_id", "role", "title")

    def __str__(self):
        return u"%s" % self.get_title()

    def get_title(self):
        """
        Returns the display title for this `SavedAddress` instance. Defaults
        to a short representation of the address.

        This method should be used instead of accessing the `title` field
        directly when displaying `SavedAddress` objects.
        """
        return self.title.strip() if self.title else six.text_type(self.address)


SavedAddressLogEntry = define_log_model(SavedAddress)
开发者ID:shawnadelic,项目名称:shuup,代码行数:30,代码来源:_addresses.py


示例19: get_all_package_children

            ProductPackageLink.objects.filter(child=self).values_list("parent", flat=True)
        ))

    def get_all_package_children(self):
        return Product.objects.filter(pk__in=(
            ProductPackageLink.objects.filter(parent=self).values_list("child", flat=True)
        ))

    def get_public_media(self):
        return self.media.filter(enabled=True, public=True)

    def is_stocked(self):
        return (self.stock_behavior == StockBehavior.STOCKED)


ProductLogEntry = define_log_model(Product)


class ProductCrossSell(models.Model):
    product1 = models.ForeignKey(
        Product, related_name="cross_sell_1", on_delete=models.CASCADE, verbose_name=_("primary product"))
    product2 = models.ForeignKey(
        Product, related_name="cross_sell_2", on_delete=models.CASCADE, verbose_name=_("secondary product"))
    weight = models.IntegerField(default=0, verbose_name=_("weight"))
    type = EnumIntegerField(ProductCrossSellType, verbose_name=_("type"))

    class Meta:
        verbose_name = _('cross sell link')
        verbose_name_plural = _('cross sell links')

开发者ID:ahmadzai,项目名称:shuup,代码行数:29,代码来源:_products.py


示例20: _

    class Meta:
        verbose_name = _("custom payment processor")
        verbose_name_plural = _("custom payment processors")

    def get_service_choices(self):
        return [
            ServiceChoice('manual', _("Manually processed payment")),
            ServiceChoice('cash', _("Cash payment"))
        ]

    def _create_service(self, choice_identifier, **kwargs):
        service = super(CustomPaymentProcessor, self)._create_service(
            choice_identifier, **kwargs)
        if choice_identifier == 'cash':
            service.behavior_components.add(
                StaffOnlyBehaviorComponent.objects.create())
        return service

    def process_payment_return_request(self, service, order, request):
        if service == 'cash':
            if not order.is_paid():
                order.create_payment(
                    order.taxful_total_price,
                    payment_identifier="Cash-%s" % now().isoformat(),
                    description="Cash Payment"
                )


PaymentMethodLogEntry = define_log_model(PaymentMethod)
PaymentProcessorLogEntry = define_log_model(PaymentProcessor)
开发者ID:suutari,项目名称:shoop,代码行数:30,代码来源:_service_payment.py



注:本文中的shuup.utils.analog.define_log_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python i18n.format_money函数代码示例发布时间:2022-05-27
下一篇:
Python utils.apply_request_middleware函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap