Example #1
0

cases_received.connect(handle_m4change_forms)


def handle_fixture_location_update(sender, doc, diff, backend, **kwargs):
    if doc.get('doc_type') == 'XFormInstance' and doc.get('domain') in M4CHANGE_DOMAINS:
        xform = XFormInstance.wrap(doc)
        if hasattr(xform, "xmlns") and xform.xmlns in ALL_M4CHANGE_FORMS:
            location_id = xform.form.get("location_id", None)
            if not location_id:
                return
            client = get_redis_client()
            redis_key = REDIS_FIXTURE_KEYS[xform.domain]
            redis_lock_key = REDIS_FIXTURE_LOCK_KEYS[xform.domain]
            lock = client.lock(redis_lock_key, timeout=5)
            if lock.acquire(blocking=True):
                try:
                    location_ids_str = client.get(redis_key)
                    location_ids = []
                    if location_ids_str:
                        location_ids = json.loads(location_ids_str)
                    if location_id not in location_ids:
                        location_ids.append(location_id)
                    client.set(redis_key, json.dumps(location_ids))
                finally:
                    release_lock(lock, True)


indicator_document_updated.connect(handle_fixture_location_update)
Example #2
0
import inspect
from django.db.models import signals
from django.utils.importlib import import_module
from ctable.fixtures import CtableMappingFixture
from fluff.signals import indicator_document_updated


def process_fluff_diff(sender, diff=None, **kwargs):
    from ctable.util import get_extractor
    from .util import get_backend_name_for_fluff_pillow
    backend_name = get_backend_name_for_fluff_pillow(diff['doc_type'])
    if diff and backend_name:
        get_extractor(backend_name).process_fluff_diff(diff, backend_name)

indicator_document_updated.connect(process_fluff_diff)


def catch_signal(app, **kwargs):
    app_name = app.__name__.rsplit('.', 1)[0]
    try:
        mod = import_module('.ctable_mappings', app_name)
        print "Creating CTable mappings for %s" % app_name

        clsmembers = inspect.getmembers(mod, inspect.isclass)
        mappings = [cls[1] for cls in clsmembers
                    if not cls[1] == CtableMappingFixture and issubclass(cls[1], CtableMappingFixture)]
        for mapping in mappings:
            mapping().create()
    except ImportError:
        pass