# HG changeset patch # User Brian Neal # Date 1375585923 18000 # Node ID 6e6492468bb863fb58e54790975d9b93c193aad4 # Parent 92101013d5acdebe0d6a570695eb8441d9a835aa Add admin action to acknowledge flagged links. Fix bug where weblinks js wasn't being included on detail page. diff -r 92101013d5ac -r 6e6492468bb8 sg101/templates/weblinks/link_detail.html --- a/sg101/templates/weblinks/link_detail.html Mon May 27 15:04:52 2013 -0500 +++ b/sg101/templates/weblinks/link_detail.html Sat Aug 03 22:12:03 2013 -0500 @@ -1,5 +1,8 @@ {% extends 'weblinks/base.html' %} {% block title %}Web Links: {{ link.title }}{% endblock %} +{% block weblinks_js %} + +{% endblock %} {% block weblinks_content %}

Link Details: {{ link.title }}

diff -r 92101013d5ac -r 6e6492468bb8 weblinks/admin.py --- a/weblinks/admin.py Mon May 27 15:04:52 2013 -0500 +++ b/weblinks/admin.py Sat Aug 03 22:12:03 2013 -0500 @@ -9,16 +9,16 @@ class CategoryAdmin(admin.ModelAdmin): - list_display = ('title', 'slug', 'description', 'count') - prepopulated_fields = {'slug': ('title', )} - readonly_fields = ('count', ) + list_display = ['title', 'slug', 'description', 'count'] + prepopulated_fields = {'slug': ['title', ]} + readonly_fields = ['count'] class PendingLinkAdmin(admin.ModelAdmin): - list_display = ('title', 'url', 'user', 'category', 'date_added') - raw_id_fields = ('user', ) - actions = ('approve_links', ) - readonly_fields = ('update_date', ) + list_display = ['title', 'url', 'user', 'category', 'date_added'] + raw_id_fields = ['user'] + actions = ['approve_links'] + readonly_fields = ['update_date'] def approve_links(self, request, qs): for pending_link in qs: @@ -41,20 +41,35 @@ class LinkAdmin(admin.ModelAdmin): - list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') - list_filter = ('date_added', 'is_public', 'category') + list_display = ['title', 'url', 'category', 'date_added', 'hits', 'is_public'] + list_filter = ['date_added', 'is_public', 'category'] date_hierarchy = 'date_added' - ordering = ('-date_added', ) - search_fields = ('title', 'description', 'url', 'user__username') - raw_id_fields = ('user', ) - readonly_fields = ('update_date', ) + ordering = ['-date_added'] + search_fields = ['title', 'description', 'url', 'user__username'] + raw_id_fields = ['user'] + readonly_fields = ['update_date'] save_on_top = True class FlaggedLinkAdmin(admin.ModelAdmin): - list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') + list_display = ['__unicode__', 'url', 'get_link_url', 'user', 'date_flagged'] date_hierarchy = 'date_flagged' - raw_id_fields = ('user', ) + raw_id_fields = ['user'] + + actions = ['hide_links'] + + def hide_links(self, request, qs): + for flagged_link in qs: + flagged_link.link.is_public = False + flagged_link.link.save() + + count = len(qs) + qs.delete() + msg = "1 link" if count == 1 else "%d links" % count + self.message_user(request, "%s hidden." % msg) + + hide_links.short_description = "Accept flags & hide links" + admin.site.register(Category, CategoryAdmin) admin.site.register(PendingLink, PendingLinkAdmin) diff -r 92101013d5ac -r 6e6492468bb8 weblinks/models.py --- a/weblinks/models.py Mon May 27 15:04:52 2013 -0500 +++ b/weblinks/models.py Sat Aug 03 22:12:03 2013 -0500 @@ -111,7 +111,7 @@ link = models.ForeignKey(Link) user = models.ForeignKey(User) date_flagged = models.DateField(auto_now_add = True) - approved = models.BooleanField(default = False, + approved = models.BooleanField(default = False, help_text = 'Check this and save to remove the referenced link from the database') objects = FlaggedLinkManager() diff -r 92101013d5ac -r 6e6492468bb8 weblinks/views.py --- a/weblinks/views.py Mon May 27 15:04:52 2013 -0500 +++ b/weblinks/views.py Sat Aug 03 22:12:03 2013 -0500 @@ -1,8 +1,7 @@ """ Views for the weblinks application. + """ - -import datetime import random from django.shortcuts import render_to_response from django.template import RequestContext @@ -13,7 +12,6 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import get_object_or_404 from django.core.urlresolvers import reverse -from django.db.models import Q from django.http import Http404 from django.views.decorators.http import require_POST @@ -38,7 +36,7 @@ categories = Category.objects.all() total_links = Link.public_objects.all().count() return render_to_response('weblinks/index.html', { - 'categories': categories, + 'categories': categories, 'total_links': total_links, }, context_instance = RequestContext(request)) @@ -55,7 +53,7 @@ raise Http404 return render_to_response('weblinks/link_summary.html', { - 'page': the_page, + 'page': the_page, 'title': 'Newest Links', }, context_instance = RequestContext(request)) @@ -71,7 +69,7 @@ except InvalidPage: raise Http404 return render_to_response('weblinks/link_summary.html', { - 'page': the_page, + 'page': the_page, 'title': 'Popular Links', }, context_instance = RequestContext(request)) @@ -112,7 +110,7 @@ # Maps URL component to database field name for the links table: LINK_FIELD_MAP = { - 'title': 'title', + 'title': 'title', 'date': '-date_added', 'hits': '-hits' } @@ -140,8 +138,8 @@ return render_to_response('weblinks/view_links.html', { 's' : sort, 'category' : cat, - 'page' : the_page, - }, + 'page' : the_page, + }, context_instance = RequestContext(request)) ####################################################################### @@ -185,8 +183,8 @@ return HttpResponseBadRequest("That link doesn't exist.") FlaggedLink.objects.create(link, request.user) - return HttpResponse("The link was reported. A moderator will review the " \ - "link shortly. Thanks for helping to improve the content on " \ + return HttpResponse("The link was reported. A moderator will review the " + "link shortly. Thanks for helping to improve the content on " "this site.") ####################################################################### @@ -194,6 +192,6 @@ def link_detail(request, id): link = get_object_or_404(Link, pk=id) return render_to_response('weblinks/link_detail.html', { - 'link': link, + 'link': link, }, context_instance = RequestContext(request))