コード例 #1
0
    def __init__(self, name, *args, **kwargs):
        # type: (str, *Any, **Any) -> None
        super(ModelEvent, self).__init__(name, **kwargs)
        self._kwargs = kwargs
        self._kwargs.pop('app', None)  # don't use app in __reduce__
        self._filterargs = args

        self.models = WeakSet()

        # initialize the filter fields: {field}__{op}
        self.filter_fields = {
            k: v for k, v in items(kwargs) if '__' in k
        }
        # optimization: Django: Transition operators require the unchanged
        # database fields before saving, a pre_save signal
        # handles this, but we want to avoid the extra database hit
        # when they are not in use.
        self.use_transitions = any('__now_' in k for k in keys(self.filter_fields))

        # _filterargs is set by __reduce__ to restore *args
        restored_args = kwargs.get('_filterargs') or ()
        self._init_attrs(**kwargs)
        self._filter_predicate = (
            Q(*args + restored_args, **self.filter_fields)
            if args or self.filter_fields else _true)
コード例 #2
0
 def wrapper(*args, **kwargs):
     try:
         return f(*args, **kwargs)
     except tuple(keys(defaults)) as e:
         if logger:
             logger.error(e)
         return next(
             d() if callable(d) else d
             for ex_type, d in items(defaults) if isinstance(e, ex_type)
         )
コード例 #3
0
ファイル: events.py プロジェクト: sambrin/thorn
    def __init__(self, name, *args, **kwargs):
        super(ModelEvent, self).__init__(name, **kwargs)
        self._kwargs = kwargs
        self._filterargs = args

        self.models = WeakSet()

        # initialize the filter fields: {field}__{op}
        self.filter_fields = {
            k: v for k, v in items(kwargs) if '__' in k
        }
        # optimization: Django: Transition operators require the unchanged
        # database fields before saving, a pre_save signal
        # handles this, but we want to avoid the extra database hit
        # when they are not in use.
        self.use_transitions = any(
            '__now_' in k for k in keys(self.filter_fields),
        )
        # _filterargs is set by __reduce__ to restore *args
        restored_args = kwargs.get('_filterargs') or ()
        self._init_attrs(**kwargs)
        self._filter_predicate = (
            Q(*args + restored_args, **self.filter_fields)
            if args or self.filter_fields else _true)
コード例 #4
0
ファイル: configcheck.py プロジェクト: celery/sphinx_celery
 def documented_settings(self):
     return {
         name for reftype, name in keys(
             self.app.env.domaindata['std']['objects'])
         if reftype == 'setting'
     }
コード例 #5
0
 def documented_settings(self):
     return {
         name
         for reftype, name in keys(self.app.env.domaindata['std']
                                   ['objects']) if reftype == 'setting'
     }