prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Always ask for page size and copies for resource generation
  Add these questions to `base-resource.html` template
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `csunplugged/resources/views/sorting_network.py`
  Content:
  ```
  1 from PIL import Image, ImageDraw, ImageFont
  2 from random import sample
  3 
  4 
  5 def resource_image(get_request, resource):
  6     """Creates a image for Sorting Network resource.
  7 
  8     Returns:
  9         A Pillow image object.
  10     """
  11     image_path = 'static/img/resource-sorting-network-colour.png'
  12     image = Image.open(image_path)
  13     draw = ImageDraw.Draw(image)
  14 
  15     (range_min, range_max, font_size) = number_range(get_request)
  16 
  17     font_path = 'static/fonts/PatrickHand-Regular.ttf'
  18 
  19     # Add numbers to text if needed
  20     if get_request['prefilled_values'] != 'blank':
  21         font = ImageFont.truetype(font_path, font_size)
  22         numbers = sample(range(range_min, range_max), 6)
  23         base_coord_x = 70
  24         base_coord_y = 2560
  25         coord_x_increment = 204
  26         for number in numbers:
  27             text = str(number)
  28             text_width, text_height = draw.textsize(text, font=font)
  29             coord_x = base_coord_x - (text_width / 2)
  30             coord_y = base_coord_y - (text_height / 2)
  31             draw.text(
  32                 (coord_x, coord_y),
  33                 text,
  34                 font=font,
  35                 fill='#000'
  36             )
  37             base_coord_x += coord_x_increment
  38 
  39     return image
  40 
  41 
  42 def subtitle(get_request, resource):
  43     """Returns the subtitle string of the resource.
  44 
  45     Used after the resource name in the filename, and
  46     also on the resource image.
  47     """
  48     TEMPLATE = '{} to {}'
  49     range_min, range_max, font_size = number_range(get_request)
  50     text = TEMPLATE.format(range_min, range_max - 1)
  51     return text
  52 
  53 
  54 def number_range(get_request):
  55     """Returns a tuple of (range_min, range_max, font_size)
  56     for the requested resource.
  57     """
  58     prefilled_values = get_request['prefilled_values']
  59     if prefilled_values == 'easy':
  60         range_min = 1
  61         range_max = 10
  62         font_size = 150
  63     elif prefilled_values == 'medium':
  64         range_min = 10
  65         range_max = 100
  66         font_size = 120
  67     elif prefilled_values == 'hard':
  68         range_min = 100
  69         range_max = 1000
  70         font_size = 90
  71     return (range_min, range_max, font_size)
  72
  ```
  
  Path: `csunplugged/resources/views/generate_resource_pdf.py`
  Content:
  ```
  1 from django.http import HttpResponse
  2 from django.template.loader import render_to_string
  3 from django.contrib.staticfiles import finders
  4 from multiprocessing import Pool
  5 from functools import partial
  6 from weasyprint import HTML, CSS
  7 from PIL import Image
  8 from io import BytesIO
  9 import importlib
  10 import base64
  11 
  12 RESPONSE_CONTENT_DISPOSITION = 'attachment; filename="{filename}.pdf"'
  13 MM_TO_PIXEL_RATIO = 3.78
  14 
  15 
  16 def generate_resource_pdf(request, resource, module_path):
  17     """Returns a response containing a randomly generated PDF resource.
  18 
  19     Returns:
  20         HTTP Response containing generated resource PDF
  21     """
  22     context = dict()
  23     get_request = request.GET
  24     context['paper_size'] = get_request['paper_size']
  25     context['resource'] = resource
  26 
  27     resource_image_generator = importlib.import_module(module_path)
  28     filename = '{} ({})'.format(resource.name, resource_image_generator.subtitle(get_request, resource))
  29     context['filename'] = filename
  30 
  31     num_copies = range(0, int(get_request['copies']))
  32     image_generator = partial(
  33         generate_resource_image,
  34         get_request,
  35         resource,
  36         module_path
  37     )
  38     with Pool() as pool:
  39         context['resource_images'] = pool.map(image_generator, num_copies)
  40     pool.close()
  41 
  42     pdf_html = render_to_string('resources/base-resource-pdf.html', context)
  43     html = HTML(string=pdf_html, base_url=request.build_absolute_uri())
  44     css_file = finders.find('css/print-resource-pdf.css')
  45     css_string = open(css_file, encoding='UTF-8').read()
  46     base_css = CSS(string=css_string)
  47     pdf_file = html.write_pdf(stylesheets=[base_css])
  48 
  49     response = HttpResponse(pdf_file, content_type='application/pdf')
  50     response['Content-Disposition'] = RESPONSE_CONTENT_DISPOSITION.format(filename=filename)
  51     return response
  52 
  53 
  54 def generate_resource_image(get_request, resource, module_path, copy_num):
  55     """Calls the resource's image generator and returns the generated
  56     image. This function also resizes the generated image for the paper
  57     size requested.
  58 
  59     Returns:
  60         Base 64 string of a generated resource image.
  61     """
  62     # Get image from resource image creator
  63     resource_image_generator = importlib.import_module(module_path)
  64     image = resource_image_generator.resource_image(get_request, resource)
  65 
  66     # Resize image to reduce file size
  67     if get_request['paper_size'] == "a4":
  68         max_pixel_height = 267 * MM_TO_PIXEL_RATIO
  69     elif get_request['paper_size'] == "letter":
  70         max_pixel_height = 249 * MM_TO_PIXEL_RATIO
  71     (width, height) = image.size
  72     if height > max_pixel_height:
  73         ratio = max_pixel_height / height
  74         width *= ratio
  75         height *= ratio
  76         image = image.resize((int(width), int(height)), Image.ANTIALIAS)
  77 
  78     # Save image to buffer
  79     image_buffer = BytesIO()
  80     image.save(image_buffer, format='PNG')
  81 
  82     # Return base64 of image
  83     return base64.b64encode(image_buffer.getvalue())
  84
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/csunplugged/resources/views/generate_resource_pdf.py b/csunplugged/resources/views/generate_resource_pdf.py
  --- a/csunplugged/resources/views/generate_resource_pdf.py
  +++ b/csunplugged/resources/views/generate_resource_pdf.py
  @@ -23,6 +23,7 @@
       get_request = request.GET
       context['paper_size'] = get_request['paper_size']
       context['resource'] = resource
  +    context['header_text'] = get_request['header_text']
   
       resource_image_generator = importlib.import_module(module_path)
       filename = '{} ({})'.format(resource.name, resource_image_generator.subtitle(get_request, resource))
  diff --git a/csunplugged/resources/views/sorting_network.py b/csunplugged/resources/views/sorting_network.py
  --- a/csunplugged/resources/views/sorting_network.py
  +++ b/csunplugged/resources/views/sorting_network.py
  @@ -56,10 +56,12 @@
       for the requested resource.
       """
       prefilled_values = get_request['prefilled_values']
  +    range_min = 0
  +    range_max = 0
  +    font_size = 150
       if prefilled_values == 'easy':
           range_min = 1
           range_max = 10
  -        font_size = 150
       elif prefilled_values == 'medium':
           range_min = 10
           range_max = 100
  
verification_info: {"golden_diff": "diff --git a/csunplugged/resources/views/generate_resource_pdf.py b/csunplugged/resources/views/generate_resource_pdf.py\n--- a/csunplugged/resources/views/generate_resource_pdf.py\n+++ b/csunplugged/resources/views/generate_resource_pdf.py\n@@ -23,6 +23,7 @@\n     get_request = request.GET\n     context['paper_size'] = get_request['paper_size']\n     context['resource'] = resource\n+    context['header_text'] = get_request['header_text']\n \n     resource_image_generator = importlib.import_module(module_path)\n     filename = '{} ({})'.format(resource.name, resource_image_generator.subtitle(get_request, resource))\ndiff --git a/csunplugged/resources/views/sorting_network.py b/csunplugged/resources/views/sorting_network.py\n--- a/csunplugged/resources/views/sorting_network.py\n+++ b/csunplugged/resources/views/sorting_network.py\n@@ -56,10 +56,12 @@\n     for the requested resource.\n     \"\"\"\n     prefilled_values = get_request['prefilled_values']\n+    range_min = 0\n+    range_max = 0\n+    font_size = 150\n     if prefilled_values == 'easy':\n         range_min = 1\n         range_max = 10\n-        font_size = 150\n     elif prefilled_values == 'medium':\n         range_min = 10\n         range_max = 100\n", "issue": "Always ask for page size and copies for resource generation\nAdd these questions to `base-resource.html` template\n", "before_files": [{"content": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\n\n\ndef resource_image(get_request, resource):\n    \"\"\"Creates a image for Sorting Network resource.\n\n    Returns:\n        A Pillow image object.\n    \"\"\"\n    image_path = 'static/img/resource-sorting-network-colour.png'\n    image = Image.open(image_path)\n    draw = ImageDraw.Draw(image)\n\n    (range_min, range_max, font_size) = number_range(get_request)\n\n    font_path = 'static/fonts/PatrickHand-Regular.ttf'\n\n    # Add numbers to text if needed\n    if get_request['prefilled_values'] != 'blank':\n        font = ImageFont.truetype(font_path, font_size)\n        numbers = sample(range(range_min, range_max), 6)\n        base_coord_x = 70\n        base_coord_y = 2560\n        coord_x_increment = 204\n        for number in numbers:\n            text = str(number)\n            text_width, text_height = draw.textsize(text, font=font)\n            coord_x = base_coord_x - (text_width / 2)\n            coord_y = base_coord_y - (text_height / 2)\n            draw.text(\n                (coord_x, coord_y),\n                text,\n                font=font,\n                fill='#000'\n            )\n            base_coord_x += coord_x_increment\n\n    return image\n\n\ndef subtitle(get_request, resource):\n    \"\"\"Returns the subtitle string of the resource.\n\n    Used after the resource name in the filename, and\n    also on the resource image.\n    \"\"\"\n    TEMPLATE = '{} to {}'\n    range_min, range_max, font_size = number_range(get_request)\n    text = TEMPLATE.format(range_min, range_max - 1)\n    return text\n\n\ndef number_range(get_request):\n    \"\"\"Returns a tuple of (range_min, range_max, font_size)\n    for the requested resource.\n    \"\"\"\n    prefilled_values = get_request['prefilled_values']\n    if prefilled_values == 'easy':\n        range_min = 1\n        range_max = 10\n        font_size = 150\n    elif prefilled_values == 'medium':\n        range_min = 10\n        range_max = 100\n        font_size = 120\n    elif prefilled_values == 'hard':\n        range_min = 100\n        range_max = 1000\n        font_size = 90\n    return (range_min, range_max, font_size)\n", "path": "csunplugged/resources/views/sorting_network.py"}, {"content": "from django.http import HttpResponse\nfrom django.template.loader import render_to_string\nfrom django.contrib.staticfiles import finders\nfrom multiprocessing import Pool\nfrom functools import partial\nfrom weasyprint import HTML, CSS\nfrom PIL import Image\nfrom io import BytesIO\nimport importlib\nimport base64\n\nRESPONSE_CONTENT_DISPOSITION = 'attachment; filename=\"{filename}.pdf\"'\nMM_TO_PIXEL_RATIO = 3.78\n\n\ndef generate_resource_pdf(request, resource, module_path):\n    \"\"\"Returns a response containing a randomly generated PDF resource.\n\n    Returns:\n        HTTP Response containing generated resource PDF\n    \"\"\"\n    context = dict()\n    get_request = request.GET\n    context['paper_size'] = get_request['paper_size']\n    context['resource'] = resource\n\n    resource_image_generator = importlib.import_module(module_path)\n    filename = '{} ({})'.format(resource.name, resource_image_generator.subtitle(get_request, resource))\n    context['filename'] = filename\n\n    num_copies = range(0, int(get_request['copies']))\n    image_generator = partial(\n        generate_resource_image,\n        get_request,\n        resource,\n        module_path\n    )\n    with Pool() as pool:\n        context['resource_images'] = pool.map(image_generator, num_copies)\n    pool.close()\n\n    pdf_html = render_to_string('resources/base-resource-pdf.html', context)\n    html = HTML(string=pdf_html, base_url=request.build_absolute_uri())\n    css_file = finders.find('css/print-resource-pdf.css')\n    css_string = open(css_file, encoding='UTF-8').read()\n    base_css = CSS(string=css_string)\n    pdf_file = html.write_pdf(stylesheets=[base_css])\n\n    response = HttpResponse(pdf_file, content_type='application/pdf')\n    response['Content-Disposition'] = RESPONSE_CONTENT_DISPOSITION.format(filename=filename)\n    return response\n\n\ndef generate_resource_image(get_request, resource, module_path, copy_num):\n    \"\"\"Calls the resource's image generator and returns the generated\n    image. This function also resizes the generated image for the paper\n    size requested.\n\n    Returns:\n        Base 64 string of a generated resource image.\n    \"\"\"\n    # Get image from resource image creator\n    resource_image_generator = importlib.import_module(module_path)\n    image = resource_image_generator.resource_image(get_request, resource)\n\n    # Resize image to reduce file size\n    if get_request['paper_size'] == \"a4\":\n        max_pixel_height = 267 * MM_TO_PIXEL_RATIO\n    elif get_request['paper_size'] == \"letter\":\n        max_pixel_height = 249 * MM_TO_PIXEL_RATIO\n    (width, height) = image.size\n    if height > max_pixel_height:\n        ratio = max_pixel_height / height\n        width *= ratio\n        height *= ratio\n        image = image.resize((int(width), int(height)), Image.ANTIALIAS)\n\n    # Save image to buffer\n    image_buffer = BytesIO()\n    image.save(image_buffer, format='PNG')\n\n    # Return base64 of image\n    return base64.b64encode(image_buffer.getvalue())\n", "path": "csunplugged/resources/views/generate_resource_pdf.py"}], "after_files": [{"content": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\n\n\ndef resource_image(get_request, resource):\n    \"\"\"Creates a image for Sorting Network resource.\n\n    Returns:\n        A Pillow image object.\n    \"\"\"\n    image_path = 'static/img/resource-sorting-network-colour.png'\n    image = Image.open(image_path)\n    draw = ImageDraw.Draw(image)\n\n    (range_min, range_max, font_size) = number_range(get_request)\n\n    font_path = 'static/fonts/PatrickHand-Regular.ttf'\n\n    # Add numbers to text if needed\n    if get_request['prefilled_values'] != 'blank':\n        font = ImageFont.truetype(font_path, font_size)\n        numbers = sample(range(range_min, range_max), 6)\n        base_coord_x = 70\n        base_coord_y = 2560\n        coord_x_increment = 204\n        for number in numbers:\n            text = str(number)\n            text_width, text_height = draw.textsize(text, font=font)\n            coord_x = base_coord_x - (text_width / 2)\n            coord_y = base_coord_y - (text_height / 2)\n            draw.text(\n                (coord_x, coord_y),\n                text,\n                font=font,\n                fill='#000'\n            )\n            base_coord_x += coord_x_increment\n\n    return image\n\n\ndef subtitle(get_request, resource):\n    \"\"\"Returns the subtitle string of the resource.\n\n    Used after the resource name in the filename, and\n    also on the resource image.\n    \"\"\"\n    TEMPLATE = '{} to {}'\n    range_min, range_max, font_size = number_range(get_request)\n    text = TEMPLATE.format(range_min, range_max - 1)\n    return text\n\n\ndef number_range(get_request):\n    \"\"\"Returns a tuple of (range_min, range_max, font_size)\n    for the requested resource.\n    \"\"\"\n    prefilled_values = get_request['prefilled_values']\n    range_min = 0\n    range_max = 0\n    font_size = 150\n    if prefilled_values == 'easy':\n        range_min = 1\n        range_max = 10\n    elif prefilled_values == 'medium':\n        range_min = 10\n        range_max = 100\n        font_size = 120\n    elif prefilled_values == 'hard':\n        range_min = 100\n        range_max = 1000\n        font_size = 90\n    return (range_min, range_max, font_size)\n", "path": "csunplugged/resources/views/sorting_network.py"}, {"content": "from django.http import HttpResponse\nfrom django.template.loader import render_to_string\nfrom django.contrib.staticfiles import finders\nfrom multiprocessing import Pool\nfrom functools import partial\nfrom weasyprint import HTML, CSS\nfrom PIL import Image\nfrom io import BytesIO\nimport importlib\nimport base64\n\nRESPONSE_CONTENT_DISPOSITION = 'attachment; filename=\"{filename}.pdf\"'\nMM_TO_PIXEL_RATIO = 3.78\n\n\ndef generate_resource_pdf(request, resource, module_path):\n    \"\"\"Returns a response containing a randomly generated PDF resource.\n\n    Returns:\n        HTTP Response containing generated resource PDF\n    \"\"\"\n    context = dict()\n    get_request = request.GET\n    context['paper_size'] = get_request['paper_size']\n    context['resource'] = resource\n    context['header_text'] = get_request['header_text']\n\n    resource_image_generator = importlib.import_module(module_path)\n    filename = '{} ({})'.format(resource.name, resource_image_generator.subtitle(get_request, resource))\n    context['filename'] = filename\n\n    num_copies = range(0, int(get_request['copies']))\n    image_generator = partial(\n        generate_resource_image,\n        get_request,\n        resource,\n        module_path\n    )\n    with Pool() as pool:\n        context['resource_images'] = pool.map(image_generator, num_copies)\n    pool.close()\n\n    pdf_html = render_to_string('resources/base-resource-pdf.html', context)\n    html = HTML(string=pdf_html, base_url=request.build_absolute_uri())\n    css_file = finders.find('css/print-resource-pdf.css')\n    css_string = open(css_file, encoding='UTF-8').read()\n    base_css = CSS(string=css_string)\n    pdf_file = html.write_pdf(stylesheets=[base_css])\n\n    response = HttpResponse(pdf_file, content_type='application/pdf')\n    response['Content-Disposition'] = RESPONSE_CONTENT_DISPOSITION.format(filename=filename)\n    return response\n\n\ndef generate_resource_image(get_request, resource, module_path, copy_num):\n    \"\"\"Calls the resource's image generator and returns the generated\n    image. This function also resizes the generated image for the paper\n    size requested.\n\n    Returns:\n        Base 64 string of a generated resource image.\n    \"\"\"\n    # Get image from resource image creator\n    resource_image_generator = importlib.import_module(module_path)\n    image = resource_image_generator.resource_image(get_request, resource)\n\n    # Resize image to reduce file size\n    if get_request['paper_size'] == \"a4\":\n        max_pixel_height = 267 * MM_TO_PIXEL_RATIO\n    elif get_request['paper_size'] == \"letter\":\n        max_pixel_height = 249 * MM_TO_PIXEL_RATIO\n    (width, height) = image.size\n    if height > max_pixel_height:\n        ratio = max_pixel_height / height\n        width *= ratio\n        height *= ratio\n        image = image.resize((int(width), int(height)), Image.ANTIALIAS)\n\n    # Save image to buffer\n    image_buffer = BytesIO()\n    image.save(image_buffer, format='PNG')\n\n    # Return base64 of image\n    return base64.b64encode(image_buffer.getvalue())\n", "path": "csunplugged/resources/views/generate_resource_pdf.py"}]}