changeset 151:e1d1a70d312d

Implement #43, various shoutbox improvements.
author Brian Neal <bgneal@gmail.com>
date Fri, 18 Dec 2009 04:30:49 +0000
parents b43e1288ff80
children bc657962941e
files gpp/core/templatetags/custom_admin_tags.py gpp/shoutbox/admin.py gpp/shoutbox/models.py gpp/shoutbox/views.py gpp/templates/core/admin_dashboard.html gpp/templates/shoutbox/render_shout.html gpp/templates/shoutbox/shout.html gpp/templates/shoutbox/shout_detail.html gpp/templates/shoutbox/shoutbox.html gpp/templates/shoutbox/view.html
diffstat 10 files changed, 54 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/core/templatetags/custom_admin_tags.py	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/core/templatetags/custom_admin_tags.py	Fri Dec 18 04:30:49 2009 +0000
@@ -11,6 +11,7 @@
 from gcalendar.models import Event
 from news.models import PendingStory
 from weblinks.models import Link
+from shoutbox.models import ShoutFlag
 
 
 register = template.Library()
@@ -32,6 +33,7 @@
                 Q(status=Event.DEL_REQ)).count()
     new_stories = PendingStory.objects.count()
     new_links = Link.objects.filter(is_public=False).count()
+    flagged_shouts = ShoutFlag.objects.count()
 
     return {
         'user': user,
@@ -42,4 +44,5 @@
         'event_requests': event_requests,
         'new_stories': new_stories,
         'new_links': new_links,
+        'flagged_shouts': flagged_shouts,
         }
--- a/gpp/shoutbox/admin.py	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/shoutbox/admin.py	Fri Dec 18 04:30:49 2009 +0000
@@ -6,14 +6,29 @@
 from shoutbox.models import ShoutFlag
 
 class ShoutAdmin(admin.ModelAdmin):
-    list_display = ('shout_date', '__unicode__')
+    list_display = ('__unicode__', 'user', 'shout_date')
     raw_id_fields = ('user', )
+    date_hierarchy = 'shout_date'
+    exclude = ('html', )
+    search_fields = ('shout', 'user__username')
+    list_filter = ('shout_date', )
+
 
 class ShoutFlagAdmin(admin.ModelAdmin):
-    list_display = ('__unicode__', 'flag_date', 'get_shout_url')
+    list_display = ('__unicode__', 'flag_date', 'shout', 'get_shout_url')
+    actions = ('delete_shouts', )
+
+    def delete_shouts(self, request, qs):
+        """
+        Admin action function to delete the shouts associated with the shout
+        flags.
+        """
+        for flag in qs:
+            flag.shout.delete()     # will delete the flag too
+
+    delete_shouts.short_description = "Delete selected flags & shouts"
 
 
 admin.site.register(Shout, ShoutAdmin)
 admin.site.register(ShoutFlag, ShoutFlagAdmin)
 
-# vim: ts=4 sw=4
--- a/gpp/shoutbox/models.py	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/shoutbox/models.py	Fri Dec 18 04:30:49 2009 +0000
@@ -1,25 +1,39 @@
 """
 Models for the shoutbox application.
 """
+import datetime
+
 from django.db import models
 from django.contrib.auth.models import User
+from django.utils.html import urlize
+
+from smiley import smilify_html
 
 
 class Shout(models.Model):
     user = models.ForeignKey(User)
-    shout_date = models.DateTimeField(auto_now_add=True)
+    shout_date = models.DateTimeField(blank=True)
     shout = models.TextField()
+    html = models.TextField()
+
+    class Meta:
+        ordering = ('-shout_date', )
+
+    def __unicode__(self):
+        if len(self.shout) > 60:
+            return self.shout[:60] + "..."
+        return self.shout
 
     @models.permalink
     def get_absolute_url(self):
         return ('shoutbox-view', [str(self.id)])
 
-    def __unicode__(self):
-        shout = self.shout[:60]
-        return u'Shout from %s: %s' % (self.user.username, shout)
-
-    class Meta:
-        ordering = ('-shout_date', )
+    def save(self, *args, **kwargs):
+        if not self.id:
+            self.shout_date = datetime.datetime.now()
+        self.html = urlize(smilify_html(self.shout), trim_url_limit=15, 
+                nofollow=True)
+        super(Shout, self).save(*args, **kwargs)
 
 
 class ShoutFlag(models.Model):
@@ -35,7 +49,8 @@
         ordering = ('flag_date', )
 
     def get_shout_url(self):
-        return '<a href="/admin/shoutbox/shout/%s">Shout</a>' % self.shout.id
+        return '<a href="/admin/shoutbox/shout/%(id)d">Shout #%(id)d</a>' % (
+                {'id': self.shout.id})
     get_shout_url.allow_tags = True
+    get_shout_url.short_description = 'Link to Shout'
 
-# vim: ts=4 sw=4
--- a/gpp/shoutbox/views.py	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/shoutbox/views.py	Fri Dec 18 04:30:49 2009 +0000
@@ -10,6 +10,7 @@
 from django.http import HttpResponseBadRequest
 from django.http import HttpResponseForbidden
 from django.http import HttpResponseRedirect
+from django.http import Http404
 from django.contrib.auth.decorators import login_required
 from django.views.decorators.http import require_POST
 
@@ -100,10 +101,7 @@
             return HttpResponseBadRequest()
         shout.shout = new_shout
         shout.save()
-        return render_to_response('shoutbox/render_shout.html', {
-            'shout': shout,
-            },
-            context_instance = RequestContext(request))
+        return HttpResponse(shout.html)
 
     return HttpResponseForbidden()
 
--- a/gpp/templates/core/admin_dashboard.html	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/templates/core/admin_dashboard.html	Fri Dec 18 04:30:49 2009 +0000
@@ -1,5 +1,5 @@
 {% if user.is_staff %}
-{% if flagged_posts or flagged_comments or flagged_profiles or event_requests or new_stories or new_downloads or new_links %}
+{% if flagged_posts or flagged_comments or flagged_profiles or event_requests or new_stories or new_downloads or new_links or flagged_shouts %}
 <ul id="dashboard-list">
 {% if flagged_posts %}
 <li><a href="/admin/forums/flaggedpost/">Posts</a>: {{ flagged_posts }}</li>
@@ -7,6 +7,9 @@
 {% if flagged_comments %}
 <li><a href="/admin/comments/commentflag/">Comments</a>: {{ flagged_comments }}</li>
 {% endif %}
+{% if flagged_shouts %}
+<li><a href="/admin/shoutbox/shoutflag/">Shouts</a>: {{ flagged_shouts }}</li>
+{% endif %}
 {% if flagged_profiles %}
 <li><a href="/admin/bio/userprofileflag/">Profiles</a>: {{ flagged_profiles }}</li>
 {% endif %}
--- a/gpp/templates/shoutbox/render_shout.html	Thu Dec 17 04:14:16 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-{% load smiley_tags %}
-{{ shout.shout|smiley_html|urlize }}
--- a/gpp/templates/shoutbox/shout.html	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/templates/shoutbox/shout.html	Fri Dec 18 04:30:49 2009 +0000
@@ -1,6 +1,5 @@
-{% load smiley_tags %}
 <p style="display:none;">
 <span class="shoutbox-user">{{ shout.user.username }}:</span>
-<span class="shoutbox-shout">{{ shout.shout|smiley_html|urlizetrunc:15 }}</span>
+<span class="shoutbox-shout">{{ shout.html|safe }}</span>
 <span class="shoutbox-date">{{ shout.shout_date|date:"D M d Y H:i:s" }}</span>
 </p>
--- a/gpp/templates/shoutbox/shout_detail.html	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/templates/shoutbox/shout_detail.html	Fri Dec 18 04:30:49 2009 +0000
@@ -1,12 +1,11 @@
 {% load avatar_tags %}
-{% load smiley_tags %}
 <tr>
 <th>
 <a href="{% url bio-view_profile username=shout.user.username %}">{% avatar shout.user %}</a>
 <a href="{% url bio-view_profile username=shout.user.username %}">{{ shout.user.username }}</a>
 </th>
 <td>
-<div {% ifequal user.id shout.user.id %}class="edit" id="shout-{{ shout.id }}"{% endifequal %}>{{ shout.shout|smiley_html|urlize }}</div>
+<div {% ifequal user.id shout.user.id %}class="edit" id="shout-{{ shout.id }}"{% endifequal %}>{{ shout.html|safe }}</div>
 </div>
 <br />
 <span class="date">{{ shout.shout_date|date:"D M d Y H:i:s" }}</span><br />
--- a/gpp/templates/shoutbox/shoutbox.html	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/templates/shoutbox/shoutbox.html	Fri Dec 18 04:30:49 2009 +0000
@@ -1,12 +1,11 @@
 {% extends 'side_block.html' %}
-{% load smiley_tags %}
 {% block block_title %}Shoutbox{% endblock %}
 {% block block_content %}
 <div id="shoutbox-shout-container">
    {% for shout in shouts %}
       <p>
       <span class="shoutbox-user">{{ shout.user.username }}:</span>
-      <span class="shoutbox-shout">{{ shout.shout|smiley_html|urlizetrunc:15 }}</span>
+      <span class="shoutbox-shout">{{ shout.html|safe }}</span>
       <span class="shoutbox-date">{{ shout.shout_date|date:"D M d Y H:i:s" }}</span>
       </p>
    {% endfor %}
--- a/gpp/templates/shoutbox/view.html	Thu Dec 17 04:14:16 2009 +0000
+++ b/gpp/templates/shoutbox/view.html	Fri Dec 18 04:30:49 2009 +0000
@@ -1,6 +1,5 @@
 {% extends 'base.html' %}
 {% load avatar_tags %}
-{% load smiley_tags %}
 {% load script_tags %}
 {% block custom_css %}
 <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/shoutbox_app.css" />