Exemple #1
0
def immediate_add(bucket, item, context, notify=True):
    """
    immediately commit the addition of an item to the 
    specified bucket to the database.
    
    if notify is False, it is the caller's responsibility to 
    issue notification of *successful* additions.
    
    note, this will clobber any unsaved changes in the 
    bucket for this item.
    """
    if isinstance(item, basestring):
        item = NewsItemRef.create_from_info(context, bucket.id, item_id=item)
    elif isinstance(item, NewsItem) or isinstance(item, NewsItemRef):
        item = NewsItemRef.create_from_item(context, bucket.id, item)
    else:
        item = NewsItemRef.create_from_info(context, bucket.id, **item)

    current_item = NewsItemRef.get(item.id, context)
    if current_item is None:
        current_item = item
    elif item.timestamp is None or item.timestamp <= current_item.timestamp:
        return False
    else:
        current_item.update_from(item)
    
    try:
        current_item.save()
        bucket._clobber(current_item)        
        
        if notify:
            notify_bucket_modified(bucket, context, updated_items=[current_item.unwrap()])

        return True
    except ResourceConflict:
        return False
Exemple #2
0
 def _send_modified_event(self, *args, **kw):
     notify_bucket_modified(self, self._context, **kw)