Example #1
0
    def subscription(self, feed, library=None):
        """Returns the subscription to the given content feed."""
        if library is None:
            from feeds import ContentFeedLibrary
            library = ContentFeedLibrary()

        log.debug('Checking whether %s is subscribed to %s at %s' %
                  (self, feed, library))

        record = library.get_record(feed)
        try:
            subs = filter(
                lambda sub: sub.feed_record.feed_name == record.feed_name,
                self.preloaded_subscriptions(library))

            if not subs:
                log.debug('No subscription record found with the name %s' %
                          (record.feed_name, ))
                return None

            other_params = [(p.name, p.value)
                            for p in record.feed_params.all()]
            for sub in subs:
                self_params = other_params[:]
                log.debug('Checking parameters %r against %r' %
                          (self_params, other_params))
                if self_params == other_params:
                    return sub

        except Subscription.DoesNotExist:
            return None
Example #2
0
    def subscription(self, feed, library=None):
        """Returns the subscription to the given content feed."""
        if library is None:
            from feeds import ContentFeedLibrary
            library = ContentFeedLibrary()

        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_name=record.feed_name)

            if not subs:
                log.debug('No subscription record found with the name %s' %
                          (record.feed_name,))
                return None

            other_params = list(record.feed_params.values('name', 'value'))
            for sub in subs:
                self_params = list(sub.feed_record.feed_params.values('name', 'value'))
                log.debug('Checking parameters %r against %r' %
                          (self_params, other_params))
                if self_params == other_params:
                    return sub

        except Subscription.DoesNotExist:
            return None
Example #3
0
    def subscription(self, feed, library=None):
        """Returns the subscription to the given content feed."""
        if library is None:
            from feeds import ContentFeedLibrary
            library = ContentFeedLibrary()

        log.debug('Checking whether %s is subscribed to %s at %s' %
                  (self, feed, library))

        record = library.get_record(feed)
        try:
            subs = filter(
                lambda sub: sub.feed_record.feed_name == record.feed_name,
                self.preloaded_subscriptions(library)
            )

            if not subs:
                log.debug('No subscription record found with the name %s' %
                          (record.feed_name,))
                return None

            other_params = [(p.name, p.value) for p in record.feed_params.all()]
            for sub in subs:
                self_params = [(p.name, p.value) for p in sub.feed_record.feed_params.all()]
                log.debug('Checking parameters %r against %r' %
                          (self_params, other_params))
                if self_params == other_params:
                    return sub

        except Subscription.DoesNotExist:
            return None
Example #4
0
    def subscribe(self, feed, library=None, commit=True):
        """Subscribe the user to a content feed."""
        if library is None:
            from feeds import ContentFeedLibrary
            library = ContentFeedLibrary()

        record = library.get_record(feed)
        subscription = Subscription(subscriber=self, feed_record=record)
        if commit:
            subscription.save()
        return subscription
Example #5
0
    def subscribe(self, feed, library=None, commit=True):
        """Subscribe the user to a content feed."""
        if library is None:
            from feeds import ContentFeedLibrary
            library = ContentFeedLibrary()

        record = library.get_record(feed)
        subscription = Subscription(subscriber=self, feed_record=record)
        if commit:
            subscription.save()
        return subscription