| 229 | class ArticlesField(StringField): |
| 230 | |
| 231 | def to_xml(self, articles): |
| 232 | article_count = len(articles) |
| 233 | items = [] |
| 234 | for article in articles: |
| 235 | title = self.converter(article.get('title', '')) |
| 236 | description = self.converter(article.get('description', '')) |
| 237 | image = self.converter(article.get('image', '')) |
| 238 | url = self.converter(article.get('url', '')) |
| 239 | item_tpl = """<item> |
| 240 | <Title><![CDATA[{title}]]></Title> |
| 241 | <Description><![CDATA[{description}]]></Description> |
| 242 | <PicUrl><![CDATA[{image}]]></PicUrl> |
| 243 | <Url><![CDATA[{url}]]></Url> |
| 244 | </item>""" |
| 245 | item = item_tpl.format( |
| 246 | title=title, |
| 247 | description=description, |
| 248 | image=image, |
| 249 | url=url |
| 250 | ) |
| 251 | items.append(item) |
| 252 | items_str = '\n'.join(items) |
| 253 | tpl = """<ArticleCount>{article_count}</ArticleCount> |
| 254 | <Articles>{items}</Articles>""" |
| 255 | return tpl.format( |
| 256 | article_count=article_count, |
| 257 | items=items_str |
| 258 | ) |
| 259 | |
| 260 | @classmethod |
| 261 | def from_xml(cls, value): |