def copy_folder(folder,user): feeds, items = [], [] folderCopy = Folder(default_folder=True, user=user, name=folder.name) folderCopy.save() transaction.commit() for feed in folder.feeds: feedCopy = SubscriptionFeed(custom_name=None, rawfeed =feed.rawfeed, folder =folderCopy) feedCopy.save() feeds.append(feedCopy) transaction.commit() for feed in feeds: for item in feed.rawfeed.items: itemCopy = SubscriptionItem(read = False, clicked = False, raw_item = item, feed = feed) itemCopy.save() transaction.commit() return folderCopy
def _save_item(folder, raw_item, feed, items): item = SubscriptionItem() item.read = False item.clicked = False item.raw_item = raw_item item.feed = feed item.folder = folder try: item, created = SubscriptionItem.objects.get_or_create( raw_item=item.raw_item, defaults={'read': item.read, 'clicked': item.clicked, 'feed': item.feed, }) if not created: logging.debug("Item wasn't created: " + raw_item.__unicode__()) except MultipleObjectsReturned: _log_error(SubscriptionItem()) #TODO: Remove dup except DataError: _log_error(item) else: items.append(item) return items