from django.http import HttpResponse
from django.utils.translation import ugettext as _
from django.views.generic import View

from .pdf import generate_receipt_pdf


class ReceiptHTMLView(View):

    def get(self, request, pk):
        return HttpResponse(
            generate_receipt_pdf(pk, request, True),
        )


class ReceiptPDFView(View):

    def get(self, request, pk):
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename=' + \
            _('receipt %s.pdf' % pk)

        generate_receipt_pdf(pk, response)
        return response

from django.http import HttpResponse
from django.utils.translation import ugettext as _
from django.views.generic import View

from .pdf import generate_receipt_pdf


class ReceiptHTMLView(View):
    """Renders a receipt as HTML."""
    def get(self, request, pk):
        return HttpResponse(
            generate_receipt_pdf(pk, request, True),
        )


class ReceiptPDFView(View):
    """Renders a receipt as a PDF, prompting to download it."""

    def get(self, request, pk):
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename=' + \
            _('receipt %s.pdf' % pk)

        generate_receipt_pdf(pk, response)
        return response


class ReceiptPDFDisplayView(View):
    """
    Renders a receipt as a PDF.

    Browsers should render the file, rather than prompt to download it.
    """
    def get(self, request, pk):
        response = HttpResponse(content_type='application/pdf')
        generate_receipt_pdf(pk, response)
        return response

Add a view to display PDF receipts
Add a view to display PDF receipts

Fixes #23
Closes !7
Closes !8

  from django.http import HttpResponse
  from django.utils.translation import ugettext as _
  from django.views.generic import View
  
  from .pdf import generate_receipt_pdf
  
  
  class ReceiptHTMLView(View):
- 
+     """Renders a receipt as HTML."""
      def get(self, request, pk):
          return HttpResponse(
              generate_receipt_pdf(pk, request, True),
          )
  
  
  class ReceiptPDFView(View):
+     """Renders a receipt as a PDF, prompting to download it."""
  
      def get(self, request, pk):
          response = HttpResponse(content_type='application/pdf')
          response['Content-Disposition'] = 'attachment; filename=' + \
              _('receipt %s.pdf' % pk)
  
          generate_receipt_pdf(pk, response)
          return response
  
+ 
+ class ReceiptPDFDisplayView(View):
+     """
+     Renders a receipt as a PDF.
+ 
+     Browsers should render the file, rather than prompt to download it.
+     """
+     def get(self, request, pk):
+         response = HttpResponse(content_type='application/pdf')
+         generate_receipt_pdf(pk, response)
+         return response
+ 
Add a view to display PDF receipts
## Code Before:
from django.http import HttpResponse
from django.utils.translation import ugettext as _
from django.views.generic import View

from .pdf import generate_receipt_pdf


class ReceiptHTMLView(View):

    def get(self, request, pk):
        return HttpResponse(
            generate_receipt_pdf(pk, request, True),
        )


class ReceiptPDFView(View):

    def get(self, request, pk):
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename=' + \
            _('receipt %s.pdf' % pk)

        generate_receipt_pdf(pk, response)
        return response

## Instruction:
Add a view to display PDF receipts
## Code After:
from django.http import HttpResponse
from django.utils.translation import ugettext as _
from django.views.generic import View

from .pdf import generate_receipt_pdf


class ReceiptHTMLView(View):
    """Renders a receipt as HTML."""
    def get(self, request, pk):
        return HttpResponse(
            generate_receipt_pdf(pk, request, True),
        )


class ReceiptPDFView(View):
    """Renders a receipt as a PDF, prompting to download it."""

    def get(self, request, pk):
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename=' + \
            _('receipt %s.pdf' % pk)

        generate_receipt_pdf(pk, response)
        return response


class ReceiptPDFDisplayView(View):
    """
    Renders a receipt as a PDF.

    Browsers should render the file, rather than prompt to download it.
    """
    def get(self, request, pk):
        response = HttpResponse(content_type='application/pdf')
        generate_receipt_pdf(pk, response)
        return response
