Ejemplo n.º 1
0
    def entry_test(self):
        atom = createAtom()
        title = createTitle(root=atom, body="testEntry")
        iid = createID(1, root=atom)
        update = createUpdated("2012-0619T21:02:00.626Z", root=atom)
        entry = createEntry(iid, title, update, root=atom)
        atom.append(entry)
        self.assertEqual(
            tostring(atom),
            '<feed xmlns="http://www.w3.org/2005/Atom">\
<entry><id>1</id><title>testEntry</title><updated>2012-0619T21:02:00.626Z</updated></entry></feed>',
        )

        root = Element("myCustomTag")
        title = createTitle(root=root, body="testEntry")
        iid = createID(1, root=root)
        update = createUpdated("2012-0619T21:02:00.626Z", root=atom)
        atom = createEntry(iid, title, update, root=root)
        root.append(atom)
        self.assertEqual(
            tostring(root),
            '<myCustomTag xmlns:atom="http://www.w3.org/2005/Atom">\
<atom:entry><atom:id>1</atom:id><atom:title>testEntry</atom:title><updated>2012-0619T21:02:00.626Z</updated>\
</atom:entry></myCustomTag>',
        )

        root = createAtomDocument(1, "atomTitle", "2012-0619T21:02:00.626Z")
        iid = createID(2, root=root)
        title = createTitle(root=root, body="testEntry")
        update = createUpdated("2012-0619T21:02:00.626Z", root=root)
        entry = createEntry(iid, title, update, root=root)
        root.append(entry)
        self.assertEqual(
            tostring(root),
            '<feed xmlns="http://www.w3.org/2005/Atom"><id>1</id>\
<title>atomTitle</title><updated>2012-0619T21:02:00.626Z</updated><entry><id>2</id>\
<title>testEntry</title><updated>2012-0619T21:02:00.626Z</updated></entry></feed>',
            "Error",
        )
Ejemplo n.º 2
0
    def generate_entries(self, atomroot, subresults, path, params_model, context):
        if subresults is None:
            return
              
        entries = []
        
        for subresult in subresults: 
            #Here could loop over results
            entry_path = generate_url_id(path, subresult.id)
            atom_id = createID(entry_path + '/' + self.extension, root = atomroot)
            ititle = createTitle(root = atomroot, 
                                 body = subresult.title, 
                                 itype = HTML_TYPE)
            atom_content = createContent(root = atomroot, 
                                        body = subresult.description, 
                                        itype = HTML_TYPE)
            atom_updated = createUpdated(subresult.updated, root = atomroot)
            atom_published = createPublished('TO_BE_DONE_2011-01-21T11:05:29.511Z', 
                                            root = atomroot)            
            entry = createEntry(atom_id, ititle, atom_updated,
                                published=atom_published,
                                content=atom_content, root = atomroot)
            
            begin_position = None
            end_position = None
            if hasattr(subresult, 'beginPosition') \
                    and subresult.beginPosition is not None:
                begin_position = subresult.beginPosition
            if hasattr(subresult, 'endPosition') \
                    and subresult.endPosition is not None:                
                end_position = subresult.endPosition 
            append_valid_time(subresult, entry, atomroot, 
                              begin_position, end_position)            
            
            idate = createDate(root = atomroot, 
                body = 'TO_BE_DONE_2002-10-18T08:07:37.387Z/2012-03-29T07:12:20.735Z')        
            entry.append(idate)
            
            if hasattr(subresult, 'geometry') \
                    and subresult.geometry is not None:
                where = create_where_from_postgis(subresult.geometry, atomroot)
                entry.append(where)
            
            
            
            self.generateEntryLinks(entry, atomroot, entry_path, \
                                    params_model, context)
            if hasattr(subresult, 'enclosure') \
                    and subresult.enclosure is not None: 
                for enclosure in subresult.enclosure:
                    if enclosure.get('rel', None) == 'enclosure': 
                        entry.append(createLink(enclosure.get('href'), 
                                            rel = 'enclosure', 
                                            root = atomroot, 
                                            itype = enclosure.get('type'),
                                            length = enclosure.get('length')))                
                            
            entries.append(entry)

        for entry in entries:
            atomroot.append(entry)