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)
评论列表
文章目录