Add a custom comment preview view for influences.
authorMatthijs Kooijman <matthijs@stdin.nl>
Fri, 31 Oct 2008 16:44:27 +0000 (17:44 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Fri, 31 Oct 2008 16:44:27 +0000 (17:44 +0100)
influences/views.py

index a8b9a7df631612d5491498d616c5344b48f1cdb7..1025efa2e8ea6a5cbb5dff4d12bf610c00a94a1f 100644 (file)
@@ -10,7 +10,7 @@ from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect, HttpResponseForbidden
 from django.views.generic.list_detail import object_detail, object_list
 from threadedcomments.models import ThreadedComment
-from threadedcomments.views import free_comment
+from threadedcomments.views import free_comment, _preview
 from xerxes.influences.models import Character
 from xerxes.influences.models import Influence
 from forms import get_influence_comment_form, InfluenceForm, CharacterForm
@@ -89,6 +89,15 @@ def influence_list(request):
     os = Influence.objects.filter(character__player=request.user)
     return render_to_response('influences/influence_list.html', {'object_list' : os}, RequestContext(request))
 
+def influence_comment_preview(request, context_processors, extra_context, **kwargs):
+    # Use a custom template
+    kwargs['template'] = 'influences/influence_comment_preview.html'
+    # The base template to extend
+    extra_context['base'] = "influences/influence_detail.html"
+    # The object to be show in the influence detail
+    extra_context['object'] = get_object_or_404(Influence, pk=kwargs['object_id'])
+    return _preview(request, context_processors, extra_context, **kwargs)
+
 @login_required
 def influence_detail(request, object_id):
 
@@ -126,6 +135,7 @@ def influence_comment(request, object_id, edit_id=None):
     # that hardcodes the form_class.
     kwargs['model'] = ThreadedComment
     # Set a custom preview view
+    kwargs['preview'] = influence_comment_preview
     if parent_id:
         kwargs['prefix'] = "reply-to-%s" % (parent_id)
     return free_comment(request, object_id=object_id, edit_id=edit_id, **kwargs)