# $Id$
# $URL$
# $Id$
# $URL$
namespaceMap = {
'rating': "http://meresco.com/namespace/record/rating"
}
def showRating(recordId, imageSize="normal"):
maximumRating = 5
averageScore = 0
numberOfVotes = 0
if any.isPartAvailable(recordId, 'rating'):
rating = parse(any.getStream(recordId, 'rating'))
averageScore = int(rating.xpath('//rating:averageScore/text()', namespaceMap)[0])
numberOfVotes = int(rating.xpath('//rating:numberOfVotes/text()', namespaceMap)[0])
average = averageScore/1000.0
score = int(average + 0.4999)
averageTitle = 'average rating %.1f (number of ratings %s)' % (average, numberOfVotes)
yield ''
yield '' % (imageSize, averageTitle) * score
yield '' % (imageSize, averageTitle) * (maximumRating - score)
yield '(%s)' % numberOfVotes
def showCreateRating(headers, recordId):
if any.recordInList(headers, recordId):
yield 'Already rated'
return
yield "Rate this "
yield """\n"""
yield ''
for i in range(1,6):
yield '' % escapeHtml(urlencode({'recordId':recordId, 'value': i}))
yield ''
yield '\n'