from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.views.generic.simple import direct_to_template
from . import models
from . import forms

def cart(request, typ):
    cart = models.Cart.objects.get_or_create_from_request(request, typ)
    if request.method == 'POST':
        formset = forms.CartItemFormSet(instance=cart, data=request.POST)
        if formset.is_valid():
            formset.save()
            return HttpResponseRedirect(reverse('satchless-cart-view', kwargs={'typ': typ}))
    else:
        formset = forms.CartItemFormSet(instance=cart)
    return direct_to_template(request,
            'satchless/cart/view.html',
            {'cart': cart, 'formset': formset})

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from . import models
from . import forms

def cart(request, typ):
    cart = models.Cart.objects.get_or_create_from_request(request, typ)
    if request.method == 'POST':
        formset = forms.CartItemFormSet(instance=cart, data=request.POST)
        if formset.is_valid():
            formset.save()
            return HttpResponseRedirect(reverse('satchless-cart-view', kwargs={'typ': typ}))
    else:
        formset = forms.CartItemFormSet(instance=cart)
    return render_to_response(
            ['satchless/cart/%s/view.html' % typ, 'satchless/cart/view.html'],
            {'cart': cart, 'formset': formset},
            context_instance=RequestContext(request))

Allow prefixed templates for different cart types
Allow prefixed templates for different cart types

  from django.core.urlresolvers import reverse
  from django.http import HttpResponseRedirect
- from django.views.generic.simple import direct_to_template
+ from django.shortcuts import render_to_response
+ from django.template import RequestContext
  from . import models
  from . import forms
  
  def cart(request, typ):
      cart = models.Cart.objects.get_or_create_from_request(request, typ)
      if request.method == 'POST':
          formset = forms.CartItemFormSet(instance=cart, data=request.POST)
          if formset.is_valid():
              formset.save()
              return HttpResponseRedirect(reverse('satchless-cart-view', kwargs={'typ': typ}))
      else:
          formset = forms.CartItemFormSet(instance=cart)
-     return direct_to_template(request,
-             'satchless/cart/view.html',
+     return render_to_response(
+             ['satchless/cart/%s/view.html' % typ, 'satchless/cart/view.html'],
-             {'cart': cart, 'formset': formset})
+             {'cart': cart, 'formset': formset},
+             context_instance=RequestContext(request))
  
Allow prefixed templates for different cart types
## Code Before:
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.views.generic.simple import direct_to_template
from . import models
from . import forms

def cart(request, typ):
    cart = models.Cart.objects.get_or_create_from_request(request, typ)
    if request.method == 'POST':
        formset = forms.CartItemFormSet(instance=cart, data=request.POST)
        if formset.is_valid():
            formset.save()
            return HttpResponseRedirect(reverse('satchless-cart-view', kwargs={'typ': typ}))
    else:
        formset = forms.CartItemFormSet(instance=cart)
    return direct_to_template(request,
            'satchless/cart/view.html',
            {'cart': cart, 'formset': formset})

## Instruction:
Allow prefixed templates for different cart types
## Code After:
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from . import models
from . import forms

def cart(request, typ):
    cart = models.Cart.objects.get_or_create_from_request(request, typ)
    if request.method == 'POST':
        formset = forms.CartItemFormSet(instance=cart, data=request.POST)
        if formset.is_valid():
            formset.save()
            return HttpResponseRedirect(reverse('satchless-cart-view', kwargs={'typ': typ}))
    else:
        formset = forms.CartItemFormSet(instance=cart)
    return render_to_response(
            ['satchless/cart/%s/view.html' % typ, 'satchless/cart/view.html'],
            {'cart': cart, 'formset': formset},
            context_instance=RequestContext(request))
