photologue_tags.py 文件源码

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

项目:DCRM 作者: 82Flex 项目源码 文件源码
def render(self, context):
        try:
            a = template.resolve_variable(self.gallery, context)
        except:
            a = self.gallery
        if isinstance(a, Gallery):
            g = a
        else:
            try:
                g = Gallery.objects.get(slug=a)
            except Gallery.DoesNotExist:
                return None
        photos = g.public()
        if len(photos) > 1:
            r = random.randint(0, len(photos) - 1)
            p = photos[r]
        elif len(photos) == 1:
            p = photos[0]
        else:
            return None
        func = getattr(p, 'get_%s_url' % (self.photosize), None)
        if func is None:
            return 'A "%s" photo size has not been defined.' % (self.photosize)
        else:
            return u'<img class="%s" src="%s" alt="%s" />' % (self.css_class, func(), p.title)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号