def to_lock_json(lock, add_remove=LockCache.LOCK_ADD):
    if (getattr(lock.locked_item, 'downcast', None) and callable(lock.locked_item.downcast)):
        item = lock.locked_item.downcast()
    else:
        item = lock.locked_item
    return {'job_id': lock.job.id, 'content_type_id': ContentType.objects.get_for_model(item).id, 'item_id': lock.locked_item.id, 'uuid': lock.uuid, 'description': lock.job.description(), 'lock_type': ('write' if lock.write else 'read'), 'action': ('add' if (add_remove == LockCache.LOCK_ADD) else 'remove')}
def to_lock_json(lock, add_remove=LockCache.LOCK_ADD):
    if (getattr(lock.locked_item, 'downcast', None) and callable(lock.locked_item.downcast)):
        item = lock.locked_item.downcast()
    else:
        item = lock.locked_item
    return {'job_id': lock.job.id, 'content_type_id': ContentType.objects.get_for_model(item).id, 'item_id': lock.locked_item.id, 'uuid': lock.uuid, 'description': lock.job.description(), 'lock_type': ('write' if lock.write else 'read'), 'action': ('add' if (add_remove == LockCache.LOCK_ADD) else 'remove')}