# HG changeset patch # User Brian Neal # Date 1261110649 0 # Node ID e1d1a70d312d5f24f727742003e0d44a96919e6b # Parent b43e1288ff805f87359207944ba841afbe7be122 Implement #43, various shoutbox improvements. diff -r b43e1288ff80 -r e1d1a70d312d gpp/core/templatetags/custom_admin_tags.py --- 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, } diff -r b43e1288ff80 -r e1d1a70d312d gpp/shoutbox/admin.py --- 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 diff -r b43e1288ff80 -r e1d1a70d312d gpp/shoutbox/models.py --- 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 'Shout' % self.shout.id + return 'Shout #%(id)d' % ( + {'id': self.shout.id}) get_shout_url.allow_tags = True + get_shout_url.short_description = 'Link to Shout' -# vim: ts=4 sw=4 diff -r b43e1288ff80 -r e1d1a70d312d gpp/shoutbox/views.py --- 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() diff -r b43e1288ff80 -r e1d1a70d312d gpp/templates/core/admin_dashboard.html --- 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 %}