Пример #1
0
    def __call__(self, entity, user):
        is_hidden = FieldsConfig.objects.get_for_model(
            entity.__class__).is_fieldname_hidden

        if is_hidden('estimated_sales'):
            return FunctionFieldResult(
                gettext('Error: «Estimated sales» is hidden'))

        if is_hidden('chance_to_win'):
            return FunctionFieldResult(
                gettext(r'Error: «% of chance to win» is hidden'))

        return self.result_type((entity.estimated_sales or 0) *
                                (entity.chance_to_win or 0) / 100.0)
Пример #2
0
    def __call__(self, entity, user):
        # cache = getattr(entity, '_alerts_cache', None)
        #
        # if cache is None:
        #     cache = entity._alerts_cache = list(Alert.objects
        #                                              .filter(entity_id=entity.id, is_validated=False)
        #                                              .order_by('trigger_date')
        #                                              .values_list('title', flat=True)
        #                                        )
        #
        # return FunctionFieldResultsList(FunctionFieldResult(title) for title in cache)
        cache = self._cache
        e_id = entity.id
        cached = cache.get(e_id)

        if cached is None:
            cached = cache[e_id] = [
                *Alert.objects.filter(
                    entity_id=e_id,
                    is_validated=False).order_by('trigger_date').values_list(
                        'title', flat=True)
            ]

        return FunctionFieldResultsList(
            FunctionFieldResult(title) for title in cached)
Пример #3
0
    def __call__(self, entity, user):
        e_cache = self._cache[entity.id]
        total = e_cache.get(user.id)

        if total is None:
            total = e_cache[user.id] = self.single_func()(entity, user)

        return (FunctionFieldDecimal(total)
                if isinstance(total, Decimal) else FunctionFieldResult(total))
Пример #4
0
    def __call__(self, entity, user):
        cache = getattr(entity, '_memos_cache', None)

        if cache is None:
            cache = entity._memos_cache = list(
                Memo.objects.filter(entity_id=entity.id).order_by(
                    '-creation_date').values_list('content', flat=True))

        return FunctionFieldResultsList(
            FunctionFieldResult(content) for content in cache)
Пример #5
0
    def __call__(self, entity, user):
        cache = getattr(entity, '_todos_cache', None)

        if cache is None:
            cache = entity._todos_cache = list(
                ToDo.objects.filter(
                    entity_id=entity.id,
                    is_ok=False).order_by('-creation_date').values_list(
                        'title', flat=True))

        return FunctionFieldResultsList(
            FunctionFieldResult(title) for title in cache)
Пример #6
0
    def __call__(self, entity, user):
        cache = getattr(entity, '_alerts_cache', None)

        if cache is None:
            cache = entity._alerts_cache = list(
                Alert.objects.filter(
                    entity_id=entity.id,
                    is_validated=False).order_by('trigger_date').values_list(
                        'title', flat=True))

        return FunctionFieldResultsList(
            FunctionFieldResult(title) for title in cache)
Пример #7
0
    def __call__(self, entity, user):
        cache = self._cache
        e_id = entity.id
        cached = cache.get(e_id)

        if cached is None:
            cached = cache[e_id] = [
                *Memo.objects.filter(entity_id=entity.id).order_by(
                    '-creation_date').values_list('content', flat=True)
            ]

        return FunctionFieldResultsList(
            FunctionFieldResult(content) for content in cached)
Пример #8
0
    def __call__(self, entity, user):
        cache = self._cache
        e_id = entity.id
        cached = cache.get(e_id)

        if cached is None:
            cached = cache[e_id] = [
                *ToDo.objects.filter(
                    entity_id=entity.id,
                    is_ok=False).order_by('-creation_date').values_list(
                        'title', flat=True)
            ]

        return FunctionFieldResultsList(
            FunctionFieldResult(title) for title in cached)
    def __call__(self, entity, user):
        # total = None
        # cache_attr = self.cache_attr
        # cache = getattr(entity, cache_attr, None)
        #
        # if cache is None:
        #     cache = {}
        #     setattr(entity, cache_attr, cache)
        # else:
        #     total = cache.get(user.id)
        #
        # if total is None:
        #     total = cache[user.id] = self.single_func()(entity, user)
        e_cache = self._cache[entity.id]
        total = e_cache.get(user.id)

        if total is None:
            total = e_cache[user.id] = self.single_func()(entity, user)

        # return FunctionFieldDecimal(total)
        return (FunctionFieldDecimal(total)
                if isinstance(total, Decimal) else FunctionFieldResult(total))
Пример #10
0
 def __call__(self, entity, user):
     return FunctionFieldResult(entity.phone or entity.mobile)