Esempio n. 1
0
def get_model_prefetch(content_model):
    """ Returns the fields that should be prefetched, for a generic relation """

    if hasattr(content_model, 'MTURK_PREFETCH'):
        return content_model.MTURK_PREFETCH
    else:
        # guess if there is no default
        prefetch = []
        if has_foreign_key(content_model, 'photo'):
            prefetch.append('photo')
        if has_foreign_key(content_model, 'shape'):
            prefetch.append('shape')
            prefetch.append('shape__photo')
        return prefetch
Esempio n. 2
0
def get_model_prefetch(content_model):
    """ Returns the fields that should be prefetched, for a generic relation """

    if hasattr(content_model, 'MTURK_PREFETCH'):
        return content_model.MTURK_PREFETCH
    else:
        # guess if there is no default
        prefetch = []
        if has_foreign_key(content_model, 'photo'):
            prefetch.append('photo')
        if has_foreign_key(content_model, 'shape'):
            prefetch.append('shape')
            prefetch.append('shape__photo')
        return prefetch
Esempio n. 3
0
def get_content_model_prefetch(content_model, content_attr='content'):
    """ Returns the fields that should be prefetched, for a relation that
    starts with '<content_attr>__'.  If the model has MTURK_PREFETCH, then that
    is used.  Otherwise, some common attributes are tested (photo, shape) and
    used if those foreign keys exist.  """

    if hasattr(content_model, 'MTURK_PREFETCH'):
        return ['%s__%s' % (content_attr, k)
                for k in content_model.MTURK_PREFETCH]
    else:
        # guess if there is no default
        prefetch = []
        if has_foreign_key(content_model, 'photo'):
            prefetch.append('%s__photo' % content_attr)
        if has_foreign_key(content_model, 'shape'):
            prefetch.append('%s__shape' % content_attr)
            prefetch.append('%s__shape__photo' % content_attr)
        return prefetch
Esempio n. 4
0
def get_content_model_prefetch(content_model, content_attr='content'):
    """ Returns the fields that should be prefetched, for a relation that
    starts with '<content_attr>__'.  If the model has MTURK_PREFETCH, then that
    is used.  Otherwise, some common attributes are tested (photo, shape) and
    used if those foreign keys exist.  """

    if hasattr(content_model, 'MTURK_PREFETCH'):
        return [
            '%s__%s' % (content_attr, k) for k in content_model.MTURK_PREFETCH
        ]
    else:
        # guess if there is no default
        prefetch = []
        if has_foreign_key(content_model, 'photo'):
            prefetch.append('%s__photo' % content_attr)
        if has_foreign_key(content_model, 'shape'):
            prefetch.append('%s__shape' % content_attr)
            prefetch.append('%s__shape__photo' % content_attr)
        return prefetch
Esempio n. 5
0
def update_changed_objects(changed_objects):
    """ This function is automatically called by
    mturk.tasks.mturk_update_votes_cubam_task
    with all objects that were changed by new votes.  """

    from photos.tasks import update_photos_num_shapes
    changed_photo_ids = [
        s.photo_id for s in changed_objects
        if has_foreign_key(s, 'photo')]
    update_photos_num_shapes(set(changed_photo_ids))
Esempio n. 6
0
def update_changed_objects(changed_objects):
    """ This function is automatically called by
    mturk.tasks.mturk_update_votes_cubam_task
    with all objects that were changed by new votes.  """

    from photos.tasks import update_photos_num_shapes
    changed_photo_ids = [
        s.photo_id for s in changed_objects if has_foreign_key(s, 'photo')
    ]
    update_photos_num_shapes(set(changed_photo_ids))
Esempio n. 7
0
def update_changed_objects(changed_objects):
    """ This function is automatically called by
    mturk.tasks.mturk_update_votes_cubam_task
    with all objects that were changed by new votes.  """

    # update shape entropy
    updated_shape_ids = set()
    for o in changed_objects:
        if has_foreign_key(o, 'shape'):
            if o.shape_id not in updated_shape_ids:
                updated_shape_ids.add(o.shape_id)
                o.shape.update_entropy()
Esempio n. 8
0
def update_changed_objects(changed_objects):
    """ This function is automatically called by
    mturk.tasks.mturk_update_votes_cubam_task
    with all objects that were changed by new votes.  """

    # update shape entropy
    updated_shape_ids = set()
    for o in changed_objects:
        if has_foreign_key(o, 'shape'):
            if o.shape_id not in updated_shape_ids:
                updated_shape_ids.add(o.shape_id)
                o.shape.update_entropy()