当前位置: 首页>>代码示例>>Python>>正文


Python ErrorDict.setdefault方法代码示例

本文整理汇总了Python中django.forms.util.ErrorDict.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorDict.setdefault方法的具体用法?Python ErrorDict.setdefault怎么用?Python ErrorDict.setdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms.util.ErrorDict的用法示例。


在下文中一共展示了ErrorDict.setdefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RentalReservationLineEditItemForm

# 需要导入模块: from django.forms.util import ErrorDict [as 别名]
# 或者: from django.forms.util.ErrorDict import setdefault [as 别名]
class RentalReservationLineEditItemForm(forms.ModelForm):
    class Meta:
        model = RentalReservationLineItem
        fields = ("product", "qty")

    def clean_qty(self):
        qty = self.cleaned_data.get("qty")
        if qty <= 0:
            raise ValidationError("Reservation qty must be greater than 0")
        return qty

    def validate_qty(self, facility, start_time, end_time):
        qty = self.instance.qty
        product = self.instance.product
        # if form corresponds to existing ReservationLineItem being changed, get previous scheduled_adjustment_id
        existing_adjustment_id = self.instance.pk or None
        # have to ignore previous scheduled_adjustment qty when determining if sufficient inventory exists
        min_inventory_during_reservation = \
            facility.get_min_expected_inventory_in_interval(product.id,
                                                            start_time,
                                                            end_time,
                                                            scheduled_adjustment_exclude_id=existing_adjustment_id)
        if min_inventory_during_reservation - qty < 0:
            if not self._errors:
                self._errors = ErrorDict()
            qty_errors = self._errors.setdefault("qty", ErrorList())
            expanded_search_buffer = timedelta(hours=5)
            inventory_search_start = start_time - expanded_search_buffer
            inventory_search_end = end_time + expanded_search_buffer
            expected_inventory_url = expected_inventory_url_with_querystring(product, facility, inventory_search_start, inventory_search_end)
            error_message = mark_safe("Only expected to have {} available at reservation time. Want to <a href='{}' target='_blank'>check</a> when more will be available?".format(min_inventory_during_reservation, expected_inventory_url))
            qty_errors.append(error_message)
开发者ID:tombnorwood,项目名称:maui,代码行数:34,代码来源:forms.py


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