(self, channels)
return doc.toprettyxml(encoding="utf-8", indent="  ", newl=os.linesep)
Creates a XML document containing metadata for each channel object in
        the "channels" parameter, which should be a list of channel objects.

        Returns: An OPML document as string
Creates a XML document containing metadata for each channel object in
        the "channels" parameter, which should be a list of channel objects.
Creates a XML document containing metadata for each channel object in the channels parameter which should be a list of channel objects .
def generate(self, channels):
        """
        Creates a XML document containing metadata for each channel object in
        the "channels" parameter, which should be a list of channel objects.

        Returns: An OPML document as string
        """
        doc = xml.dom.minidom.Document()

        opml = doc.createElement("opml")
        opml.setAttribute("version", "2.0")
        doc.appendChild(opml)

        def create_node(name, content):
            node = doc.createElement(name)
            node.appendChild(doc.createTextNode(content))
            return node

        head = doc.createElement("head")
        head.appendChild(create_node("title", self.title or ""))
        head.appendChild(create_node("dateCreated", self.created))
        opml.appendChild(head)

        def create_outline(channel):
            from mygpo.subscriptions.models import SubscribedPodcast
            from mygpo.podcasts.models import PodcastGroup

            outline = doc.createElement("outline")

            if isinstance(channel, SubscribedPodcast):
                title = channel.podcast.title
                outline.setAttribute("xmlUrl", channel.ref_url)
                outline.setAttribute("description", channel.podcast.description or "")
                outline.setAttribute("type", "rss")
                outline.setAttribute("htmlUrl", channel.podcast.link or "")
            elif isinstance(channel, PodcastGroup):
                title = channel.title
                for subchannel in channel.podcast_set.all():
                    outline.appendChild(create_outline(subchannel))
            else:
                title = channel.title
                outline.setAttribute("xmlUrl", channel.url)
                outline.setAttribute("description", channel.description or "")
                outline.setAttribute("type", "rss")
                outline.setAttribute("htmlUrl", channel.link or "")

            outline.setAttribute("title", title or "")
            outline.setAttribute("text", title or "")
            return outline

        body = doc.createElement("body")
        for channel in channels:
            body.appendChild(create_outline(channel))
        opml.appendChild(body)

        return doc.toprettyxml(encoding="utf-8", indent="  ", newl=os.linesep)
def generate ( self , channels ) : doc = xml . dom . minidom . Document ( ) opml = doc . createElement ( "opml" ) opml . setAttribute ( "version" , "2.0" ) doc . appendChild ( opml ) def create_node ( name , content ) : node = doc . createElement ( name ) node . appendChild ( doc . createTextNode ( content ) ) return node head = doc . createElement ( "head" ) head . appendChild ( create_node ( "title" , self . title or "" ) ) head . appendChild ( create_node ( "dateCreated" , self . created ) ) opml . appendChild ( head ) def create_outline ( channel ) : from mygpo . subscriptions . models import SubscribedPodcast from mygpo . podcasts . models import PodcastGroup outline = doc . createElement ( "outline" ) if isinstance ( channel , SubscribedPodcast ) : title = channel . podcast . title outline . setAttribute ( "xmlUrl" , channel . ref_url ) outline . setAttribute ( "description" , channel . podcast . description or "" ) outline . setAttribute ( "type" , "rss" ) outline . setAttribute ( "htmlUrl" , channel . podcast . link or "" ) elif isinstance ( channel , PodcastGroup ) : title = channel . title for subchannel in channel . podcast_set . all ( ) : outline . appendChild ( create_outline ( subchannel ) ) else : title = channel . title outline . setAttribute ( "xmlUrl" , channel . url ) outline . setAttribute ( "description" , channel . description or "" ) outline . setAttribute ( "type" , "rss" ) outline . setAttribute ( "htmlUrl" , channel . link or "" ) outline . setAttribute ( "title" , title or "" ) outline . setAttribute ( "text" , title or "" ) return outline body = doc . createElement ( "body" ) for channel in channels : body . appendChild ( create_outline ( channel ) ) opml . appendChild ( body ) return doc . toprettyxml ( encoding = "utf-8" , indent = "  " , newl = os . linesep )