dddp/models.py
def get_meteor_ids(model, object_ids):
    """Return Alea ID mapping for all given ids of specified model."""
    # Django model._meta is now public API -> pylint: disable=W0212
    meta = model._meta
    result = collections.OrderedDict(
        (str(obj_pk), None)
        for obj_pk
        in object_ids
    )
    if isinstance(meta.pk, AleaIdField):
        # primary_key is an AleaIdField, use it.
        return collections.OrderedDict(
            (obj_pk, obj_pk) for obj_pk in object_ids
        )
    alea_unique_fields = [
        field
        for field in meta.local_fields
        if isinstance(field, AleaIdField) and field.unique and not field.null
    ]
    if len(alea_unique_fields) == 1:
        aid = alea_unique_fields[0].name
        query = model.objects.filter(
            pk__in=object_ids,
        ).values_list('pk', aid)
    else:
        content_type = ContentType.objects.get_for_model(model)
        query = ObjectMapping.objects.filter(
            content_type=content_type,
            object_id__in=list(result)
        ).values_list('object_id', 'meteor_id')
    for obj_pk, meteor_id in query:
        result[str(obj_pk)] = meteor_id
    for obj_pk, meteor_id in result.items():
        if meteor_id is None:
            result[obj_pk] = get_meteor_id(model, obj_pk)
    return result
def get_meteor_ids(model, object_ids):
    """Return Alea ID mapping for all given ids of specified model."""
    # Django model._meta is now public API -> pylint: disable=W0212
    meta = model._meta
    result = collections.OrderedDict(
        (str(obj_pk), None)
        for obj_pk
        in object_ids
    )
    if isinstance(meta.pk, AleaIdField):
        # primary_key is an AleaIdField, use it.
        return collections.OrderedDict(
            (obj_pk, obj_pk) for obj_pk in object_ids
        )
    alea_unique_fields = [
        field
        for field in meta.local_fields
        if isinstance(field, AleaIdField) and field.unique and not field.null
    ]
    if len(alea_unique_fields) == 1:
        aid = alea_unique_fields[0].name
        query = model.objects.filter(
            pk__in=object_ids,
        ).values_list('pk', aid)
    else:
        content_type = ContentType.objects.get_for_model(model)
        query = ObjectMapping.objects.filter(
            content_type=content_type,
            object_id__in=list(result)
        ).values_list('object_id', 'meteor_id')
    for obj_pk, meteor_id in query:
        result[str(obj_pk)] = meteor_id
    for obj_pk, meteor_id in result.items():
        if meteor_id is None:
            result[obj_pk] = get_meteor_id(model, obj_pk)
    return result
def get_meteor_ids ( model , object_ids ) : # Django model._meta is now public API -> pylint: disable=W0212 meta = model . _meta result = collections . OrderedDict ( ( str ( obj_pk ) , None ) for obj_pk in object_ids ) if isinstance ( meta . pk , AleaIdField ) : # primary_key is an AleaIdField, use it. return collections . OrderedDict ( ( obj_pk , obj_pk ) for obj_pk in object_ids ) alea_unique_fields = [ field for field in meta . local_fields if isinstance ( field , AleaIdField ) and field . unique and not field . null ] if len ( alea_unique_fields ) == 1 : aid = alea_unique_fields [ 0 ] . name query = model . objects . filter ( pk__in = object_ids , ) . values_list ( 'pk' , aid ) else : content_type = ContentType . objects . get_for_model ( model ) query = ObjectMapping . objects . filter ( content_type = content_type , object_id__in = list ( result ) ) . values_list ( 'object_id' , 'meteor_id' ) for obj_pk , meteor_id in query : result [ str ( obj_pk ) ] = meteor_id for obj_pk , meteor_id in result . items ( ) : if meteor_id is None : result [ obj_pk ] = get_meteor_id ( model , obj_pk ) return result
Return Alea ID mapping for all given ids of specified model.
Return Alea ID mapping for all given ids of specified model .