def subscription(self, feed, library=None): """Returns the subscription to the given content feed.""" if library is None: from feeds import FeedLibrary library = FeedLibrary() log.debug('Checking whether %s is subscribed to %s at %s' % (self, feed, library)) record = library.get_record(feed) try: subs = self.subscriptions.select_related() \ .filter(feed_record__feed_type=record.feed_type) if not subs: log.debug('No subscription record found with the name %s' % (record.feed_type,)) return None other_params = record.feed_params for sub in subs: self_params = sub.feed_record.feed_params log.debug('Checking parameters %r against %r' % (self_params, other_params)) if self_params == other_params: return sub except Subscription.DoesNotExist: return None
def subscribe(self, feed, library=None, commit=True): """Subscribe the user to a content feed.""" if library is None: from feeds import FeedLibrary library = FeedLibrary() record = library.get_record(feed) subscription = Subscription(subscriber=self, feed_record=record) if commit: subscription.save() return subscription