Example #1
0
    def __call__(self, item, context=None):
        return _datetime_now()

    def __str__(self):
        return "datetime.now"


class BooleanChoiceQuestion(JsonObject):
    type = TypeProperty('icds_boolean')
    boolean_property = DefaultProperty(required=True)
    true_values = ListProperty(required=True)
    false_values = ListProperty(required=True)
    nullable = BooleanProperty(default=True)


icds_ucr_quickcache = get_django_quickcache(memoize_timeout=60,
                                            timeout=60 * 60)


@icds_ucr_quickcache(('user_id', ))
def _get_user_location_id(user_id):
    user = CommCareUser.get_db().get(user_id)
    return user.get('user_data', {}).get('commcare_location_id')


class ICDSUserLocation(JsonObject):
    """Heavily cached expression to reduce queries to Couch
    """
    type = TypeProperty('icds_user_location')
    user_id_expression = DefaultProperty(required=True)

    def configure(self, user_id_expression):
Example #2
0
from quickcache.django_quickcache import get_django_quickcache

quickcache = get_django_quickcache(memoize_timeout=10, timeout=5 * 60)
Example #3
0
        if request:
            session_id = str(id(get_request()))
        else:
            session_id = None

    if session_id:
        session_id = session_id.encode('utf-8')
        # hash it so that similar numbers end up very different (esp. because we're truncating)
        return hashlib.md5(session_id).hexdigest()[:7]
    else:
        # quickcache catches this and skips the cache
        # this happens during tests (outside a fake task/request context)
        # and during management commands
        raise ForceSkipCache("Not part of a session")


quickcache = get_django_quickcache(timeout=5 * 60, memoize_timeout=10,
                                   assert_function=quickcache_soft_assert,
                                   session_function=get_session_key)


def skippable_quickcache(*args, **kwargs):
    warnings.warn(
        "skippable_quickcache is deprecated. Use quickcache with skip_arg instead.",
        DeprecationWarning
    )
    return quickcache(*args, **kwargs)


__all__ = ['quickcache', 'skippable_quickcache']
Example #4
0
from __future__ import absolute_import
from __future__ import unicode_literals
import warnings
from quickcache.django_quickcache import get_django_quickcache

from corehq.util.soft_assert import soft_assert

quickcache_soft_assert = soft_assert(
    notify_admins=True,
    fail_if_debug=False,
    skip_frames=5,
)

quickcache = get_django_quickcache(timeout=5 * 60,
                                   memoize_timeout=10,
                                   assert_function=quickcache_soft_assert)


def skippable_quickcache(*args, **kwargs):
    warnings.warn(
        "skippable_quickcache is deprecated. Use quickcache with skip_arg instead.",
        DeprecationWarning)
    return quickcache(*args, **kwargs)


__all__ = ['quickcache', 'skippable_quickcache']
from quickcache.django_quickcache import get_django_quickcache

quickcache = get_django_quickcache(timeout=5 * 60, memoize_timeout=10)


@quickcache(['person.id'], skip_arg='strict', timeout=60 * 60)
def get_all_posts(person, strict=False):
    return Post.objects.filter(person=person).all()