def update_from_dict(self, dt, default_thumb=None): self.title = dt.get('title',None) self.published = dt.get('published',None) self.content = dt.get('content',None) self.sticky = dt.get('sticky',None) self.can_comment = dt.get('can_comment',None) self.page_id = dt.get('page_id',None) self.metacontent = html.striphtml(self.content) self.summary = html.stripobjects(self.content) media_data = html.get_metamedia_data(self.content, default_thumb) self.links = media_data.get('link',{}) self.metatags = media_data.get('meta',{}) self.tags.clear() for label in dt.get('tags',[]): tag = Tag.get_from_id(slugify(label)) or Tag(label=label) self.tags.add(tag) self.updated = rfc3339.now().replace(tzinfo=None)
def from_dict(cls, dt, default_thumb=None): item = cls() item.title = dt.get('title',None) item.published = dt.get('published',None) item.content = dt.get('content',None) item.sticky = dt.get('sticky',None) item.can_comment = dt.get('can_comment',None) item.page_id = dt.get('page_id',None) item.contributors = [] item.metacontent = html.striphtml(item.content) item.summary = html.stripobjects(item.content) media_data = html.get_metamedia_data(item.content, default_thumb) item.links = media_data.get('link',{}) item.metatags = media_data.get('meta',{}) for label in dt.get('tags',[]): tag = Tag.get_from_id(slugify(label)) or Tag(label=label) item.tags.add(tag) item.updated = rfc3339.now().replace(tzinfo=None) if item.created is None: item.created = item.updated return item
def test_blank(self): # make sure the shuffled sequence does not lose any elements response = stripobjects(13) self.assertEqual(response, u'')
def test_hr(self): # make sure the shuffled sequence does not lose any elements response = stripobjects(self.with_hr) self.assertEqual(response,self.no_hr)
def test_remove_iframe(self): response = stripobjects("""<div><iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0"></iframe></div>""") self.assertEquals(response,"""<div/>""")
def test_remove_embed(self): response = stripobjects("""<div><embed src="http://www.youtube.com/v/JW5meKfy3fY?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></div>""") self.assertEquals(response,"""<div/>""")
def test_removeembededobject(self): # make sure the shuffled sequence does not lose any elements response = stripobjects(self.with_object) self.assertEqual(response,self.no_object)