Permalink
Browse files

further comment icon display

  • Loading branch information...
Raik Gruenberg
Raik Gruenberg committed Apr 6, 2014
1 parent 3bf500b commit 36b211dd4b2f585db44b79d6b57ea7b0732417f2
View
@@ -1,11 +1,47 @@
from django.db import models
from django_comments.models import Comment
from django.utils.safestring import mark_safe
import django.contrib.staticfiles.templatetags.staticfiles as ST
class RatedComment(Comment):
CHOICES = ((0, '--'),
(1, 'fresh'),
(-1, 'rotten'))
rating = models.IntegerField(choices=CHOICES, default=0)
ICONS = {'rotten': 'rotten.png',
'fresh': 'fresh.png',
'mixed': 'mixed.png',
'neutral': 'comment.png'}
def get_icon(self, modifier=''):
"""
@param modifier - str, will be inserted before '.png' file ending
@return str, fresh/rotten/neutral icon file name
"""
r = ''
if self.rating == 0:
r = self.ICONS['neutral']
if self.rating == 1:
r = self.ICONS['fresh']
if self.rating == -1:
r = self.ICONS['rotten']
if modifier:
r = r.replace('.png', modifier+'.png')
return ST.static(r)
def get_icon_html(self, height=0, modifier='_nano'):
"""
@param height - int, 0..no scaling, otherwise image height
@return str, HTML snippet for image depending on comment rating
"""
height = 'height="%i"' % height if height else ''
r = '<img src="%s" %s>' % (self.get_icon(modifier=modifier), height)
return mark_safe(r)
Binary file not shown.
@@ -94,10 +94,7 @@ def comment_vote_symbol(obj, height=0, iconset=None, mouseover=''):
Image summary of comment ratings associated with an object.
Image annotated with % of fresh votes in title(mouseover)
"""
icons = iconset or {'rotten': 'rotten.png',
'fresh': 'fresh.png',
'mixed': 'mixed.png',
'neutral': 'comment.png'}
icons = iconset or CM.RatedComment.ICONS
votes = comment_vote_stats(obj)
verdict = votes['verdict']
@@ -277,9 +277,13 @@ <h2>Recent Comments</h2>
{% for c in comments %}
<li><b>{{c.user_name}}</b> {{c.submit_date|date:"Y-m-d"}}:<br>
<p>
{{ c.get_icon_html }}
<a href="{{c.content_object.get_absolute_url}}#comments">
{{c.comment|truncate:55}}
</a></p>
</a><br>
<span class="mini quiet">{{ c.content_object }}</span>
</p>
</li>
{% endfor %}

0 comments on commit 36b211d

Please sign in to comment.