Exemplo n.º 1
0
    def format_entry_for_adn(self, entry, for_publish=False):
        posts = []
        if (not self.channel_id or (self.channel_id and self.publish_to_stream)):
            if for_publish and not entry.published_post or not for_publish:
                post = yield format_for_adn(self, entry)
                posts += [(post, 'post')]

        if self.channel_id and not entry.published_channel:
            if for_publish and not entry.published_channel or not for_publish:
                post = broadcast_format_for_adn(self, entry)
                posts += [(post, 'channel')]

        raise ndb.Return(posts)
Exemplo n.º 2
0
    def format_entry_for_adn(self, entry, for_publish=False):
        posts = []
        if (not self.channel_id
                or (self.channel_id and self.publish_to_stream)):
            if for_publish and not entry.published_post or not for_publish:
                post = yield format_for_adn(self, entry)
                posts += [(post, 'post')]

        if self.channel_id and not entry.published_channel:
            if for_publish and not entry.published_channel or not for_publish:
                post = broadcast_format_for_adn(self, entry)
                posts += [(post, 'channel')]

        raise ndb.Return(posts)
Exemplo n.º 3
0
    def to_json(self, feed=None, format=False):
        include = ['title', 'link', 'published', 'published_at', 'added']
        data = {}
        for attr in include:
            data[attr] = getattr(self, attr, None)

        for dt in ['published_at', 'added_at']:
            if data.get(dt):
                data['%s_in_secs' % (dt)] = time.mktime(data[dt].timetuple())
                data[dt] = format_date(data[dt])

        if self.overflow:
            data['overflow_reason'] = OVERFLOW_REASON.for_display(
                self.overflow_reason)

        if self.key:
            data['id'] = self.key.urlsafe()

        feed = feed or self.key.parent().get()
        if format:
            data['html'] = {}
            for post, kind in feed.format_entry_for_adn(self).get_result():
                data['html'][kind] = build_html_from_post(post)

            if feed and feed.channel_id:
                data['alert'] = broadcast_format_for_adn(feed, self)

            width = None
            height = None
            if feed.include_thumb and self.thumbnail_image_url:
                data['thumbnail_image_url'] = self.thumbnail_image_url
                width = self.thumbnail_image_width
                height = self.thumbnail_image_height

            if feed.include_video and self.video_oembed:
                data['thumbnail_image_url'] = self.video_oembed[
                    'thumbnail_url']
                width = self.video_oembed['thumbnail_width']
                height = self.video_oembed['thumbnail_height']

            if width and height:
                width, height = fit_to_box(width, height, 100, 100)
                data['thumbnail_image_width'] = width
                data['thumbnail_image_height'] = height

        return data
Exemplo n.º 4
0
    def to_json(self, feed=None, format=False):
        include = ['title', 'link', 'published', 'published_at', 'added']
        data = {}
        for attr in include:
            data[attr] = getattr(self, attr, None)

        for dt in ['published_at', 'added_at']:
            if data.get(dt):
                data['%s_in_secs' % (dt)] = time.mktime(data[dt].timetuple())
                data[dt] = format_date(data[dt])

        if self.overflow:
            data['overflow_reason'] = OVERFLOW_REASON.for_display(self.overflow_reason)

        if self.key:
            data['id'] = self.key.urlsafe()

        feed = feed or self.key.parent().get()
        if format:
            data['html'] = {}
            for post, kind in feed.format_entry_for_adn(self).get_result():
                data['html'][kind] = build_html_from_post(post)

            if feed and feed.channel_id:
                data['alert'] = broadcast_format_for_adn(feed, self)

            width = None
            height = None
            if feed.include_thumb and self.thumbnail_image_url:
                data['thumbnail_image_url'] = self.thumbnail_image_url
                width = self.thumbnail_image_width
                height = self.thumbnail_image_height

            if feed.include_video and self.video_oembed:
                data['thumbnail_image_url'] = self.video_oembed['thumbnail_url']
                width = self.video_oembed['thumbnail_width']
                height = self.video_oembed['thumbnail_height']

            if width and height:
                width, height = fit_to_box(width, height, 100, 100)
                data['thumbnail_image_width'] = width
                data['thumbnail_image_height'] = height

        return data
Exemplo n.º 5
0
    def _immediate_publish(self, entry, in_transaction=False):
        if (self.feed.publish_to_stream or not self.feed.channel_id) and (not entry.published_post or self.ignore_publish_state):
            entry.published_post = True
            data = yield format_for_adn(self.feed, entry)
            path = 'posts'
            deferred.defer(publish_to_api, entry.key.urlsafe(), self.feed.key.urlsafe(), path, data,
                           self.user.access_token, _transactional=in_transaction, _retry_options=api_publish_opts,
                           _target='backend', _url='/api/backend/deferred/task')

        if self.feed.channel_id and (not entry.published_channel or self.ignore_publish_state):
            entry.published_channel = True
            data = broadcast_format_for_adn(self.feed, entry)
            path = 'channels/%s/messages' % self.feed.channel_id
            deferred.defer(publish_to_api, entry.key.urlsafe(), self.feed.key.urlsafe(), path, data,
                           self.user.access_token, _transactional=in_transaction, _retry_options=api_publish_opts,
                           _target='backend', _url='/api/backend/deferred/task')

        entry.published = True
        entry.published_at = datetime.now()
        yield entry.put_async()