prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  #6963 Too many codes in 1 package
  URL: https://meinberlin-dev.liqd.net/dashboard/modules/burgerinnenhaushalt-3-phasen-21/download-codes/
  user: admin, initiator
  expected behaviour: Each code-package should contain a max. of 1.000.000 codes. ~~The wording of the helptext should have also the right number of 1.000.000 codes per package as each package should contain a maximum of 1.000.000 codes per excel-file.~~
  behaviour: ~~the number in the wording of the helptext is "10.000.000" and~~ the packages can contain more than 1.000.000 codes.
  important screensize: -
  device & browser: mac ff
  Comment/Question: I tried it with generating two mill codes and the codes were put in only one code-package. I also couldn't download the package probably because it was too big.
  
  Linked: https://github.com/liqd/a4-meinberlin/issues/4907
  
  
  </issue>
  <code>
  [start of meinberlin/apps/votes/tasks.py]
  1 from background_task import background
  2 
  3 from adhocracy4.modules.models import Module
  4 from meinberlin.apps.votes.models import VotingToken
  5 from meinberlin.apps.votes.models import get_token_12
  6 
  7 # Number of tokens to insert into database per bulk_create
  8 BATCH_SIZE = 1000000
  9 # Max number of tokens in one download / package
  10 PACKAGE_SIZE = 10000000
  11 
  12 
  13 def generate_voting_tokens(module_id, number_of_tokens, existing_tokens):
  14     module = Module.objects.get(pk=module_id)
  15     package_number = VotingToken.next_package_number(module)
  16     module_name = module.name
  17     project_id = module.project.id
  18     project_name = module.project.name
  19 
  20     number_to_generate = number_of_tokens
  21     package_number_limit = 0
  22     if number_of_tokens > PACKAGE_SIZE:
  23         package_number_limit = number_of_tokens - PACKAGE_SIZE
  24     while number_to_generate > 0:
  25         if number_to_generate >= BATCH_SIZE:
  26             generate_voting_tokens_batch(
  27                 module_id,
  28                 BATCH_SIZE,
  29                 package_number,
  30                 number_of_tokens,
  31                 module_name,
  32                 project_id,
  33                 project_name,
  34                 existing_tokens,
  35             )
  36             number_to_generate = number_to_generate - BATCH_SIZE
  37         else:
  38             generate_voting_tokens_batch(
  39                 module_id,
  40                 number_to_generate,
  41                 package_number,
  42                 number_of_tokens,
  43                 module_name,
  44                 project_id,
  45                 project_name,
  46                 existing_tokens,
  47             )
  48             number_to_generate = 0
  49         if package_number_limit >= number_to_generate:
  50             package_number += 1
  51             package_number_limit - PACKAGE_SIZE
  52 
  53 
  54 @background(schedule=1)
  55 def generate_voting_tokens_batch(
  56     module_id,
  57     batch_size,
  58     package_number,
  59     number_of_tokens,
  60     module_name,
  61     project_id,
  62     project_name,
  63     existing_tokens,
  64 ):
  65     module = Module.objects.get(pk=module_id)
  66     VotingToken.objects.bulk_create(
  67         [get_token_and_hash(module, package_number) for i in range(batch_size)]
  68     )
  69 
  70 
  71 def get_token_and_hash(module, package_number):
  72     token = get_token_12()
  73     token_hash = VotingToken.hash_token(token, module)
  74     return VotingToken(
  75         token=token, token_hash=token_hash, module=module, package_number=package_number
  76     )
  77
  [end of meinberlin/apps/votes/tasks.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/meinberlin/apps/votes/tasks.py b/meinberlin/apps/votes/tasks.py
  --- a/meinberlin/apps/votes/tasks.py
  +++ b/meinberlin/apps/votes/tasks.py
  @@ -5,9 +5,9 @@
   from meinberlin.apps.votes.models import get_token_12
   
   # Number of tokens to insert into database per bulk_create
  -BATCH_SIZE = 1000000
  +BATCH_SIZE = 100000
   # Max number of tokens in one download / package
  -PACKAGE_SIZE = 10000000
  +PACKAGE_SIZE = 1000000
   
   
   def generate_voting_tokens(module_id, number_of_tokens, existing_tokens):
  
verification_info: {"golden_diff": "diff --git a/meinberlin/apps/votes/tasks.py b/meinberlin/apps/votes/tasks.py\n--- a/meinberlin/apps/votes/tasks.py\n+++ b/meinberlin/apps/votes/tasks.py\n@@ -5,9 +5,9 @@\n from meinberlin.apps.votes.models import get_token_12\n \n # Number of tokens to insert into database per bulk_create\n-BATCH_SIZE = 1000000\n+BATCH_SIZE = 100000\n # Max number of tokens in one download / package\n-PACKAGE_SIZE = 10000000\n+PACKAGE_SIZE = 1000000\n \n \n def generate_voting_tokens(module_id, number_of_tokens, existing_tokens):\n", "issue": "#6963 Too many codes in 1 package\nURL: https://meinberlin-dev.liqd.net/dashboard/modules/burgerinnenhaushalt-3-phasen-21/download-codes/\r\nuser: admin, initiator\r\nexpected behaviour: Each code-package should contain a max. of 1.000.000 codes. ~~The wording of the helptext should have also the right number of 1.000.000 codes per package as each package should contain a maximum of 1.000.000 codes per excel-file.~~\r\nbehaviour: ~~the number in the wording of the helptext is \"10.000.000\" and~~ the packages can contain more than 1.000.000 codes.\r\nimportant screensize: -\r\ndevice & browser: mac ff\r\nComment/Question: I tried it with generating two mill codes and the codes were put in only one code-package. I also couldn't download the package probably because it was too big.\r\n\r\nLinked: https://github.com/liqd/a4-meinberlin/issues/4907\r\n\n", "before_files": [{"content": "from background_task import background\n\nfrom adhocracy4.modules.models import Module\nfrom meinberlin.apps.votes.models import VotingToken\nfrom meinberlin.apps.votes.models import get_token_12\n\n# Number of tokens to insert into database per bulk_create\nBATCH_SIZE = 1000000\n# Max number of tokens in one download / package\nPACKAGE_SIZE = 10000000\n\n\ndef generate_voting_tokens(module_id, number_of_tokens, existing_tokens):\n    module = Module.objects.get(pk=module_id)\n    package_number = VotingToken.next_package_number(module)\n    module_name = module.name\n    project_id = module.project.id\n    project_name = module.project.name\n\n    number_to_generate = number_of_tokens\n    package_number_limit = 0\n    if number_of_tokens > PACKAGE_SIZE:\n        package_number_limit = number_of_tokens - PACKAGE_SIZE\n    while number_to_generate > 0:\n        if number_to_generate >= BATCH_SIZE:\n            generate_voting_tokens_batch(\n                module_id,\n                BATCH_SIZE,\n                package_number,\n                number_of_tokens,\n                module_name,\n                project_id,\n                project_name,\n                existing_tokens,\n            )\n            number_to_generate = number_to_generate - BATCH_SIZE\n        else:\n            generate_voting_tokens_batch(\n                module_id,\n                number_to_generate,\n                package_number,\n                number_of_tokens,\n                module_name,\n                project_id,\n                project_name,\n                existing_tokens,\n            )\n            number_to_generate = 0\n        if package_number_limit >= number_to_generate:\n            package_number += 1\n            package_number_limit - PACKAGE_SIZE\n\n\n@background(schedule=1)\ndef generate_voting_tokens_batch(\n    module_id,\n    batch_size,\n    package_number,\n    number_of_tokens,\n    module_name,\n    project_id,\n    project_name,\n    existing_tokens,\n):\n    module = Module.objects.get(pk=module_id)\n    VotingToken.objects.bulk_create(\n        [get_token_and_hash(module, package_number) for i in range(batch_size)]\n    )\n\n\ndef get_token_and_hash(module, package_number):\n    token = get_token_12()\n    token_hash = VotingToken.hash_token(token, module)\n    return VotingToken(\n        token=token, token_hash=token_hash, module=module, package_number=package_number\n    )\n", "path": "meinberlin/apps/votes/tasks.py"}]}