Commits

Yorgos Pagles  committed b8f4ad9

Mezzanine compatibility in rendering

  • Participants
  • Parent commits 7d44ba7

Comments (0)

Files changed (1)

File newsletter/views.py

 from django.core.exceptions import ValidationError, ObjectDoesNotExist
 from django.conf import settings
 from django.core.xheaders import populate_xheaders
+from django.template.response import TemplateResponse
 
 from django.template import loader, RequestContext, Context
 
-from django.shortcuts import get_object_or_404, render_to_response
+from django.shortcuts import get_object_or_404
 from django.http import HttpResponse, Http404
 
 from django.contrib import messages
     UnsubscribeRequestForm, UpdateForm
 )
 
+def render(request, templates, dictionary=None, context_instance=None,
+           **kwargs):
+    """
+    Mimics ``django.shortcuts.render`` but uses a TemplateResponse for
+    ``mezzanine.core.middleware.TemplateForDeviceMiddleware``
+    """
+    dictionary = dictionary or {}
+    if context_instance:
+        context_instance.update(dictionary)
+    else:
+        context_instance = RequestContext(request, dictionary)
+    return TemplateResponse(request, templates, context_instance, **kwargs)
+
 
 def archive_index(request, queryset, date_field, num_latest=15,
                   template_name=None, template_loader=loader,
         'action': 'subscribe'
     }
 
-    return render_to_response(
+    return render(
         "newsletter/subscription_subscribe_user.html",
         env, context_instance=RequestContext(request))
 
         'action': 'unsubscribe'
     }
 
-    return render_to_response(
+    return render(
         "newsletter/subscription_unsubscribe_user.html",
         env, context_instance=RequestContext(request))
 
         'action': 'subscribe'
     }
 
-    return render_to_response(
+    return render(
         "newsletter/subscription_subscribe.html",
         env, context_instance=RequestContext(request))
 
         'action': 'unsubscribe'
     }
 
-    return render_to_response(
+    return render(
         "newsletter/subscription_unsubscribe.html",
         env, context_instance=RequestContext(request))
 
         'action': 'update'
     }
 
-    return render_to_response(
+    return render(
         "newsletter/subscription_update.html",
         env, context_instance=RequestContext(request))
 
         'action': action
     }
 
-    return render_to_response(
+    return render(
         "newsletter/subscription_activate.html", env,
         context_instance=RequestContext(request)
     )