Exemplo n.º 1
0
Arquivo: rss.py Projeto: Havvy/madcow
    def rss_tree(self):
        """Build the RSS tree"""
        rss = xml.TreeBuilder('rss', version='2.0', nsmap=self.nsmap)

        with rss.child('channel'):
            rss.add('link', self.link)
            rss.add('title', self.title)
            rss.add('description', self.desc)
            rss.add('language', self.language)
            rss.add('copyright', self.copyright)
            rss.add('managingEditor', self.editor)
            rss.add('webMaster', self.webmaster)
            rss.add('pubDate', self.published.rfc822format())
            rss.add('lastBuildDate', self.build_date.rfc822format())
            rss.add('generator', self.generator)
            rss.add('docs', self.docs)
            rss.add('ttl', self.ttl)

            for category in self.categories:
                rss.add('category', category.name, domain=category.domain)

            if self.image is not None:
                with rss.child('image'):
                    rss.add('url', self.image.url)
                    rss.add('title', self.image.title or self.title)
                    rss.add('link', self.image.link or self.link)
                    rss.add('width', self.image.width)
                    rss.add('height', self.image.height)

            if self.add_atom and self.rss_url:
                rss.add('atom:link', rel='self', type='application/rss+xml', href=self.rss_url)

            for item in self:
                published = self.published if item.published is None else tzdatetime.new(item.published)
                with rss.child('item'):
                    rss.add('link', item.link)
                    rss.add('title', item.title)
                    rss.add('description', item.desc)
                    rss.add('author', item.author)
                    rss.add('comments', item.comments)
                    rss.add('guid', item.guid, isPermaLink='false')
                    rss.add('pubDate', published.rfc822format())

                    for category in item.categories:
                        rss.add('category', category.name, domain=category.domain)

                    if self.add_dc:
                        rss.add('dc:title', item.title)
                        rss.add('dc:creator', item.author)
                        rss.add('dc:language', self.language)
                        rss.add('dc:rights', self.copyright)
                        rss.add('dc:date', published.isoformat())
                        rss.add('dc:format', item.content_type)
                        rss.add('dc:identifier', item.guid)

        for stylesheet in self.stylesheets:
            rss.add_pi('xml-stylesheet', **stylesheet.__dict__)

        return rss
Exemplo n.º 2
0
 def guid(self):
     """Global unique identifier for this object"""
     id = first([getattr(self, key, None) for key in ('publish_id', 'external_id', 'id')])
     date = first([getattr(self, key, None) for key in ('published', 'activation_date', 'created', 'modified')])
     date = tzdatetime.new(date).utc
     meta = type(self)._meta
     return 'tag:%s,%s:/%s/%s/%d/%d' % (current_site.domain, date.strftime('%Y-%m-%d'), meta.app_label,
                                        meta.object_name.lower(), id, date.unixtime)
Exemplo n.º 3
0
 def guid(self):
     """Global unique identifier for this object"""
     id = first([getattr(self, key, None) for key in ('publish_id', 'external_id', 'id')])
     date = first([getattr(self, key, None) for key in ('published', 'activation_date', 'created', 'modified')])
     date = tzdatetime.new(date).utc
     meta = type(self)._meta
     return 'tag:%s,%s:/%s/%s/%d/%d' % (current_site.domain, date.strftime('%Y-%m-%d'), meta.app_label,
                                        meta.object_name.lower(), id, date.unixtime)
Exemplo n.º 4
0
 def __init__(self,
              link,
              title=None,
              desc=None,
              language=None,
              copyright=None,
              rss_url=None,
              editor=None,
              webmaster=None,
              published=None,
              build_date=None,
              categories=None,
              generator=None,
              docs=None,
              ttl=None,
              image=None,
              stylesheets=None,
              add_atom=False,
              add_dc=False,
              extra_namespaces=None):
     self.link = link
     self.title = title or self.link
     self.desc = desc or self.title
     self.language = language or DEFAULT_LANGUAGE
     self.copyright = copyright
     self.rss_url = rss_url
     self.editor = editor
     self.webmaster = webmaster
     self.published = tzdatetime.new(published)
     self.build_date = self.published if build_date is None else tzdatetime.new(
         build_date)
     self.categories = categories or []
     self.generator = generator or DEFAULT_GENERATOR
     self.docs = docs or DEFAULT_DOCS
     self.ttl = ttl
     self.image = image
     self.stylesheets = stylesheets or []
     self.add_atom = add_atom
     self.add_dc = add_dc
     self.extra_namespaces = extra_namespaces
Exemplo n.º 5
0
Arquivo: rss.py Projeto: Havvy/madcow
 def __init__(self, link, title=None, desc=None, language=None, copyright=None, rss_url=None,
              editor=None, webmaster=None, published=None, build_date=None, categories=None,
              generator=None, docs=None, ttl=None, image=None, stylesheets=None, add_atom=False,
              add_dc=False, extra_namespaces=None):
     self.link = link
     self.title = title or self.link
     self.desc = desc or self.title
     self.language = language or DEFAULT_LANGUAGE
     self.copyright = copyright
     self.rss_url = rss_url
     self.editor = editor
     self.webmaster = webmaster
     self.published = tzdatetime.new(published)
     self.build_date = self.published if build_date is None else tzdatetime.new(build_date)
     self.categories = categories or []
     self.generator = generator or DEFAULT_GENERATOR
     self.docs = docs or DEFAULT_DOCS
     self.ttl = ttl
     self.image = image
     self.stylesheets = stylesheets or []
     self.add_atom = add_atom
     self.add_dc = add_dc
     self.extra_namespaces = extra_namespaces
Exemplo n.º 6
0
Arquivo: xml.py Projeto: Havvy/madcow
 def add_time(self, name, dt=None, **kwargs):
     """Add a datetime object serialized as UNIX epochal time"""
     val = tzdatetime.new(dt)
     kwargs.setdefault('type', 'time')
     kwargs.setdefault('format', 'unix')
     return self.add(name, val.unixtime, **kwargs)
Exemplo n.º 7
0
 def add_time(self, name, dt=None, **kwargs):
     """Add a datetime object serialized as UNIX epochal time"""
     val = tzdatetime.new(dt)
     kwargs.setdefault('type', 'time')
     kwargs.setdefault('format', 'unix')
     return self.add(name, val.unixtime, **kwargs)
Exemplo n.º 8
0
    def rss_tree(self):
        """Build the RSS tree"""
        rss = xml.TreeBuilder('rss', version='2.0', nsmap=self.nsmap)

        with rss.child('channel'):
            rss.add('link', self.link)
            rss.add('title', self.title)
            rss.add('description', self.desc)
            rss.add('language', self.language)
            rss.add('copyright', self.copyright)
            rss.add('managingEditor', self.editor)
            rss.add('webMaster', self.webmaster)
            rss.add('pubDate', self.published.rfc822format())
            rss.add('lastBuildDate', self.build_date.rfc822format())
            rss.add('generator', self.generator)
            rss.add('docs', self.docs)
            rss.add('ttl', self.ttl)

            for category in self.categories:
                rss.add('category', category.name, domain=category.domain)

            if self.image is not None:
                with rss.child('image'):
                    rss.add('url', self.image.url)
                    rss.add('title', self.image.title or self.title)
                    rss.add('link', self.image.link or self.link)
                    rss.add('width', self.image.width)
                    rss.add('height', self.image.height)

            if self.add_atom and self.rss_url:
                rss.add('atom:link',
                        rel='self',
                        type='application/rss+xml',
                        href=self.rss_url)

            for item in self:
                published = self.published if item.published is None else tzdatetime.new(
                    item.published)
                with rss.child('item'):
                    rss.add('link', item.link)
                    rss.add('title', item.title)
                    rss.add('description', item.desc)
                    rss.add('author', item.author)
                    rss.add('comments', item.comments)
                    rss.add('guid', item.guid, isPermaLink='false')
                    rss.add('pubDate', published.rfc822format())

                    for category in item.categories:
                        rss.add('category',
                                category.name,
                                domain=category.domain)

                    if self.add_dc:
                        rss.add('dc:title', item.title)
                        rss.add('dc:creator', item.author)
                        rss.add('dc:language', self.language)
                        rss.add('dc:rights', self.copyright)
                        rss.add('dc:date', published.isoformat())
                        rss.add('dc:format', item.content_type)
                        rss.add('dc:identifier', item.guid)

        for stylesheet in self.stylesheets:
            rss.add_pi('xml-stylesheet', **stylesheet.__dict__)

        return rss