title: How to refactor similar looking functions across 2 different class based views in Django 1.10?
body: <p>Am using codecoverage and it complains that I have 2 functions in 2 different class based views that are too similar.</p>
  
  <p>Attached is the codecoverage error
  <a href="https://i.stack.imgur.com/E15yI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E15yI.png" alt="enter image description here"></a></p>
  
  <p>Below are the code that were highlighted:</p>
  
  <pre><code>class PalletContentPickup(APIView):
      """
      Picking up a pallet content to transfer to exiting pallet content
      """
      def put(self, request, pk):
          count = request.data['count']
          pallet_id = request.data['pallet_id']
          from_pallet_content = QuickFind.get_pallet_content_or_404(pallet_content_id=pk)
          to_pallet = QuickFind.get_pallet_or_404(pallet_id=pallet_id)
  
          Transfer.validate_if_can_pickup_pallet_content(from_pallet_content, to_pallet, request.user)
  
          to_pallet_content = QuickFind.get_or_create_pallet_content(pallet=to_pallet, product=from_pallet_content.product)
          ExitFormHelper.create_exit_form_line_item_on_pallet_content_if_no_exit_form_line(to_pallet_content, request.user)
          Transfer.previous_pallet_content_to_new_pallet_content(from_pallet_content, to_pallet_content, count)
  
          serializer = PalletSerializer(from_pallet_content.pallet)
          return Response({"data": serializer.data}, status=status.HTTP_202_ACCEPTED)
  
  
  class PalletContentPutback(APIView):
      """
      Put back pallet content to an approved pallet
      """
      def put(self, request, pk):
          count = request.data['count']
          pallet_id = request.data['pallet_id']
          from_pallet_content = QuickFind.get_pallet_content_or_404(pallet_content_id=pk)
          to_pallet = QuickFind.get_pallet_or_404(pallet_id=pallet_id)
  
          Transfer.validate_if_can_putback_pallet_content(from_pallet_content, to_pallet, request.user)
  
          to_pallet_content = QuickFind.get_or_create_pallet_content(pallet=to_pallet, product=from_pallet_content.product)
          ExitFormHelper.create_exit_form_line_item_on_pallet_content_if_no_exit_form_line(to_pallet_content, request.user)
          Transfer.previous_pallet_content_to_new_pallet_content(from_pallet_content, to_pallet_content, count)
  
          serializer = PalletSerializer(from_pallet_content.pallet)
          return Response({"data": serializer.data}, status=status.HTTP_202_ACCEPTED)
  </code></pre>
  
  <p>I read about <a href="http://www.laurencegellert.com/2011/08/python-strategy-pattern/" rel="nofollow noreferrer">strategy pattern in Python</a></p>
  
  <p>Not sure if I should apply strategy pattern here and if so, how? Because the example in the url still does not help me realise exactly how to perform strategy pattern here.</p>