models.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:django-happenings 作者: natgeosociety 项目源码 文件源码
def one_line_address(self):
        """
        Put the address all on one line
        """
        import re
        from django.utils.html import strip_tags
        if self.street_address and self.city and self.state and self.zipcode:
            # Since the street address is a text field, we have to clean it up a bit
            # making sure HTML tags are removed, <BR> tags are converted to newlines
            # and newlines are replaced with ', '
            address = re.sub(r'<br\s*/?>', '\n', self.street_address)
            address = strip_tags(address)

            address_parts = address.splitlines()
            address_parts.extend([
                self.city,
                self.state,
                self.zipcode,
                unicode(self.country.name),
            ])
            return ", ".join(address_parts)
        return ""
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号