polyblog/polysite/globals.py

26 lines
1.1 KiB
Python

import mistune
from imageapp.models import BlogImage
from blogapp.models import blogentry, blogcategory, blogcomment
class CustomRenderer(mistune.Renderer):
def image(self, src, title, alt_text):
try:
img = BlogImage.objects.get(pk=src)
return '<div id="textimg"><img width="100%" src="' + img.image.url + '"/><br>Title: ' + img.title + '<br>Caption: ' + img.caption + '</div>'
except BlogImage.DoesNotExist:
return '<i>Should display an image here but none with id ' + src + ' was found.</i>'
def footer_info(request):
blogentries = blogentry.objects.all().order_by('-date')[:5]
blogcategories = blogcategory.objects.all()
blogcomments = blogcomment.objects.all().order_by('-date')[:5]
return {'blogentries': blogentries, 'blogcategories': blogcategories, 'blogcomments': blogcomments}
# def getincludes(request):
# eventlist = evententry.objects.all().order_by('-date')[:10]
# appointmentlist = event.objects.all().filter(eventend__gte = datetime.datetime.now()).order_by('eventstart')[:5]
# return {'eventlist' : eventlist, 'appointmentlist' : appointmentlist}