Replace CSS with a version with newlines.
[matthijs/projects/xerxes.git] / influences / admin.py
1 from django.contrib import admin
2 from django.contrib.admin.util import unquote
3 from django.shortcuts import get_object_or_404, render_to_response
4 from django.template import RequestContext
5 from xerxes.influences.models import Character, Influence
6 from django.contrib.contenttypes import generic
7 from threadedcomments.models import ThreadedComment
8 from django.utils.safestring import mark_safe
9
10 class CharacterAdmin(admin.ModelAdmin):
11     list_filter=('status', 'player')
12     search_fields=('name',)
13     list_display=('player', 'name', 'status') 
14
15 admin.site.register(Character, CharacterAdmin)
16
17 class InfluenceAdmin(admin.ModelAdmin):
18     list_filter=('character', 'status', 'longterm')
19     search_fields=('character', 'summary', 'description', 'contact')
20     list_display=('character', 'contact', 'summary', 'longterm', 'status') 
21
22     class Media:
23         js = ('base/js/yahoo-dom-event.js', 'base/js/logger-debug.js')
24
25     def __call__(self, request, url):
26         if (url and url.endswith('/comments')):
27             return self.comments_view(request, unquote(url[:-9]))
28         else:
29             return super(InfluenceAdmin, self).__call__(request, url)
30     
31     def comments_view(self, request, object_id):
32         model = self.model
33         opts = model._meta
34         obj = get_object_or_404(model, pk=object_id)
35
36         comments = obj.get_comments(private=True)
37
38         context = {
39             'root_path'     : self.admin_site.root_path,
40             'app_label'     : self.model._meta.app_label,
41             'object'        : obj,
42             'opts'          : opts,
43             'comments'      : comments,
44             'media'         : mark_safe(self.media),
45         }
46         return render_to_response('admin/influences/influence/comments.html', context, RequestContext(request))
47         
48 admin.site.register(Influence, InfluenceAdmin)